Urgent query related to execute immediate in a  procedure.

hi,
I want to create a table in the production database,within a procedure so I write query like:
CREATE OR REPLACE PROCEDURE TEST
IS
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE PE.BUD_VS_REV AS SELECT * FROM WH.WH_BUD_VS_REVNM1';
END;
but this is not working within the procedure it gives the
ORA-01031: insufficient privileges.
I already have asked to DBA he said that this user has all previlidges.
one more thing if I write this query in an annonymous block like:
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE PE.BUD_VS_REV AS SELECT * FROM WH.WH_BUD_VS_REVNM1';
END;
its working well.
can any buddy tellme what can be the reason,actually.
Thanx
Ritesh!

Look this example:
DBA >> CREATE USER LEO IDENTIFIED BY LEO
2 /
User created.
DBA >> GRANT CREATE SESSION TO LEO
2 /
Grant succeeded.
LEO >> CREATE OR REPLACE PROCEDURE TEST
2 IS
3 BEGIN
4 EXECUTE IMMEDIATE 'CREATE TABLE PE.BUD_VS_REV AS SELECT * FROM WH.WH_BUD_VS
_REVNM1';
5 END;
6 /
CREATE OR REPLACE PROCEDURE TEST
ERROR at line 1:
ORA-01031: insufficient privileges
DBA >> GRANT CREATE ANY PROCEDURE TO LEO
2 /
Grant succeeded.
LEO >> CREATE OR REPLACE PROCEDURE TEST
2 IS
3 BEGIN
4 EXECUTE IMMEDIATE 'CREATE TABLE PE.BUD_VS_REV AS SELECT * FROM WH.WH_BUD_VS
_REVNM1';
5 END;
6 /
Procedure created.

Similar Messages

  • **URGENT** Problem using execute immediate in a procedure ...

    Hi all,
    I am writing this procedure
    create or replace procedure pr_test is
    begin
    EXECUTE IMMEDIATE 'CREATE or replace view test1 as select * from table_name';
    end ;
    when I execute this procedure even in the same schema who owns this table it gives me this message.
    BEGIN pr_test; END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "COLIS.PR_TEST", line 3
    ORA-06512: at line 1
    can any body lets me know the solution????
    Thanks in advance
    Take Care !
    Ghulam

    Thank you very much fellows.
    But I have reached at this point that one has to have create view privellege explicitly to create view using a dynamic sql statemetn. Actually I could create the view using SQL*Plus and every thing was working fine through SQL*Plus. But I granted the rights of create user from a user having DBA role.
    Anyways! Thank you very much for contributing this discussion. I really appreciate it.
    Ghulam Mustafa Butt

  • Put the query result of "EXECUTE IMMEDIATE" command in a local table

    Hi all.
    Is it possible to put the output of the "EXECUTE IMMEDIATE" command in a local table so that the ouput can be accessed through other procedures.
    Regards,
    Andila

    Hi Andila, well you could just make your dynamic sql statement an insert statement based on your select. See example below
    create column table test_table_1
    "COL1" nvarchar(10),
    "COL2" nvarchar(10)
    CREATE PROCEDURE INSERT_P() 
    LANGUAGE SQLSCRIPT AS 
      sql_string NVARCHAR(2000) := '';
    BEGIN 
      sql_string := 'insert into test_table_1 (select ''val1'', ''val2'' from dummy) ';
      EXECUTE IMMEDIATE (:sql_string); 
    END; 
    call insert_p();
    select * from test_table_1;
    However you may want to investigate other options instead of using dynamic SQL as this is not a recommended approach. Less optimized compared to standard sql.
    Peter

  • Execute immediate for stored procedure with out parameter

    Hi,
    I have problem with dynamically executing the statement hope anyone can help me.
    I have a table which stores the procedure names. and procedure parameter values are stored on another column with parameter values coming from java side.
    I have to create a procedure that dynamically executes the procedure on table1 with the values from table 2.
    Now I'm getting real trouble to execute immediate this proc with parameters. I tried the DBMS_SQL package as well.
    Problem is you need to mention the OUT mode specifically for the out parameter. Can anybody plz help me with this issue??
    TABLE1_
    PROCESS_ID     PROC_NAME
    1      proc1(p1 IN number, p2 IN varchar2, p3 OUT varchar2)
    2     proc2(p1 IN number, p2 out varchar2, p3 OUT varchar2)
    TABLE2_
    PROCESS_ID     PROC_PARMS
    1     100, 'test', :return
    2     200, :return1, :return2
    Thank You

    826957 wrote:
    Hi,
    I have problem with dynamically executing the statement hope anyone can help me.
    I have a table which stores the procedure names. and procedure parameter values are stored on another column with parameter values coming from java side.
    I have to create a procedure that dynamically executes the procedure on table1 with the values from table 2.
    Now I'm getting real trouble to execute immediate this proc with parameters. I tried the DBMS_SQL package as well.
    Problem is you need to mention the OUT mode specifically for the out parameter. Can anybody plz help me with this issue??
    TABLE1_
    PROCESS_ID     PROC_NAME
    1      proc1(p1 IN number, p2 IN varchar2, p3 OUT varchar2)
    2     proc2(p1 IN number, p2 out varchar2, p3 OUT varchar2)
    TABLE2_
    PROCESS_ID     PROC_PARMS
    1     100, 'test', :return
    2     200, :return1, :return2
    Thank YouSounds like an appalling design and a nightmare waiting to happen.
    Why not have your Java just call the correct procedures directly?
    Such design smells badly of an entity attribute value modelling style of coding. Notoriously slow, notoriously buggy, notoriously hard to maintain, notoriously hard to read. It really shouldn't be done like that.

  • EXECUTE IMMEDIATE call to procedure

    need help on this piece of code.
    1. lv_rec is a record of a table temp1 from which i need to validate lv_code.
    2. The package1.proc_get_rec procedure has an IN OUT record parameter which is %ROWTYPE of the table in which the code exists.
    3. lv_err_msg_out parameter will hold an error message if validation fails.
    4. i need dynamic validation here because the table temp1(where code exists) and the package(needed to be called to validate the code) i am calling is residing in a defferent module.
    declare
    lv_plsql_block varchar2(1000);
    lv_code :='B';
    lv_rec temp1%ROWTYPE;
    lv_err_msg_inout varchar2(100);
    begin
    lv_plsql_block := ' BEGIN package1.proc_get_rec(:1, :2, :3, :4); END;';
    EXECUTE IMMEDIATE lv_plsql_block USING
    lv_code,
    SYSDATE,
    IN OUT lv_rec,
    IN OUT lv_err_msg_inout;
    dbms_output.put_line('Err msg is '||lv_err_msg_inout);
    end;
    When i execute the above piece of code, i get the following error message:
    Oracle Error :: PLS-00457 expressions have to be of SQL types
    Is there any workaround for this problem??
    Thanks in advance
    Dodsferd

    There is a procedure proc_get_rec which uses a %ROWTYPE of a table.
    This procedure and table temp1 might exist or might not exist in the database based on the type of installation of the product
    Now I cannot directly execute the above procedure because the table temp1 might exist or not.
    So I am using dynamic SQL to make sure that there are no compilation errors.
    In Dynamic SQL I am not able to pass the %ROWTYPE parameter of the procedure dynamically.
    Kindly suggest some workarround for this.
    Below is the sample of the procedure through which the dynamic SQL is called:
    procedure P1 (lv_code varchar2(10))
    is
    lv_plsql_block varchar2(1000);
    lv_rec temp1%ROWTYPE;
    lv_err_msg_inout varchar2(100);
    begin
    lv_plsql_block := ' BEGIN package1.proc_get_rec(:1, :2, :3, :4); END;';
    EXECUTE IMMEDIATE lv_plsql_block USING
    lv_code,
    SYSDATE,
    IN OUT lv_rec,
    IN OUT lv_err_msg_inout;
    dbms_output.put_line('Err msg is '||lv_err_msg_inout);
    end P1;

  • Problem to insert using execute immediate

    Have a procedure like this:
    create or replace procedure proc_set_category(
    VC_object_id IN number,
    VC_object IN varchar2,
    VC_category_id IN varchar2
    is
    sq varchar2(200);
    BEGIN
         sq:='INSERT INTO ' || VC_object ||'_category (' || VC_object || '_id,category_id) VALUES (' || VC_object_id || ',' || VC_category_id ||')';
         EXECUTE IMMEDIATE sq;
    END;
    Procedure created.
    but when i try to execute the following query it generates an error
    execute proc_set_category(1,'news','event')
    ERROR at line 1:
    ORA-00984: column not allowed here
    ORA-06512: at "SCOTT.PROC_SET_CATEGORY", line 10
    ORA-06512: at line 1
    I have a news_category table.where is the problem?

    sq:='INSERT INTO ' || VC_object ||'_category (' || VC_object || '_id,category_id) VALUES (' || VC_object_id || ',' || VC_category_id ||')';
    EXECUTE IMMEDIATE sq;
    execute immediate 'INSERT INTO ' || VC_object ||'_category (' || VC_object || '_id,category_id) VALUES (:1, :2)'
      using VC_object_id, VC_category_id;

  • Problem with execute immediate code

    I have the following anonymous block:
    declare
    v_id_char varchar2(50) := '2072018827821663';
    trace_flg number := 0;
    v_exe_imm varchar2(500) := 'univdb.EML_CAMPUS_200605(v_id_char, trace_flg)';
    v_exe_imm2 varchar2(500) := 'univdb.EML_CAMPUS_200605(:v_id_char, :trace_flg)';
    begin
    --1) execute immediate v_exe_imm;
    --2) execute immediate v_exe_imm2 using v_id_char, trace_flg);
    univdb.EML_CAMPUS_200605(v_id_char, trace_flg);
    end;
    The compiled procedure that is getting called is defined like this:
    CREATE OR REPLACE PROCEDURE univdb.eml_campus_200605(
    hist_str IN VARCHAR2,
    trace_flg IN NUMBER := 0) IS ...
    As you might expect, when I execute the block without execute immediate it works.
    But either of the execute immediate statements results in ORA-00900: invalid SQL statment.
    I want to use execute immediate because the procedure that gets called will need to be dynamic.
    Help appreciated,
    ...elsa

    For me, thats crude if you have a procedure thats
    getting created dynamically.
    anyway, you could try a
    execute immediate ' begin ' || your_funny_proc || '
    end;';But for sure the whole stuff is very error prone.Actually, the procedure itself isn't getting built dynamically, only which procedure to call. It's really quite clever in my opinion.
    Anyway, I tried you suggestion:
    declare
    v_id_char varchar2(50) := '2072018827821663';
    trace_flg number := 0;
    v_exe_imm varchar2(500) := 'univdb.EML_CAMPUS_200605(v_id_char, trace_flg)';
    v_exe_imm2 varchar2(500) := 'univdb.EML_CAMPUS_200605(:v_id_char, :trace_flg)';
    begin
    execute immediate 'BEGIN ' || v_exe_imm || '; END;';
    --execute immediate v_exe_imm2 using v_id_char, trace_flg);
    --univdb.EML_CAMPUS_200605(v_id_char, trace_flg);
    end;
    and got
    ORA-06550: line 1, column 32:
    PLS-00201: identifier 'V_ID_CHAR' must be declared
    Did I misunderstand what you were trying for?

  • EXECUTE IMMEDIATE NO PRIVALIGE

    No privilege to execute this statement ,but the current user is already has right to create sequence.
    EXECUTE IMMEDIATE(' CREATE SEQUENCE '||P_Sequance_Name||
                             ' START WITH '||P_Start_With||
                             ' MAXVALUE '||P_MaxValue||
                             ' MINVALUE '||P_MinValue||
                             ' '||P_CYCLE||
                             ' '||P_CACHE||
                             ' '||P_ORDER);

    If you trying to use EXECUTE IMMEDIATE in forms procedure - this is probably not a privilege problem.
    EXECUTE IMMEDIATE is is not supported in client side.
    Try to replace it with
    forms_ddl(' CREATE SEQUENCE '||P_Sequance_Name||
                                ' START WITH '||P_Start_With||
                                ' MAXVALUE   '||P_MaxValue||
                                ' MINVALUE   '||P_MinValue||
                                ' '||P_CYCLE||
                                ' '||P_CACHE||
                                ' '||P_ORDER);

  • Execute a DML query its length exceeds 4000 characters with execute immediate statement.

    I want to execute a DML query with execute immediate statement. That DML query length exceeds 4000 characters. This query has Xquery related conditions, i can not split the query. when i tried execute it is giving "string literal too long".  I tried with DBMS_SQL.Parse() and DBMS_SQL.Execute also, but it is giving same error. I have to execute this DML query inside a Procedure. Please help me to resolve this. We are using oracle 10g version
    Thanks & Regards,
    K.Kedarnadh

    Actually Query is a dynamic query. Query length will exceeds if the no of domains\domain values \products exceeds. Any way Below one is current dynamic query, which is generated within procedure
    SELECT
      IVT.ID_IVT
        ,IVT.ID_INS_IVT
      ,EXTRACTVALUE(IVT.DOCUMENT_IVT,'//productName/text()') AS PRODUCTNAME
      ,EXTRACTVALUE(IVT.DOCUMENT_IVT,'//elementName/text()') AS INSTANCENAME
      ,EXTRACTVALUE(IVT.DOCUMENT_IVT,'//elementInternalName/text()') AS INTERNALNAME
        ,CTG.NAME_CTG
        ,CTR.NAME_CTR
        ,MDL.NAME_MDL
      ,IVT.REEDIT_FLAG_IVT
        FROM  VARIATION_IVT IVT INNER JOIN CATEGORY_CTG CTG ON CTG.ID_CTG=IVT.ID_CTG_IVT
      AND IVT.STATUS_IVT='Active' AND IVT.DELETE_FLAG_IVT=0 AND IVT.ID_PRJ_IVT=1
      AND  IVT.DOCUMENT_IVT.existsnode('.//domain[domainName="Jurisdictions" and (domainValue="Delhi" or domainValue="Bangladesh" or domainValue="Mumbai" or domainValue="India" or domainValue="Pakistan" or domainValue="Nepal" or domainValue="Maldives" or domainValue="Kolkata" or domainValue="Bhutan" or domainValue="Chennai" or domainValue="ALL")]')=1 AND  IVT.DOCUMENT_IVT.existsnode('.//domain[domainName="Channels" and (domainValue="Agents" or domainValue="SBI" or domainValue="Maruti" or domainValue="Direct" or domainValue="CitiFinancial" or domainValue="SCB" or domainValue="BankAssurance" or domainValue="CitiBank" or domainValue="Employees" or domainValue="GE" or domainValue="Brokers" or domainValue="Telemarketing" or domainValue="Agency" or domainValue="ALL")]')=1 AND  IVT.DOCUMENT_IVT.existsnode('.//domain[domainName="ModeofDelivery" and (domainValue="Walkin" or domainValue="Internet" or domainValue="ALL")]')=1 AND  IVT.DOCUMENT_IVT.existsnode('.//context[(productName="ALL" or productName="A009" or productName="A010" or productName="A046" or productName="AccidentShieldClassic" or productName="AccidentShieldOnline" or productName="AM01" or productName="AM02" or productName="AME_Cancellation" or productName="ARHG" or productName="ARPA" or productName="B003" or productName="B004" or productName="B007" or productName="B008" or productName="B009" or productName="B010" or productName="B012" or productName="B013" or productName="B015" or productName="B016" or productName="B017" or productName="BC04_PA" or productName="BC06_FDP" or productName="BC06_PA" or productName="BC09" or productName="BC10" or productName="BC12" or productName="BC13" or productName="BF03" or productName="BS01" or productName="BS02" or productName="C017" or productName="C035" or productName="C036" or productName="C037" or productName="C038" or productName="C040" or productName="C041" or productName="C041Gold" or productName="C041New" or productName="C045HomeContents" or productName="C048" or productName="C049" or productName="C054" or productName="C057" or productName="C060Building" or productName="C060Contents" or productName="C060FDP" or productName="C061Building" or productName="C061Contents" or productName="C062" or productName="C063" or productName="C067" or productName="C070" or productName="C072" or productName="C074" or productName="C077" or productName="C081" or productName="C082" or productName="C087" or productName="C088" or productName="CITIFOREVER" or productName="CITISECURE" or productName="CITICHILDPLAN" or productName="D001" or productName="DB01" or productName="DD01" or productName="DD02" or productName="DD03" or productName="DD04" or productName="DD09" or productName="DD10" or productName="E005" or productName="E011" or productName="E016" or productName="E020" or productName="E030" or productName="E034" or productName="E040" or productName="E041" or productName="E045HCP" or productName="E045HSP" or productName="E049" or productName="E049New" or productName="E052" or productName="E053" or productName="E054FDP" or productName="E055" or productName="E056" or productName="E057" or productName="E058" or productName="E061" or productName="E061BATCH" or productName="E062" or productName="E063" or productName="E064HCP" or productName="E064HSP" or productName="E066" or productName="E069" or productName="E073" or productName="E075" or productName="E076" or productName="E088" or productName="E090" or productName="E093A" or productName="E093B" or productName="E095" or productName="E099A" or productName="E099B" or productName="E106" or productName="E107" or productName="E110" or productName="E112" or productName="E114" or productName="E115" or productName="E116" or productName="F001" or productName="FamilyHealthInsurance" or productName="FamilyHospitalBenefits" or productName="FamilyHospitalisationCoverBenefit" or productName="G001" or productName="G002" or productName="HealthShieldOnline" or productName="Health_B005" or productName="Health_S057" or productName="HealthSheild" or productName="HealthWalkin" or productName="HomeContentOnline" or productName="HomeShieldOnline" or productName="HomeShieldWalkin" or productName="HospitalCashOnline" or productName="J001" or productName="J008" or productName="K001" or productName="KV02" or productName="LC03" or productName="ML01" or productName="MP02" or productName="MP03" or productName="MR01" or productName="O005" or productName="PO01" or productName="PO02" or productName="PO03" or productName="PO04" or productName="PO05" or productName="PO06" or productName="RR02" or productName="RR03" or productName="RR04" or productName="S006" or productName="S033" or productName="S049" or productName="S051" or productName="S054" or productName="S057" or productName="S060" or productName="S061" or productName="S065" or productName="S065TM" or productName="S068" or productName="S076" or productName="S077" or productName="S079" or productName="S080" or productName="S081" or productName="S084" or productName="S085" or productName="S086" or productName="S087" or productName="S088" or productName="S091" or productName="S092" or productName="S093" or productName="S094" or productName="S095" or productName="S097" or productName="S098" or productName="S099" or productName="S100" or productName="S101" or productName="S102" or productName="S103" or productName="S104" or productName="S106" or productName="S107" or productName="S108" or productName="S109" or productName="S110" or productName="S111" or productName="S113" or productName="SCBNAC" or productName="SF02" or productName="SS01" or productName="SS02" or productName="SUNFHM" or productName="SurgicalShield" or productName="TD01" or productName="TD02" or productName="TP01" or productName="U002Building" or productName="U002Contents" or productName="U004Building" or productName="U007" or productName="U009" or productName="U013" or productName="U014" or productName="U015" or productName="U016" or productName="V001" or productName="V002" or productName="V005" or productName="V006" or productName="V008" or productName="W008" or productName="W020" or productName="W021" or productName="W022" or productName="W023" or productName="W024" or productName="W026" or productName="W027" or productName="W028" or productName="W029" or productName="W105" or productName="W106" or productName="WI01" or productName="WI02" or productName="WI03" or productName="WI07" or productName="WI08" or productName="WI09" or productName="WI10" or productName="WI11" or productName="WI12" or productName="WI13" or productName="WI14" or productName="WI17" or productName="WI20" or productName="WI21" or productName="WI21_Health" or productName="WI23" or productName="WI24" or productName="WI26" or productName="WI30" or productName="WI31" or productName="WI33" or productName="WI34" or productName="X001" or productName="X002" or productName="X003" or productName="X004" or productName="X005" or productName="X008" or productName="Y001" or productName="Y007" or productName="Y009" or productName="Y010" or productName="Y011" or productName="Y011H" or productName="Y020" or productName="Y020N" or productName="Z008" or productName="ZI001")]')=1
      INNER JOIN CENTER_CTR CTR ON CTR.ID_CTR=CTG.ID_CTR_CTG
        INNER JOIN MODEL_MDL MDL ON  MDL.ID_MDL=CTR.ID_MDL_CTR

  • Need some help in EXECUTE IMMEDIATE Query

    Hi All,
    First of all i have a question. Is EXECUTE IMMEDIATE allowed for multi-row queries. (I am using Oracle 10g R2).
    Some of my colleagues are using pipeline operator. Please refer below
    BEGIN
    EXECUTE IMMEDIATE 'CREATE TABLE TEMP NOLOGGING AS'||
    '(' ||
    'SELECT P.PSEQ,' ||
    'I.PLEY,' ||
    'I.ORG,' ||
    'I.RKEY,' ||
    'COUNT(P.PSEQ) COUNT'||
    'FROM' ||
    'PROD P,' ||
    'INV I,' ||
    'PLAC PL,' ||
    'ORG O' ||
    'WHERE' ||
    'I.RKEY=P.PSEQ' ||
    'AND'||
    'P.COMP=''RT''' ||
    'AND'||
    'I.INVST = ''IN''' ||
    'AND'||
    'P.SSN=''C''' ||
    'AND'||
    'PL.PLEY=I.PLEY' ||
    'AND'||
    'I.ORG=O.OSEQ' ||
    'GROUP BY' ||
    'I.PLKEY,' ||
    'I.ORG,' ||
    'I.PLEY,' ||
    'P.PSEQ' ||
    END;
    Is it at neccessary to concatenate. Earlied i have used execute immediate with multi row queries successfully without any ||.
    Please help me to understand??
    Thanks in advance.
    Message was edited by:
    SID

    btw it's the concatenation operator, and '|' is known as the pipe character. Pipelines are something different.

  • ****URGENT*** execute immediate problem

    Hi all,
    I am writing this procedure
    create or replace procedure pr_test is
    begin
    EXECUTE IMMEDIATE 'CREATE or replace view test1 as select * from table_name';
    end ;
    when I execute this procedure even in the same schema who owns this table it gives me this message.
    BEGIN pr_test; END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "COLIS.PR_TEST", line 3
    ORA-06512: at line 1
    can any body lets me know the solution????
    Thanks in advance
    Take Care !
    Ghulam

    You must grant first the privilege in SQLPlus:
    SQL> grant create [any] view to user_who_created_procedure;
    GB

  • Using execute immediate creating a table from another

    hi friend i wanted to create a table from a select statement in a pl sql procedure. i am using execute immediate but getting problems with it pls can anyone help me.
    here is the query i am using
    EXECUTE IMMEDIATE 'CREATE TABLE table_name AS  (SELECT * FROM  a_view   WHERE column_name LIKE '%some_string%');
    i need to know if this can be done and if yes how. pls help me its bit urgent too. the schema name is same and the privileges are available to create tables too.

    Your syntax is wrong.
    If you would use a syntax higlighted editor, it would show.
    Yout try to execute a string where another string is embedded. Please use two times single quote or use the 'q' function:
    This one is correct:
    EXECUTE IMMEDIATE 'CREATE TABLE table_name AS (SELECT * FROM  a_view WHERE column_name LIKE ''%some_string%'')';
    or this one:
    EXECUTE IMMEDIATE q'|CREATE TABLE table_name AS (SELECT * FROM  a_view WHERE column_name LIKE '%some_string%')|';
    good luck

  • Problem with execute immediate

    hi,
    Oracle gurus,
    when i execute the following statement in a procedure it is not getting executed and it is getting strucked,
    pls provide me some suggestions.
    This is very urgent.
    is there any proble with commented lines?
    EXECUTE IMMEDIATE          'select
                        oh.account_no,
                        p.ord_line_no,
                        o.ord_no,
                        p.lot ,
                        (pr1.each_qty/pr.each_qty),
                        :p_comp_id ,
                        p.cube,
                        sysdate,
                        SYSDATE,--p.pick_date,
                        SYSDATE,--pw.date_time_released,
                        pr.each_qty,
                        :p_ebiz_appown_no,
                        p.ord_cntrl_no,
                        oh.ord_cntrl_no,
                        nvl(p.prod_no,0),
                        :p_ebiz_user_no,
                        nvl(sl.wdth,0) * nvl(sl.dpth,0),
                        decode(s.haz_mat_class,null,''N'',''Y''),
                        ''N'',
                        p.ord_line_no,
                        p.loc,
                        p.lp,
                        (nvl(p.qty,0)/nvl(pr.each_qty,1)),
                        1,
                        (nvl(p.qty,1)/pr1.each_qty),--ceil(nvl(p.qty,1)/pr1.each_qty),
                        oh.ord_prio,
                        oh.ord_type,
                        o.ord_no ,
                        nvl(p.pkg_no,0),
                        :p_task_no,
                        p.pick_line,
                        pl.pickline_type,
                        to_char(nvl(p.transact_id,0)),
                        p.qty ,
                        oh.ord_type,
                        :p_site_id,
                        nvl(s.sku,''SKU ERROR''),
                        s.sku_desc1_35      ,
                        s.prod_fam ,
                        s.prod_cat,
                        o.prod_stat,
                        2 ,
                        SYSDATE,--nvl(p.pick_date,sysdate),
                        bt.task_desc ,
                        bt.task_type,
                        null,--p.pick_date,
                        sl.type_stor_equip ,
                        o.uom,
                        p.wght
                   from      [email protected] pr,
                        mast_abbtype bt,
                        mast_company bc,
                        [email protected] sl,
                        sku@'||l_dblink||' s,
                        picks@'||l_dblink||' p,
                        ordline'||l_dblink||' o,
                        ordhead@'||l_dblink||' oh,
                        prodqty@'||l_dblink||' pr1,
                        pickwave@'||l_dblink||' pw,
                        pickline@'||l_dblink||' pl
                   where      decode(bt.comp_id,null,:p_comp_id,bt.comp_id)=:p_comp_id
                        and decode(bt.site_id,null,:p_site_id,bt.site_id)=:p_site_id
                        and bt.task_type = ''PICK''--decode(null,''PICK'',''PIK'',''PIK'')
                        and bc.delete_flag=''N''
                        and bt.active_flag=''Y''
                        and bc.active_flag=''Y''
                        and bt.delete_flag=''N''                    --and nvl(bc.ebiz_appown_no,-1) = nvl(bt.ebiz_appown_no,-1)
         and nvl(bc.ebiz_appown_no,-1) =1nvl(p_ebiz_appown_no,-1)
                   and nvl(p.failed_pick_flg,''N'') != ''Y''
                   and (bt.site_id =:p_site_id or bt.site_id is null)
                        and p.cmpl_time is not null
                        and p.wave_no = pw.wave_no
                        and s.prod_no = p.prod_no
                   and pr.prod_no = s.prod_no
                        and pr.pkg_no = p.pkg_no
    --and p.ord_cntrl_no in (select ord_cntrl_no from [email protected]  where ord_no = nvl(NULL, ord_no))
    --nvl(p_ebiz_po_no, p.ord_cntrl_no)
    --     and p.ord_cntrl_no = nvl(p_rec_cntrl_no, p.ord_cntrl_no)
         and nvl(p.prod_no,0) = nvl(:p_ebiz_sku_no, nvl(p.prod_no,0))
                   and oh.ord_type = nvl(NULL, oh.ord_type)
                   and nvl(o.prod_stat, ''~'') = nvl(:p_sku_status, nvl(o.prod_stat, ''~''))
                   and p.lp = nvl(:p_lp, p.lp)
                   and nvl(p.lot, ''~'') = nvl(:p_batch_no, nvl(p.lot, ''~''))
                   and pr.logical_case_flg = ''Y''
                   --and nvl(bt.site_id,''~'') = nvl(bc.site_id,''~'')
                   and s.comp_code = p.comp_code
                   and sl.loc = p.loc
              --     and nvl(pick_time,0) != ''9898''
                   and p.ord_cntrl_no = o.ord_cntrl_no
                   and p.ord_line_no = o.ord_line_no
                   and o.ord_cntrl_no = oh.ord_cntrl_no
                   and trunc(p.pick_date) between trunc(nvl(sysdate-10000,p.pick_date)) and trunc(nvl(sysdate,p.pick_date))
                   and nvl(p.pick_date,sysdate)<= nvl(bc.effective_date,sysdate)
                   and p.ord_cntrl_no = decode(null,null,p.ord_cntrl_no,null)
                   and pr1.pkg_no = pr.pkg_no
                   and pr1.prod_no = pr.prod_no
                   and pr1.logical_plt_flg = ''Y'' '
                   --and p.pick_line = pl.line_id      '
         Bulk collect into
                   l_account_no,
                   l_asn_line_no,
                   l_asn_no,
                   l_batch_no,
                   l_cases_per_pallet,
                   l_comp_id,
                   l_cube,
                   l_currdate,
                   l_date_time_ended,
                   l_date_time_started,
                   l_eachs_per_case,
                   l_ebiz_appown_no,
                   l_ebiz_asn_no,
                   l_ebiz_cntrl_no,
                   l_ebiz_sku_no,
                   l_ebiz_user_no,
                   l_footage,
                   l_hazmat_flag,
                   l_intf_conf_flag,
                   l_line_no,
                   l_location,
                   l_lp,
                   l_no_of_cases,
                   l_no_of_units,
                   l_no_plts,
                   l_order_priority,
                   l_order_type,
                   l_ord_no,
                   l_packcode,
                   l_parent_task_no,
                   l_pickline_id,
                   l_pickline_type,
                   l_po_no,
                   l_qty,
                   l_rcv_type,
                   l_site_id,
                   l_sku,
                   l_skudesc1,
                   l_skufam,
                   l_skugroup,
                   l_sku_status,
                   l_status_flag,
                   l_task_date,
                   l_task_desc,
                   l_task_type,
                   l_time,
                   l_type_stor_equip,
                   l_uom_id,
                   l_wght
         using           p_comp_id,p_ebiz_appown_no,p_ebiz_user_no,p_task_no,
                   p_site_id,p_comp_id,p_comp_id,p_site_id,p_site_id,          p_site_id,p_ebiz_sku_no,p_sku_status,p_lp,p_batch_no;
    regards RR.

    hi,
    again iam sending the same query for ur easy reference.
    pls treat it urgent.
    EXECUTE IMMEDIATE 'select
    oh.account_no,p.ord_line_no,     o.ord_no,     p.lot ,
    (pr1.each_qty/pr.each_qty),     :p_comp_id ,p.cube,
    sysdate,     SYSDATE,--p.pick_date,     SYSDATE,--pw.date_time_released,
    r.each_qty,:p_ebiz_appown_no,     p.ord_cntrl_no,oh.ord_cntrl_no,
    nvl(p.prod_no,0),     :p_ebiz_user_no,nvl(sl.wdth,0) * nvl(sl.dpth,0),
    decode(s.haz_mat_class,null,''N'',''Y''),''N'',p.ord_line_no,p.loc,p.lp,
    (nvl(p.qty,0)/nvl(pr.each_qty,1)),     1,
    (nvl(p.qty,1)/pr1.each_qty),--ceil(nvl(p.qty,1)/pr1.each_qty),
    oh.ord_prio,     oh.ord_type,o.ord_no ,nvl(p.pkg_no,0),
    :p_task_no,p.pick_line,pl.pickline_type,     to_char(nvl(p.transact_id,0)),
    p.qty ,     oh.ord_type,:p_site_id,     nvl(s.sku,''SKU ERROR''),
    s.sku_desc1_35      ,     s.prod_fam ,     s.prod_cat,
    o.prod_stat,     2 ,     SYSDATE,--nvl(p.pick_date,sysdate),
    bt.task_desc ,bt.task_type,     null,--p.pick_date,sl.type_stor_equip ,
    o.uom,     p.wght
    FROM
    [email protected] pr,
    mast_abbtype bt,
    mast_company bc,
    [email protected] sl,
    sku@'||l_dblink||' s,
    picks@'||l_dblink||' p,
    ordline'||l_dblink||' o,
    ordhead@'||l_dblink||' oh,
    prodqty@'||l_dblink||' pr1,
    pickwave@'||l_dblink||' pw,
    pickline@'||l_dblink||' pl
    WHERE
    decode(bt.comp_id,null,:p_comp_id,bt.comp_id)=:p_comp_id
    and decode(bt.site_id,null,:p_site_id,bt.site_id)=:p_site_id
    and bt.task_type = ''PICK''--decode(null,''PICK'',''PIK'',''PIK'')
    and bc.delete_flag=''N''
    and bt.active_flag=''Y''
    and bc.active_flag=''Y''
    and bt.delete_flag=''N''
    and nvl(p.failed_pick_flg,''N'') != ''Y''
    and (bt.site_id =:p_site_id or bt.site_id is null)
    and p.cmpl_time is not null
    and p.wave_no = pw.wave_no
    and s.prod_no = p.prod_no
    and pr.prod_no = s.prod_no
    and pr.pkg_no = p.pkg_no
    and nvl(p.prod_no,0) = nvl(:p_ebiz_sku_no, nvl(p.prod_no,0))
    and oh.ord_type = nvl(NULL, oh.ord_type)
    and nvl(o.prod_stat, ''~'') = nvl(:p_sku_status, nvl(o.prod_stat, ''~''))
    and p.lp = nvl(:p_lp, p.lp)
    and nvl(p.lot, ''~'') = nvl(:p_batch_no, nvl(p.lot, ''~''))
    and pr.logical_case_flg = ''Y''
    and s.comp_code = p.comp_code
    and sl.loc = p.loc
    and p.ord_cntrl_no = o.ord_cntrl_no
    and p.ord_line_no = o.ord_line_no
    and o.ord_cntrl_no = oh.ord_cntrl_no
    and trunc(p.pick_date) between trunc(nvl(sysdate-10000,p.pick_date)) and trunc(nvlsysdate,p.pick_date))
    and nvl(p.pick_date,sysdate)<= nvl(bc.effective_date,sysdate)
    and p.ord_cntrl_no = decode(null,null,p.ord_cntrl_no,null)
    and pr1.pkg_no = pr.pkg_no
    and pr1.prod_no = pr.prod_no
    and pr1.logical_plt_flg = ''Y'' '
    Bulk collect into
    l_account_no,
    l_asn_line_no,
                   l_asn_no,
                   l_batch_no,
                   l_cases_per_pallet,
                   l_comp_id,
                   l_cube,
                   l_currdate,
                   l_date_time_ended,
                   l_date_time_started,
                   l_eachs_per_case,
                   l_ebiz_appown_no,
                   l_ebiz_asn_no,
                   l_ebiz_cntrl_no,
                   l_ebiz_sku_no,
                   l_ebiz_user_no,
                   l_footage,
                   l_hazmat_flag,
                   l_intf_conf_flag,
                   l_line_no,
                   l_location,
                   l_lp,
                   l_no_of_cases,
                   l_no_of_units,
                   l_no_plts,
                   l_order_priority,
                   l_order_type,
                   l_ord_no,
                   l_packcode,
                   l_parent_task_no,
                   l_pickline_id,
                   l_pickline_type,
                   l_po_no,
                   l_qty,
                   l_rcv_type,
                   l_site_id,
                   l_sku,
                   l_skudesc1,
                   l_skufam,
                   l_skugroup,
                   l_sku_status,
                   l_status_flag,
                   l_task_date,
                   l_task_desc,
                   l_task_type,
                   l_time,
                   l_type_stor_equip,
                   l_uom_id,
                   l_wght
         using           p_comp_id,p_ebiz_appown_no,p_ebiz_user_no,p_task_no,
         p_site_id,p_comp_id,p_comp_id,p_site_id,p_site_id,          p_site_id,p_ebiz_sku_no,p_sku_status,p_lp,p_batch_no;
    here l_dblink contains database link
    regards
    RR

  • [Solved] Reference apex_application.g_fXX in "execute immediate" statement

    Hi!
    I created a dynamically generated tabular form - the number of columns is not known in advanced. Each cell of the form is a text item generated with apex_item.text().
    I want to write an after-submit process that saves the values from the form into a database table. In this process I already know how many columns there are in the report so I want to do the following:
    --for each row...
    for i in 1..apex_application.g_f01.count loop
      -- and for each column in that row (number of columns is in v_col_count)
      for j in 1..v_col_count loop
        -- get the value of text item
        v_query := 'select apex_application.g_f0' || j || '(' || i || ')' || ' from dual';
        execute immediate v_query into v_value;
        -- now do some DML with v_value
      end loop;
    end loop;The problem is that I get an error: ORA-06553: PLS-221: 'G_Fxx' is not a procedure or is undefined where xx is the number from the generated query.
    My question is - am I doing something wrong or is is just not possible to reference apex_application.g_fxx in "execute immediate"? Will I have to manually check for all 50 possibilites of apex_application.g_fxx? Is there another way?
    TIA,
    Jure

    Well now I know what was wrong and what you were trying to tell me - apex_application.g_fxx is not visible in "plain" SQL. And now I also have a solution to this problem. The point is to wrap the select statement with begin - end block so that the statement is rendered as pl/sql:
    --for each row...
    for i in 1..apex_application.g_f01.count loop
      -- and for each column in that row (number of columns is in v_col_count)
      for j in 1..v_col_count loop
        -- get the value of text item
        v_query := 'begin select apex_application.g_f0' || j || '(:i)' || ' into :x from dual; end;';
        execute immediate v_query using i, out v_value;
        -- now do some DML with v_value
      end loop;
    end loop;This works great :).
    Jure

  • Java Stored Procedure in EXECUTE IMMEDIATE

    Hi,
    I need advice for the following.
    I'm on Oracle 11g R2. I'm testing application in Oracle 11gR1 and R2 and Oracle Express.
    Purpose is to generate XML reports.
    I have PLSQL Stored Procedure which does that, but since there is bug in Oracle11gR2 related to XMLTRANSFORM I have and Java Stored Procedure which is workaround. They are both compiled, valid etc.
    Java class is :
    import java.io.PrintWriter;
    import java.io.Writer;
    import oracle.xml.parser.v2.DOMParser;
    import oracle.xml.parser.v2.XMLDocument;
    import oracle.xml.parser.v2.XSLProcessor;
    import oracle.xml.parser.v2.XSLStylesheet;
    * This class is used as Java stored procedure
    * There is a bug on Oracle11gR2, related to the limitation on the number of style sheet instructions
    * This stored procedure is workaround when PLSQL code can not be used.
    * File must not have package, otherwise is wrongly compiled in DB
    public class JavaXslt {
         public static void XMLTtransform(oracle.sql.CLOB xmlInput,oracle.sql.CLOB xslInput,oracle.sql.CLOB output) throws Exception{
              DOMParser parser;
              XMLDocument xml;
              XMLDocument xsldoc;
              try{
                   parser = new DOMParser();
                   parser.parse(xmlInput.getCharacterStream());
                   xml = parser.getDocument();
                   parser.parse(xslInput.getCharacterStream());
                   xsldoc = parser.getDocument();
                   XSLProcessor processor = new XSLProcessor();
                   XSLStylesheet xsl = processor.newXSLStylesheet(xsldoc);
                   Writer w = output.setCharacterStream(1L);
                   PrintWriter pw = new PrintWriter(w);
                   processor.processXSL(xsl, xml, pw);
              }catch (Exception ex){
                   throw ex;
    PROCEDURE Java_XmlTransform (xml CLOB, xslt CLOB, output CLOB) AS LANGUAGE JAVA
    NAME 'JavaXslt.XMLTtransform(oracle.sql.CLOB, oracle.sql.CLOB, oracle.sql.CLOB)';
    I'm calling Java stored procedure from PLSQL Stored procedure (if it is Oracle11gR2) like that :
    Java_Proc.Java_XmlTransform(inputXML, xslt, res);
    So till here everything works ok. XSLT as applied and output XML (res) is OK.
    But when Oracle Express is used Java is out of the question, so there is no Java stored procedure. Howewer PLSQL Stored procedure is still needed.
    So I had to put call to Java Stored procedure in EXECUTE IMMEDIATE statement in order to compile to PLSQL package.
    But when I do that :
    EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING inputXML, xslt, res;
    result value CLOB (res) has zero length...
    What am I missing? Should i set return value to Java class?
    Hope my explanations are clear though.
    Thanks

    Hi odie_63,
    Thanks for quick response.
    I didn't clearly explained.
    When using Oracle 11gR1 and Oracle Express I'm using only PLSQL Procedure.
    When using Oracle 11gR2 i have to use Java Stored procedure because there is documented bug in R2.
    That's why i have to use EXECUTE IMMEDIATE. I don't know which version is the client DB and whether there is or no Java procedures.
    I did tried
    EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, OUT res; and the result was ORA-06537: OUT bind variable bound to an IN position
    When using IN OUT for last parameter i.e.
    EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, IN OUT res;
    there is no exception, but still DBMS_LOB.getlength(res) = 0
    Thanks

Maybe you are looking for