use of execute immediate

Hi all
I have a statement i.e. Select ename from EMP; I want to run it in execute immediate command.
He return several rows at a time.

How can I run this statement with oracle execute immediate command

Please review...

dipuna wrote:
Hi all
I have a statement i.e. Select ename from EMP; I want to run it in execute immediate command.
He return several rows at a time.

If you have this EXACT statement, then you need not dynamic nothing :)

dipuna wrote:

How can I run this statement with oracle execute immediate command

Please review...

Examples of both methods (as previously mentioned).

TUBBY_TUBBZ?
declare
   type l_enames_tab is table of scott.emp.ename%type;
   l_enames_array    l_enames_tab ;
begin
  5
   execute immediate 'select ename from scott.emp' bulk collect into l_enames_array;

   for x in 1 .. l_enames_array.count
   loop
      dbms_output.put_line(l_enames_array(x));
   end loop;

end;
/

SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
TUBBY_TUBBZ?TUBBY_TUBBZ?
declare
   type l_enames_tab is table of scott.emp.ename%type;
   l_enames_array    l_enames_tab ;
   l_ref_cursor      sys_refcursor;
begin
  6
   open l_ref_cursor for
   'select ename from scott.emp';

   fetch l_ref_cursor bulk collect into l_enames_array;
   close l_ref_cursor; 

   for x in 1 .. l_enames_array.count
   loop
      dbms_output.put_line(l_enames_array(x));
   end loop;

end;
 19  /
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
TUBBY_TUBBZ?

Tags: Database

Similar Questions

  • Creating external Tables using the EXECUTE IMMEDIATE in PL/SQL

    Hi guys,.

    I am trying to create an external Table using the EXECUTE IMMEDIATE in a procedure and I managed to compile and no errors were generated. But when I try to run it from sql using the exec command I get the following error:

    ------------------------------------------------------------------------
    ERROR on line 5:
    ORA-00911: invalid character
    ORA-06512: at "GEO. TEST_DDL', line 4
    ORA-06512: at line 5

    -------------------------------------------------------------------------

    I tried to check the whole statement to create the external table, but I can't find where is the error. Surprisingly, if I simply run the command table create external on sqlplus it works, but not a procedure.

    If anyone can help with ideas or experience?

    Geoffrey Kossami

    The error means that there is an identifier somewhere that starts with a nonalphanumeric. This is a typical mistake of editing. A procedure compiles correctly is not of course because the underlying dynamic sql running is OK. Which of course only be resolved when you try to run it.

    There is certainly a problem with the text you provide to be run as a piece of dynamic sql code. You should try to watch it with dbms_output and run this code in sqlplus. But your problem is with the code you run as dynamic PL/SQL, it is not itself compilable.

    Jack

  • use of execute immediate with variables

    Hello

    I want to update a table with immediate execution, but I need to use the variable to run immediately. I typed a code, but the code below does not work and I m getting the error ORA-00936. Something wrong with this code?

    WHILE v_acu_payment_amount > 0

    LOOP

    BEGIN

    SELECT emplid, amount_past_due

    IN v_emplid, v_vade_tutari

    OF vade_temp

    WHERE the sira = v_sirano AND emplid IN (r1.emplid);

    END;

    v_acu_payment_amount: = v_acu_payment_amount - v_vade_tutari;

    Dbms_output.put_line ('paymentamount2' | v_acu_payment_amount);

    IF v_acu_payment_amount > 0

    THEN

    EXECUTE IMMEDIATE "update vade_temp set AMOUNT_PAST_DUE = to_number('||) 0

    || ') where sira = to_number (')

    || v_sirano

    || ')';

    ON THE OTHER

    Temp: = v_acu_payment_amount * (-1);

    Dbms_output.put_line (temp);

    EXECUTE IMMEDIATE "update vade_temp set AMOUNT_PAST_DUE = to_number (')"

    || Temp

    || ') where sira = to_number (')

    || v_sirano

    || ')';

    END IF;

    COMMIT;

    v_sirano: = v_sirano + 1;

    END LOOP;

    Kind regards

    Gunce

    In addition, you have no dynamic SQL for this

    [code]

    WHILE v_acu_payment_amount > 0

    LOOP

    BEGIN

    SELECT emplid, amount_past_due

    IN v_emplid, v_vade_tutari

    OF vade_temp

    WHERE the sira = v_sirano AND emplid IN (r1.emplid);

    END;

    v_acu_payment_amount: = v_acu_payment_amount - v_vade_tutari;

    Dbms_output.put_line ('paymentamount2' | v_acu_payment_amount);

    IF v_acu_payment_amount > 0

    THEN

    UPDATE vade_temp

    SET amount_past_due = 0

    WHERE the sira = v_sirano;

    ON THE OTHER

    Temp: = v_acu_payment_amount * (-1);

    Dbms_output.put_line (temp);

    UPDATE vade_temp

    SET AMOUNT_PAST_DUE = temp

    where sira = v_sirano;

    END IF;

    COMMIT;

    v_sirano: = v_sirano + 1;

    END LOOP;

    [/ code]

    But if you need dynamic sql statements, then you should use bind variables as

    ...

    EXECUTE IMMEDIATE "UPDATE vade_temp SET amount_past_due =: b1 WHERE sira =: b2' using 0, v_sirano;"

    ...

    HTH

  • Use of EXECUTE IMMEDIATE with XML

    Database version: 10.2.0.3.0 - 64bi

    Hi all

    I have an xml that is stored in a table, xmltype column.
    I target insert tables including column names and xml nodes are the same.
    using the table of all_tab_columns I will generate columns must be passed to xmltable.
    all these data, I'll store them in variables and finally proceed to xmltable as below
    I just want to know using execute immediate is good to use XML?

    SQL_STMT: = 'insert'. table_name | ' ( '|| V_COLUMN_NAME |') ' ;
    SQL_STMT: = SQL_STMT | ' SELECT '. V_XTAB_COLUMN_NAME |
    "FOR TO_XML,
    XMLTABLE(' || v_xpath ||)
    "PASSAGE XML_VALUE
    columns | V_COLUMNS_DATA_TYPE
    ||') XTAB
    WHERE Seq_NO = ' | P_SEQUENCE_NO;

    RUN IMMEDIATELY SQL_STMT;

    Thank you and best regards,
    Ruby

    Hi Ruby,

    I just want to know using execute immediate is good to use XML?

    Sorry, but this question does not make much sense.
    Whether or not dynamic SQL means XML is not relevant, the statement will end up as a cursor in the shared pool independently and be executed or retrieved as any other.

    If I were you, I'd be worried on the statement do not use bind variables, or the need for dynamic SQL in the first place.

    Why should you use dynamic SQL?
    If it's laziness, because there are a lot of columns to write down, then it is a bad reason.

  • Problem in Using of EXECUTE IMMEDIATE clause

    Hello
    I tried using using the clause, but am getting an error. Any help is welcome.

    Here is the code

    declare
    number of g_salary;
    v_stm varchar2 (100);
    Start
    v_stm: = "insert into emp (empno, deptno, sal) values (: 1,: 2: 3)"; "
    execute immediate v_stm using empno, sal, deptno;
    end;


    Here is the error message

    ERROR on line 1:
    ORA-06550: line 6, column 31:
    PLS-00201: identifier 'EMPNO' must be declared.
    ORA-06550: line 6, column 1:
    PL/SQL: Statement ignored

    You must provide values that must be inserted into the table.
    something like

    declare
       g_salary number ;
       v_stm varchar2(100);
    begin
       v_stm := 'insert into emp (empno, deptno, sal) values (:1, :2, :3)';
       execute immediate v_stm using 10, 20, 30;
    end;
    

    not tested

  • use of execute immediate to select

    Hi all

    I am writing a procedure as follows:

    create or replace procedure (run_yr_mo in number) as

    number of v_count: = 0;

    Start

    run immediately "select count (*)
    from all_tables
    where owner = "MGR"
    and table_name = "FC_PR_" '. run_yr_mo | »
    in v_count;

    dbms_output.put_line (v_count);

    end;

    This returns me an error when immediate execution.
    run_yr_mo = 200912

    Can someone help me with this.

    Thank you

    Why use run immediately?

    create or replace procedure myproc ( run_yr_mo in number) as
     v_count number := 0;
    begin
      select count(*)
      into v_count
      from all_tables
      where owner = 'MGR'
      and table_name = 'FC_PR_'||to_char(run_yr_mo,'fm999999');
    
      dbms_output.put_line(v_count);
    end;
    

    You missed to give a name to the procedure and you need to format numbers as strings explicitly to avoid possible extra spaces get added at the beginning of the implicit conversion.

  • How to set multiple parameters in a sql EXECUTE IMMEDIATE

    I want to set nls_language and nls_date_language and set them as different languages. fnd_global.set_nls_context () does not work. So I think I can use the EXECUTE IMMEDIATE and add them together into a single statement. But I don't know how to make that happen. Can someone help me? Thank you very much.

    PS: It must be done in a single call.

    928091 wrote:
    Hey, thanks for your reply, I forgot to mention that it should be in the begin-end block, do you know how?

    EXEC is a more SQL API which can be used to execute the PL/SQL code. What it does is put the PL/SQL code in a BEGIN block... END of block and run.

    So, you can also manually put code in a BEGIN block... END of block and run like that.

    SQL> begin
      2     execute immediate q'[begin execute immediate 'alter session set nls_date_language = ''AMERICAN'''; execute immediate 'alter session set nls_language = ''AMERICAN'''; end;]';
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    And I don't understand what possible benefit he made a single run in a BEGIN block... Terminate during execution of multiples.

    Why this code is not in your interest, something like this

    begin
         execute immediate 'alter session set nls_date_language = ''AMERICAN''';
         execute immediate 'alter session set nls_language = ''AMERICAN''';
    end;
    /
    
  • dml execution 2 statements at a time with the help of execute immediate

    I would like to run 2 DML statements at a time with the help of execute immediate usefulness,.

    ex:

    update employee set ename = 'Chantal' where eno = 123;
    Update dept set dname = 'IT' where dno = 345;

    I want the two statement to execute at a time, but I don't want to use any loop as well.

    Thanks in advance

    You can use:

    execute immediate 'begin update employee set ename='jagadeesh' where eno=123; update dept set dname='IT' where dno=345; end;';
    

    Although updates will always run one after the other.

    If you want the simultaneous treatment, then you need to use DBMS_JOB and DBMS_SCHEDULER to plan both work to run to run each of the statements independently.

  • "EXECUTE IMMEDIATE" of CLOB

    I have plsql-variable with CLOB datatype. It contains the source code of a package body. The size of the variable does not fit into 'varchar2' data type, it is larger.
    Now, I want to run a "EXECUTE IMMEDIATE" statement to create my package body defined in my CLOB variable.
    How can I use the "EXECUTE IMMEDIATE"?
    Note that "EXECUTE IMMEDIATE" does not allow for CLOB-variable as an argument.
    Note that "EXECUTE IMMEDIATE" allows "varchar2" - variables as arguments but "varchar2" contains maximum only some 32 KB of data.


    --

    Maybe it's possible to run something like
    "EXECUTE IMMEDIATE v1 | v2 | v3»
    where v1, v2, v3 are of type varchar2 and altogether they contain ca 100K of data and execute immediately would succeed?
    I wil outside, a s test...

    I wil outside, a s test...

    You may have searched for as well ;)

    Re: immediate execution of a CLOB field.

    Note: In 11 GR 2 run immediately accepts a clob as well...

  • EXECUTE IMMEDIATE in error > > ORA-00972: identifier is too long

    Hello

    I wrote a code using execute immediate command. This command essentially creates a cursor that selects user_tab_columns table names. These table names are then used inside the statement immediately execute in order to apply the same select statement on the table being selected within the cursor names. The problem is that the above error is thrown saying identifier is too long. I can't understand how to solve this problem.

    Please find the below code:

    Declare
    Cursor C_1 is select distinct table_name
    of user_tab_columns
    where column_name = 'PROGRAM_UPDATE_DATE' AND table_name LIKE '% MISPA '.
    intersect
    Select unique table_name
    of gsi_daily_count;
    table_names varchar2 (100);
    Begin
    C_1 open;
    Loop
    Extract the C_1 in table_names;
    WHEN THE EXIT C_1% NOTFOUND;

    EXECUTE IMMEDIATE "select last_extract_date,
    TO_CHAR (min (largest (nvl (last_update_date, "1 January 10"), nvl (program_update_date, "1 January 10"))), "MON-DD-YY HH24:MI:SS") mi.
    TO_CHAR (max (greatest (nvl (last_update_date, "1 January 10"), nvl (program_update_date, "1 January 10"))), "MON-DD-YY HH24:MI:SS") my
    of ' | table_names |
    "Last_extract_date group".
    order of last_extract_date desc;';

    End loop;
    Close C_1;
    COMMIT;
    End;
    /


    Help, please.

    Kind regards
    Hossam
    declare
      cursor C_1
      is
      select distinct table_name
        from user_tab_columns
       where column_name = 'PROGRAM_UPDATE_DATE'
         and table_name LIKE 'MISPA%'
      intersect
      select unique table_name
        from gsi_daily_count;
    
      table_names varchar2(100);
    begin
      open C_1;
      loop
        fetch C_1 into table_names;
        exit when c_1%notfound;
    
        execute immediate
          'select last_extract_date,
                  to_char(min(greatest(nvl(last_update_date,''01-Jan-10''),nvl(program_update_date,''01-Jan-10''))),''DD-MON-YY HH24:MI:SS'') mi,
                  to_char(max(greatest(nvl(last_update_date,''01-Jan-10''),nvl(program_update_date,''01-Jan-10''))),''DD-MON-YY HH24:MI:SS'') ma
             from'|| table_names ||
          'group by last_extract_date
            order by last_extract_date desc;';
      end Loop;
      close C_1;
      commit;
    End;
    

    Here is the list of question I see in this code.

    1. in the SQL string, you must have a after the keyword and before the GROUP BY keyword.

    2. you should not use ';' in EXECUTE IMMEDIATE. You must remove it.

    3. the result set returned by the EXECUTE IMMEDIATE should be stored in a Variable. You use the INTO LEDGES INTO clause or in BULK to this effect.

  • Execute Immediate and by calling a function

    I'm calling a function by using the Execute Immediate, but not sure what the correct syntax for the function's return value after the Execute Immediate runs.

    I need the value for further processing in my PL/SQL package.

    I tried several methods, but cannot get the right format for this work/compilation.


    EExecute Immediate plsql_block back in ShName2;

    Have been that plsql_block has the code to:
    Declare shname2 varchar2 (4000); Begin shname2: = lurking. ShortNm ('STRUCTURE'); End;
    SQL> set serveroutput on
    SQL>
    SQL> create or replace
      2  function fun
      3     return varchar2
      4  is
      5  begin
      6     return 'hello';
      7  end fun;
      8  /
    
    Function created.
    
    SQL>
    SQL>
    SQL> declare
      2     var varchar2(100);
      3  begin
      4     execute immediate 'begin :this := fun; end;' using in out var;
      5    dbms_output.put_line(var);
      6  end;
      7  /
    hello
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    
  • Execute Immediate for an IF statement

    All,
    I'm trying to run an IF statement dynamically at execution using the Execute Immediate statement, but I am gettign error... The error is PLS-00201: identifier 'V_BARG_UNIT' must be declared
    The condition and the result for the case statement is stored in a test_dynamic_if_tbl table that has 2 columns.
    condition = v_barg_unit = 'ABC' and result_val = v_bg_group: = "93"

    Yet the code...

    DECLARE
    cmd VARCHAR2 (4000);
    v_barg_unit VARCHAR2 (10): = 'ABC ';
    v_bg_group VARCHAR2 (10): = ' ';

    ABC of the CURSOR
    IS
    SELECT * FROM test_dynamic_if_tbl;
    BEGIN
    FOR c1 IN abc
    LOOP
    cmd: =.
    "Start."
    If ' | C1.condition
    || "THEN."
    || C1.result_val
    || ' ; End if;
    End;';
    Dbms_output.put_line ('cmd: ' | cmd);

    Cmd EXECUTE IMMEDIATE.

    Dbms_output.put_line (' status: ' | c1.condition);
    Dbms_output.put_line ('result_value: ' | c1.result_val);
    Dbms_output.put_line ('v_bg_group: ' | v_bg_group);
    END LOOP;
    END;

    What I am doing wrong?

    Thanks for your help in advance,
    Vinay

    Published by: user652279 on September 16, 2009 11:45

    Published by: user652279 on September 16, 2009 11:47

    Well, dynamic sql is executed in a separate context and scope. V_barg_unit stated in your code is therefore not visible in the dynamic PL/SQL block you run. You can pass block dynamic PL/SQL using the variable binding and the USING clause:

    DECLARE
        cmd VARCHAR2 (4000);
        v_barg_unit VARCHAR2 (10) := 'ABC';
        v_bg_group VARCHAR2 (10) := ' ';
    
    CURSOR abc
    IS
    SELECT * FROM test_dynamic_if_tbl;
    BEGIN
    FOR c1 IN abc
    LOOP
    cmd :=
    'declare v_barg_unit VARCHAR2 (10);
    Begin
    v_barg_unit := :v_barg_unit;
    If ' || c1.condition
    || ' THEN '
    || c1.result_val
    || ' ; End if;
    End;';
    DBMS_OUTPUT.put_line ('cmd: ' || cmd);
    
    EXECUTE IMMEDIATE cmd USING v_barg_unit,OUT v_bg_group;
    
    DBMS_OUTPUT.put_line ('Condition: ' || c1.condition);
    DBMS_OUTPUT.put_line ('result_value: ' || c1.result_val);
    DBMS_OUTPUT.put_line ('v_bg_group: ' || v_bg_group);
    END LOOP;
    END;
    

    However, since you do not know what name will be stored in test_dynamic_if_tbl my suggestion is not a generic solution.

    SY.

    Published by: Solomon Yakobson September 16, 2009 12:07

  • Create a temporary table using EXECUTE IMMEDIATE

    Hello

    I need to create a report more complex which must have three different queries. I use a determined IF clause that the query that uses the report, according to the parameters.

    I want to write the output to a csv file, so I created a PROCEDURE.

    The first package of the procedure has the three SQL and the IF clause in order to determine the query that the report uses and stores the query code in a variable (v_sql), which is passed to the PROCEDURE that needs to write to the output of the report.

    I tried to create a table with data from the request in order to make a LOOP and exit, something like this:

    WRITE_FILE (errBUFF of the PROCEDUREOUT VARCHAR2,
    retCODEOUT VARCHAR2,
    v_sqlIN VARCHAR2)

    IS

    ContorNUMBER;

    BEGIN

    EXECUTE IMMEDIATE v_sql;
    SLIDE G
    IS
    Select * from XXROR_REG_MF_TBL;
    --
    -initialization
    --
    retCode: = 0;
    errBUFF: = NULL;
    Contor: = 0;
    --
    -cursor
    --

    FOR X IN G
    LOOP
    APPS. FND_FILE.
    PUT_LINE)
    APPS. FND_FILE. OUTPUT,
    ....)

    I should mention that v_sql is something like:

    CREATE GLOBAL TEMPORARY TABLE ACEs (SELECT * of the double);

    I can't really do that, so I was wondering if you have any suggestions

    Thank you

    Claudiu

    Hello

    I don't think you need a table at all. You can set the cursor based on the SQL passed as parameter

    https://docs.Oracle.com/database/121/LNPLS/dynamic.htm#LNPLS629

    Concerning

    Marcus

  • Pass Pl/sql table in the USING clause in the EXECUTE IMMEDIATE statement

    Getting error when I try to pass the PL/SQL table in the USING clause in the EXECUTE IMMEDIATE statement:

    Declare
    result NUMBER;
    TYPE values_tab IS TABLE OF NUMBER INDEX OF directory;
    lv_tab values_tab;
    lv_exp varchar2 (300);
    lv_exec varchar2 (300);
    BEGIN
    lv_tab (1): = 5;
    lv_tab (2): = 48;
    lv_tab (3): = 7;
    lv_tab (4): = 6;
    lv_exp: = ': + b1: b2 + (: b3 *: b4)';
    lv_exec: = 'SELECT'. lv_exp | ' THE DOUBLE '.

    IMMEDIATE EXECUTION
    lv_exec
    IN
    result
    USING
    lv_tab;
    DBMS_OUTPUT. Put_line (result);

    END;
    /

    Error on line 1
    ORA-06550: line 20, column 12:
    PLS-00457: expressions must be SQL types
    ORA-06550: line 15, column 8:
    PL/SQL: Statement ignored


    I am trying to evaluate the expression ': + b1: b2 + (: b3 *: b4) "which is stored in the table. This table has different expressions (expressions about 300). I want to use the bind variable in the expression because each expression evaluated thousands of time may be more in some cases. If I use bind variable can he fill pool.

    Is there a way I can pass parameters with the HELP of (IN) dynamically instead of write "help lv_tab (1), lv_tab (2), lv_tab (3), lv_tab (4)? As number of change of the input parameters depend on the expression in the table.

    If it is possible please suggest any other ideas/approaches

    Help, please...

    Published by: satnam on June 11, 2009 11:50

    Well, you keep changing faster reqs that I can follow. In any case, assuming that N-th variable bind (left to right) corresponds to n-th collection item:

    Declare
        result NUMBER;
        lv_tab values_tab := values_tab();
        lv_exp varchar2(300);
        lv_exec varchar2(300);
        lv_i number := 0;
    BEGIN
        lv_tab.extend(4);
        lv_tab(1) := 5;
        lv_tab(2) := 48;
        lv_tab(3) := 7;
        lv_tab(4) := 6;
        lv_exp := ':5000135+:5403456+(:5900111*:5200456)';
        lv_exec := lv_exp;
        While regexp_like(lv_exec,':\d+') loop
          lv_i := lv_i + 1;
          lv_exec := REGEXP_REPLACE(lv_exec,':\d+',':b(' || lv_i || ')',1,1);
        end loop;
        lv_exec := 'BEGIN :a := ' || lv_exec || '; END;';
    DBMS_OUTPUT.PUT_LINE(lv_exec);
    EXECUTE IMMEDIATE lv_exec USING OUT result,IN lv_tab;
    DBMS_OUTPUT.PUT_LINE(result);
    END;
    /
    BEGIN :a := :b(1)+:b(2)+(:b(3)*:b(4)); END;
    95
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • How to create and insert data with Execute Immediate?

    Hi guys

    Am stuck on a procedure of formatting in a package... script works okay however integrating a module turns out to be difficult!

    Am not used to oracle... I have the script runs, but not in the package... Well not all that... Drop Table worked

    CREATE or REPLACE PACKAGE BODY is

    PROCEDURE DropTable1 IS

    BEGIN

    run immediately ("DROP TABLE mytable1");

    END;

    PROCEDURE PopulateTable1 IS

    BEGIN

    immediately execute ('CREATE TABLE mytable1 )

    AS LONG AS)

    Select

    substr (T1.genarea, 3, 3) as M_Class,

    substr (T1.genarea, 6, 30) as M_Description,

    substr (T1.genarea, 36, 3) as M_Class,

    substr (T1.genarea, 39, 30) as M_Description,

    substr (T1. ItemItem, 1, 3) as product_code,.

    T3. CHANNEL_NUM as SALES_CHANNEL,

    to_date(''t2.time_id'',''dd-mon-yyyy'') as mis_date,

    Sum (T2.ap_cw_cfi_irp + T2.ap_cw_issues_irp) as ap_gross,

    sum (t2. Ap_Cw_Cfi_Irp + t2. Ap_Revivals_Irp) as ap_net,

    Sum (T2.sp_inc_irp + T2.sp_issues_irp) as sp_gross,

    Sum (T2.sp_dec_irp + T2.sp_fs_irp) as sp_net

    Of

    d_pr t1, t2 age_map t3 law

    where

    T1.pfx = "WE"and t1.coy ="1" and t1.tabl = "T81" and substr (t1.itemitem, 1, 3) = t2.product_id and t3. AGE_NUM = t2.age_id

    Group

    substr (T1.genarea, 3, 3),

    substr (T1.genarea, 6, 30),

    substr (T1.genarea, 36, 3),

    substr (T1.genarea, 39, 30),

    substr (T1. ItemItem, 1, 3).

    T3. CHANNEL_NUM,

    to_date(''t2.time_id'',''dd-mon-yyyy'')

    )');

    COMMIT;

    END PopulateTable1;

    END test;

    /

    Thank you

    Hello

    a few notes.

    1. to_date(t2.time_id,'dd-mon-yyyy')

    New York T2.Time_ID Cis the varchar2 data type that contains values to JJ-me-YYYY format?

    And if, in which language is used for the names of the months? Conversions are point impossible to solve in reasonable time limits without logging of dml errors and unique failure on charges of staging nightly!


    2 single quote escaping "alternative in string literals.

    You can use Q or q to escape single quotes in strings.

    http://docs.Oracle.com/database/121/SQLRF/sql_elements003.htm#SQLRF00218

    3. validation

    Not required because the DDL commands commit implied.

    In general I recommend you write commit clauses only in calling script rather than in the code unless it connects with an autonomous transaction.

    You end up with a lot of validation of code here and there and you don't know where it is and where it isn't. That is, your process may have more than one appeal process and commit the middle of the process, it is not atomic processes.

    Here's the demo although I recommend also using the static table and truncate to efficiency. ETG is good choice for the purpose of maintenance table.

    create or replace
    package testing is
      procedure staging_one;
    end;
    /
    create or replace
    package body testing is
      --
      procedure staging_one is
        --
        procedure drop_staging_one is
          table_does_not_exist exception;
          pragma exception_init(table_does_not_exist, -00942);
        begin
          execute immediate q'{
            drop table staging_one purge
          }';
        exception when table_does_not_exist then
          return; -- fine
        end;
        --
        procedure create_staging_one is
        begin
          execute immediate q'{
    
            -- remove >>>
            create table staging_one nologging
            as
            select * from dual
            -- <<< remove
    
            /* uncomment >>>
            create table staging_one nologging
            as
            select
              substr(t1.genarea,3,3)                    as m_class,
              substr(t1.genarea,6,30)                   as m_description,
              substr(t1.genarea,36,3)                   as m_class,
              substr(t1.genarea,39,30)                  as m_description,
              substr(t1.itemitem,1,3)                   as product_code,
              t3.channel_num                            as sales_channel,
              to_date(t2.time_id,'dd-mon-yyyy')         as mis_date,
              sum(t2.ap_cw_cfi_irp+t2.ap_cw_issues_irp) as ap_gross,
              sum(t2.ap_cw_cfi_irp+t2.ap_revivals_irp)  as ap_net,
              sum(t2.sp_inc_irp   +t2.sp_issues_irp)    as sp_gross,
              sum(t2.sp_dec_irp   +t2.sp_fs_irp)        as sp_net
            from
              d_pr t1,
              act t2,
              age_map t3
            where
              t1.pfx                      = 'IT'
              and t1.coy                  = '1'
              and t1.tabl                 = 'T81'
              and substr(t1.itemitem,1,3) = t2.product_id
              and t3.age_num              = t2.age_id
            group by
              substr(t1.genarea,3,3),
              substr(t1.genarea,6,30),
              substr(t1.genarea,36,3),
              substr(t1.genarea,39,30),
              substr(t1.itemitem,1,3),
              t3.channel_num,
              to_date(t2.time_id,'dd-mon-yyyy')
            <<< uncomment */
          }';
          --
        end;
      -- main
      begin
        drop_staging_one;
        create_staging_one;
      end;
    end;
    /
    
    set serveroutput on
    
    exec testing.staging_one;
    
    select * from staging_one
    ;
    commit
    ;
    
    PACKAGE TESTING compiled
    PACKAGE BODY TESTING compiled
    anonymous block completed
    DUMMY
    -----
    X 
    
    committed.
    

Maybe you are looking for