Rows affected the dynamic SQL


Hello

VERSION - Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64 bit Production

I want the number of rows affected by SQL dynamic, as shown below in the code where insert statement will be repeated for each record in the CURSOR.

for rec in c1
loop


ABC: =' insert into test
Select a.*,' | recomm. OP_ID |', "' | recomm. OP_NAME | " 'of BL_testI' | recomm. OP_ID: ' where START_DATE > = trunc(sysdate-2) and START_DATE < trunc(sysdate-1)';

insert into str_test values (abc);

immediately run abc;

commit;

When exit c1% notfound;
end loop;

In a normal query I would do it spontaneously SQL COUNT but cannot use it here.

Thnx in advance

Just use SQL % ROWCOUNT. What is the problem with that?

Here is an example.

SQL > declare
l_sql 2 varchar2 (4000);
3. start
4 l_sql: = ' insert into t select * from emp';
5. immediately run l_sql;
6 dbms_output.put_line(l_sql ||) ': Number of inserted rows = ' | to_char(SQL%RowCount));)
7 end;
8.

insert into t select * from EMP: number of inserted rows = 11

PL/SQL procedure successfully completed.

SQL >

Tags: Database

Similar Questions

  • Retrieve and display a result set using the dynamic sql?

    Hi all

    How would display a result set in Oracle using the dynamic SQL? Reason being, the table where I'd retrieve and display the result set is a GLOBAL TEMP TABLE created in a stored procedure. If I try to use the loop as usual, the compiler complains that the table does not exist. This makes sense because the compiler does not recognize the table because it is created dynamically. Here is an example:

    create or replace PROCEDURE maketemptab IS
    sql_stmt VARCHAR2 (500);
    OutputString VARCHAR2 (50);

    BEGIN
    -create temporary table
    sql_stmt: = ' CREATE of TABLE TEMPORARY GLOBAL globtemptab (id NUMBER, col1 VARCHAR2 (50))';
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... created table ');

    -Insert a row into the temporary table
    sql_stmt: = "INSERT INTO globtemptab values (1, 'some data of a test')';"
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... inserted row ');

    -Insert a row into the temporary table
    sql_stmt: = ' INSERT INTO globtemptab values (2, "some more test data");
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... inserted row ');

    -Select the row on temporary table
    sql_stmt: = 'SELECT col1 FROM globtemptab WHERE id = 1';
    EXECUTE IMMEDIATE sql_stmt INTO outputstring;
    dbms_output.put_line ('... selected line: ' | outputstring);

    -drop temporary table
    sql_stmt: = 'DROP TABLE globtemptab;
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... moved table ');

    -display the result set
    for tabdata loop (select col1 from globtemptab)
    dbms_output.put_line ('... test of recovered data are' | tabdata.col1)
    end loop;
    end;


    In short, how to rewrite the SQL below the comment "to display the result set" using the dynamic sql?

    Thank you
    Amedeo.

    Hello

    Try this:

    CREATE OR REPLACE PROCEDURE maketemptab IS
       sql_stmt     VARCHAR2(500);
       outputstring VARCHAR2(50);
       v_cursor     SYS_REFCURSOR;
       v_col1       VARCHAR2(30);
    BEGIN
       -- create temp table
       sql_stmt := 'CREATE GLOBAL TEMPORARY TABLE globtemptab(id NUMBER, col1 VARCHAR2(50))';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...table created');
    
       -- insert row into temp table
       sql_stmt := 'INSERT INTO globtemptab values (1, ''some test data'')';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...row inserted');
    
       -- insert row into temp table
       sql_stmt := 'INSERT INTO globtemptab values (2, ''some more test data'')';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...row inserted');
    
       -- select row from temp table
       sql_stmt := 'SELECT col1 FROM globtemptab WHERE id=1';
       EXECUTE IMMEDIATE sql_stmt
          INTO outputstring;
       dbms_output.put_line('...row selected: ' || outputstring);
    
       OPEN v_cursor FOR 'SELECT col1 FROM globtemptab';
    
       LOOP
          FETCH v_cursor
             INTO v_col1;
          EXIT WHEN v_cursor%NOTFOUND;
          dbms_output.put_line('...test data retrieved is' || v_col1);
       END LOOP;
       CLOSE v_cursor;
    
       -- drop temp table
       sql_stmt := 'DROP TABLE globtemptab';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...table dropped');
    END;
    /
    

    Kind regards

  • using the dynamic SQL syntax

    I am trying to create a dynamic sql to execute the following statement:

    create the table mytbl_20100901 in select * from matbl double;

    When I try the following error I
    ORA-06550: line 6, column 10:
    PLS-00103: encountered the symbol "SELECT" at the expected in the following way:

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    declare
    sql_cmd varchar2 (1000);

    Start

    sql_cmd: = select "create table mytbl_ | To_char (sysdate, 'YYYYMMDD') | ' in select * from matbl ' double.

    immediately run sql_cmd;

    end;
    ;;;;;;;;;;;;;;;;;;;;;;;;;

    How to fix the sql_cmd assignment statement?

    Thank you.

    Hello

    user1035690 wrote:
    I am trying to create a dynamic sql to execute the following statement:

    create the table mytbl_20100901 in select * from matbl double;

    When I try the following error I
    ORA-06550: line 6, column 10:
    PLS-00103: encountered the symbol "SELECT" at the expected in the following way:

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    declare
    sql_cmd varchar2 (1000);

    Start

    sql_cmd: = select "create table mytbl_ | To_char (sysdate, 'YYYYMMDD') | ' in select * from matbl ' double.

    immediately run sql_cmd;

    end;
    ;;;;;;;;;;;;;;;;;;;;;;;;;

    How to fix the sql_cmd assignment statement?

    Thank you.

    The dual table is not necessary a lot in PL/SQL.
    You can simply say:

    sql_cmd := 'create table mytbl_' || TO_CHAR(sysdate, 'YYYYMMDD') || ' as select * from mytbl';
    dbms_output.put_line (sql_cmd || ' <= sql_cmd');
    -- EXECUTE IMMEDIATE sql_cmd;
    

    During the development of the dynamic SQL statements, I suggest that you post the command rather than run it first.
    When it seems correct, then a comment instructions EXECUTE IMMEDIATE.
    Before the Production code, remove or comment the call to out_line.

  • See the number of rows affected the performance of sqlplus to a sql file

    Hello

    It's just we have a sql file that contains a bunch of select/update/insert statements.

    I have a unix script that calls sqlplus on this sql file. However, at the exit I don't get the number of rows affected.

    Without adding any code in the input sql file, how can I change the code of sqlplus shell script to print the number of rows affected for each statement in the sql file?

    ${ORACLE_HOME}/bin/sqlplus -L >> ${LOG_FILE} 2>&1  << EOF
      ${ORAID}/${ORAPASS}@${ORAINS}
      whenever sqlerror exit sql.sqlcode;
      set echo on;
      set feedback off;
      set serveroutput on;
      @${SQL_FILE};
      exit;
    EOF
    RC=$?
    

    The SQL_FILE of entry content is:

    select 12 "col1" from dual;
    select 'abcd' "col2" from dual;
    select;
    select 13 'col3' from dual;
    

    The result of the race of sqlplus is (LOG_FILE):

    SQL*Plus: Release 11.2.0.2.0 Production on Fri Jun 6 14:28:00 2014
    
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    
    Enter user-name: 
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
    Data Mining and Real Application Testing options
    
    SQL> SQL> SQL> SQL> SQL> SQL> select 12 "col1" from dual;
    
          col1
    ----------
            12
    SQL> select 'abcd' "col2" from dual;
    
    col2
    ----
    abcd
    SQL> select;
    select
         *
    ERROR at line 1:
    ORA-00936: missing expression
    
    
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
    Data Mining and Real Application Testing options
    

    Thank you

    Srinivas - y.

    1. echo setting
    2. Set feedback off;

    use

    Set of feedback on

  • Insert rows in the PL/SQl table

    Hello
    I have a PL/SQl table that I filled through bulk collect and now I'm trying to loop through the table (actually quite a few nested loops)... Now in one of my curls, I might need to insert a new row by splitting the field in the existing row in the table. Can I insert the line in the pl/sql table in the loop without affecting the "FOR i IN tab.first... Tab.Last' loop?
    Also, what would be the index of such a line inserted into the table. Can I access it with tab.last + 1 (doesn't look like it can be done if I insert into various levels of loops).
    OR
    If I insert the lines insde loops nested, then I can access the new lines as soon as I close all the loops and open a new loop? The new lines will be at the last table.

    Any help will be appreciated...

    The expression v_arr. LAST gives the index of the last entry, so you can refer to this element as

    v_arr(v_arr.LAST)
    

    Then the attributes of this element will be

    v_arr(v_arr.LAST).attr
    

    for example

    DECLARE
        TYPE table_defs_tt IS TABLE OF user_tables%ROWTYPE INDEX BY PLS_INTEGER;
        v_mytables table_defs_tt;
    BEGIN
        SELECT * BULK COLLECT INTO v_mytables
        FROM   user_tables
        WHERE  ROWNUM <= 100;
    
        DBMS_OUTPUT.PUT_LINE(v_mytables(v_mytables.LAST).table_name);
    END;
    
  • How to pass the Record of entry to the dynamic SQL Code

    Hi all

    I am trying to run under Oracle applications API on the remote database using DB Link. I try to run using dynamic SQL. Part of the code is given below.

    DECLARE

    l_batch_info_rec wsh_picking_batches_pub.batch_info_rec;

    l_rule_id NUMBER;

    l_rule_name VARCHAR2 (240);

    l_batch_prefix VARCHAR2 (240);

    BEGIN

    l_batch_info_rec.document_set_id: = v_document_set_id;

    l_batch_info_rec.order_type_id: = v_order_type_id;

    l_batch_info_rec. Default_Stage_Subinventory: = v_default_stage_subinventory;

    l_batch_info_rec.pick_grouping_rule_id: = v_pick_grouping_rule_id;

    l_batch_info_rec.pick_sequence_rule_id: = v_pick_sequence_rule_id;

    l_batch_info_rec.autopack_level: = v_autopack_level;

    l_batch_info_rec.autopack_flag: = v_autopack_flag;

    l_batch_info_rec.ac_delivery_criteria: = v_ac_delivery_criteria;

    l_batch_info_rec.backorders_only_flag: = v_backorders_only_flag;

    l_batch_info_rec.existing_rsvs_only_flag: = v_existing_rsvs_only_flag;

    l_batch_info_rec.customer_id: = v_customer_id;

    l_batch_info_rec.order_header_id: = v_header_id;

    l_batch_info_rec.from_scheduled_ship_date: = NULL;

    l_batch_info_rec.organization_id: = v_organization_id;

    l_batch_info_rec.include_planned_lines: = v_include_planned_lines;

    l_batch_info_rec.autocreate_delivery_flag: = v_autocreate_deliveries_flag;

    l_batch_info_rec.autodetail_pr_flag: = v_autodetail_pr_flag;

    l_batch_info_rec.allocation_method: = 'I ';

    l_batch_info_rec.pick_from_locator_id: = NULL;

    l_batch_info_rec.auto_pick_confirm_flag: = 'n';         -The value manually to run Transact order

    l_batch_info_rec.autopack_flag: = 'n';         -Manually configure to perform the manual packaging

    l_rule_id: = NULL;

    l_rule_name: = NULL;

    l_batch_prefix: = NULL;

    v_sqlstmt1: = ' START

    wsh_picking_batches_pub.create_batch' | g_db_link | "(1.0,

    fnd_api.g_true,

    fnd_api.g_true,

    : l_return_status,.

    : l_msg_count,.

    : l_msg_data,.

    : l_rule_id,.

    : l_rule_name,.

    : l_batch_info_rec,.

    : l_batch_prefix,.

    : p_new_batch_id

    );

    END;';

    --

    EXECUTE IMMEDIATE V_sqlstmt1

    With the HELP OF THE l_return_status,.

    ON l_msg_count,.

    ON l_msg_data,.

    BY l_rule_id,

    BY l_rule_name,

    BY l_batch_info_rec,

    BY l_batch_prefix,

    OUT p_new_batch_id;

    --

    END;

    After you run this script, I get below error "PLS-00457: expressions must be SQL types ' for variable l_batch_info_rec which is of type record. can someone please guide me how can I pass variable type dynamic SQL record.

    Thank you

    Priyanka

    Food for thought:

    On remote db:

    SQL > create or replace
    package 2 pkg
    3 is
    4 type r_type is (record
    Number 5,
    6 name varchar2 (10)
    7                            );
    (p) 8 procedure
    9 p_rec in r_type,
    10 p_out out varchar2
    11                  );
    12 end;
    13.

    Package created.

    SQL > create or replace
    package 2 body pkg
    3 is
    4 procedure p)
    5 p_rec in r_type,
    6 p_out out varchar2
    7                  )
    8 is
    9 start
    10 p_out: = "ID = ' |" p_rec.ID | 'Name =' | p_rec. Name;
    11 end;
    12 end;
    13.

    Package body created.

    SQL >

    On local db:

    SQL > set serveroutput on
    SQL > declare
    v_rec 2 pkg.r_type@pdb1sol12;
    3 v_out varchar2 (50);
    4 start
    v_rec.ID 5: = 1;
    6 v_rec.name: = 'XXX ';
    7 immediate execution"
    8                        begin
    9 pkg.p@pdb1sol12 (: 1,: 2);
    10                        end;'
    11 using v_rec,
    12 v_out;
    13 dbms_output.put_line (v_out);
    14 end;
    15.
    using v_rec;
    *
    ERROR on line 11:
    ORA-06550: line 11, column 20:
    PLS-00457: expressions must be SQL types
    ORA-06550: line 7, column 5:
    PL/SQL: Statement ignored

    SQL > declare
    2 number of v_id: = 1;
    3 v_name varchar2 (10): = 'XXX ';
    4 v_out varchar2 (50);
    5. start
    6 immediate execution"
    7 report
    8 v_rec pkg.r_type@pdb1sol12.
    9                        begin
    10                            v_rec.id  := :1;
    11 v_rec.name: =: 2;
    12 pkg.p@pdb1sol12 (v_rec,: 3);
    13                        end;'
    14 using v_id,
    15 in v_name,
    16 v_out;
    17 dbms_output.put_line (v_out);
    18 end;
    19.
    ID = 1 name = XXX

    PL/SQL procedure successfully completed.

    SQL >

    SY.

  • Dynamic recovery for the dynamic sql query

    Hi all

    I want to create a query dynamically and to fetch it in a dynamic cursor record... The structure of the record should be the same as that of the query...
    Can you suggest any method to do this.

    for example

    OPEN < dynamic news > TO < dynamic stmt >;
    LOOP
    FETCH < dynamic news > < DYNAMIC rec >;
    ---
    END LOOP;
    CLOSE < dynamic news >;

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Thank you
    Merz

    Published by: merz Sep 12, 2011 17:02

    Published by: merz Sep 12, 2011 17:03

    Merz says:

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Is not possible. What you describe is called four dynamic sql type. For this type of synamic SQL, you use the DBMS_SQL package.

    SY.

  • alternate colors of rows in the dynamic table?

    Hi all

    I know the line replacement colors are easily achievable on static tables using the class styles. Does anyone know if this can be implemented on the pages dynamically display multiple records?

    Yes, it's very easy to do. The actual coding depends on your language on the server side. The basic principle is to use the modulo operator (%) with a counter that is incremented on each iteration of the loop.

    Modulo division produced the rest of a sum of division. So, if you use modulo division on the counter and divide the meter by 2, the result will alternate between 1 and 0, which can be used to determine which class to apply to the current line.

    In PHP:

    >
    
    
    
    

    Create a style for all rows in the table and another for the hilite class rule. Stripes.

  • execute the dynamic sql statement

    Hi all

    CREATE TABLE  XX_OFFICE_USER_IMP 
      (
        ID              NUMBER,
        OFFICE          VARCHAR2(10 BYTE),
        USER_NAME       VARCHAR2(10 BYTE),
        BANK_ACCOUNT_ID NUMBER,
        TRANSFERED      NUMBER
      )
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (421,'0000','F0000',10029,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (422,'0000','F0000',10031,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (423,'0000','F0000',10033,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (424,'0000','F0000',10036,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (425,'0000','F0000',10037,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (426,'0000','F0000',10039,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (427,'0000','F0000',10041,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (428,'0000','F0000',10046,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (429,'0000','F0000',10048,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (430,'0000','F0000',10067,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (431,'0000','F0000',10072,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (432,'0000','F0000',10087,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (433,'0000','F0000',10092,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (434,'0000','F0000',10008,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (435,'0000','F0000',10012,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (436,'0000','F0000',10013,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (437,'0000','F0000',10014,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (438,'0000','F0000',10017,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (439,'0000','F0000',10019,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (440,'0000','F0000',10024,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (441,'0000','F0000',10025,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (442,'0000','F0000',10001,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (443,'0000','F0000',10002,null);
    CREATE TABLE XXBG_CASIER_CASH
      (
        CASHIER         VARCHAR2(32 BYTE),
        BANK_ACCOUNT_ID NUMBER(38,0)
      )
    declare 
    v_exe_grant varchar2(32767 char);
    begin 
    
    
    for i in (select * from xx_office_user_imp where office = '0000') loop
    
      insert into XXBG_CASIER_CASH values (i.user_name, i.bank_account_id);
    
      v_exe_grant := 
                     'create user '  || i.user_name || ' identified by ' || i.user_name || ';' 
                  || 'GRANT create session to ' || i.user_name || ';' 
                  || 'GRANT select on apps.XXBG_CE_STATEMENT_HEADERS_CASH to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.FND_USER TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.dFND_DESCR_FLEX_COL_USAGE_TL TO ' || i.user_name || ';' 
                  || 'GRANT select on apps.fnd_descr_flex_column_usages to ' || i.user_name || ';' 
                  || 'GRANT select on apps.fnd_descriptive_flexs to ' || i.user_name || ';' 
                  || 'GRANT select on apps.fnd_descriptive_flexs_tl to ' || i.user_name || ';' 
                  || 'GRANT select on ce.ce_statement_headers to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.fnd_doc_sequence_assignments TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON CE.CE_STATEMENT_HEADERS_S TO ' || i.user_name || ';' 
                  || 'GRANT EXECUTE ON APPS.XXBG_GET_NEXTVAL TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON CE.CE_STATEMENT_LINES TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.XXBG_CE_STATEMENT_LINES TO ' || i.user_name || ';' 
                  || 'GRANT select on apps.CE_BANK_ACCOUNTS to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.CE_BANK_BRANCHES_V TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON CE.XXBG_CASIER_CASH TO ' || i.user_name || ';' 
                  || 'GRANT EXECUTE ON APPS.XXBG_ST TO ' || i.user_name || ';' 
                  || 'GRANT select on ce.xxbg_ce_statement_lines_detail to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.ce_transaction_codes TO ' || i.user_name || ';' 
                  || 'GRANT select on ce.ce_statement_lines_s to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON CE.XXBG_CE_STATEMENT_LINES_DET_SQ TO ' || i.user_name || ';' 
                  || 'GRANT select on apps.xx_pko_lines to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON apps.xx_rko_lines TO ' || i.user_name || ';' 
                  || 'GRANT select on apps.XX_INVOICE_RELATIONS_CASH to ' || i.user_name || ';' 
                  || 'GRANT select on APPS.PO_VENDOR_SITES_ALL to ' || i.user_name || ';' 
                  || 'GRANT select on ap.AP_INVOICE_LINES_INTERFACE_S to ' || i.user_name || ';' 
                  || 'GRANT select on ap.AP_INVOICE_LINES_INTERFACE to ' || i.user_name || ';' 
                  || 'GRANT select on APPS.ap_distribution_set_lines_all to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.AP_INVOICES_INTERFACE_S TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.AP_INVOICES_INTERFACE TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.AP_DISTRIBUTION_SETS_ALL  TO ' || i.user_name || ';' 
                  || 'GRANT select on apps.ce_lookups  to ' || i.user_name || ';' 
                  || 'GRANT select on ar.HZ_CUST_SITE_USES_ALL to ' || i.user_name || ';' 
                  || 'GRANT select on ar.HZ_LOCATIONS to ' || i.user_name || ';' 
                  || 'GRANT select on ar.HZ_PARTIES to ' || i.user_name || ';' 
                  || 'GRANT select on ar.HZ_PARTY_SITES to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON AR.HZ_CUST_ACCT_SITES_ALL TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON AR.HZ_CUST_ACCOUNTS TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.XXBG_CLAIMS_V TO ' || i.user_name || ';' 
                  || 'GRANT select on apps.xxbg_insis_agents_v to ' || i.user_name || ';' 
                  || 'GRANT select on ce.xxbg_cash_doc_types to ' || i.user_name || ';' 
                  || 'GRANT select on AP.AP_BANK_ACCOUNTS_ALL to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON AP.AP_BANK_BRANCHES TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.FND_DESCR_FLEX_CONTEXTS TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.FND_DESCR_FLEX_CONTEXTS_TL TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.AP_SUPPLIERS to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.per_employees_x TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.fnd_doc_seq_categories_ap_v TO ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.AP_LC_INVOICE_TYPES_V to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON ce.xxbg_ce_statement_lines_sq to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.XXBG_STATEMENT_HEADERS_CASH to ' || i.user_name || ';' 
                  || 'GRANT SELECT ON APPS.XXBG_INSIS_POLICY_V TO ' || i.user_name || ';' 
                  || 'GRANT insert  ON ce.ce_statement_lines to ' || i.user_name || ';' 
                  || 'GRANT INSERT  ON CE.XXBG_CE_STATEMENT_LINES_DETAIL TO ' || i.user_name || ';' 
                  || 'GRANT INSERT ON APPS.AP_INVOICES_INTERFACE TO ' || i.user_name || ';' 
                  || 'GRANT INSERT ON APPS.AP_INVOICE_LINES_INTERFACE TO ' || i.user_name || ';' 
                  || 'GRANT INSERT ON APPS.XX_RKO_LINES TO ' || i.user_name || ';' 
                  || 'GRANT INSERT ON APPS.XX_PKO_LINES TO ' || i.user_name || ';' 
                  || 'GRANT delete on ce.xxbg_ce_statement_lines_detail to ' || i.user_name || ';' 
                  || 'GRANT update on ce.XXBG_CE_STATEMENT_LINES_DETAIL to ' || i.user_name || ';' 
                  || 'GRANT DELETE ON CE.CE_STATEMENT_LINES TO ' || i.user_name || ';' 
                  || 'GRANT INSERT ON CE.CE_STATEMENT_HEADERS TO ' || i.user_name || ';' 
                  || 'GRANT update on CE.CE_STATEMENT_HEADERS to ' || i.user_name || ';' 
                  || 'GRANT update on ce.CE_STATEMENT_LINES to ' || i.user_name || ';' 
                  || 'GRANT select on apps.XX_AGENTS_NO_V to ' || i.user_name || ';' ;
                  
                  
      execute immediate v_exe_grant;
      
    update xx_office_user_imp
      set transfered = 1 
      where id = i.id
    ;
    
    v_exe_grant := '';
    end loop;
    
    end;
    /
    After execute the PL/SQL block I get the message:
    Error report:
    ORA-00911: invalid character
    ORA-06512: at line 79
    00911. 00000 -  "invalid character"
    *Cause:    identifiers may not start with any ASCII character other than
               letters and numbers.  $#_ are also allowed after the first
               character.  Identifiers enclosed by doublequotes may contain
               any character other than a doublequote.  Alternative quotes
               (q'#...#') cannot use spaces, tabs, or carriage returns as
               delimiters.  For all other contexts, consult the SQL Language
               Reference Manual.
    *Action:
    Any ideas? I think I call correct immediate execution.

    DB version: 11g

    Unfortunately I can't provide you the sql code of the other tables to create their... Maybe you should try without all budgets... :)


    Thanks in advance,
    Bahchevanov.

    Edited by: bahchevanov on 11 October 2012 06:14

    Bahchevanov wrote:
    Any ideas?

    Sure. EXECUTE IMMEDIATE executes a unique statement when you try to run the job. So use:

    execute immediate 'create user '  || i.user_name || ' identified by ' || i.user_name;
    execute immediate 'GRANT create session to ' || i.user_name;
    execute immediate 'GRANT select on apps.XXBG_CE_STATEMENT_HEADERS_CASH to ' || i.user_name;
    .
    .
    .
    

    SY.

  • How to integrate the dynamic SQL generated in the data definition XML file?

    Hi all

    I have it here is the XML file that is attached to the definition of data model RTF as below. Also, I have a function that will return to create a dynamic query as shown below.

    <?xml version="1.0" encoding="UTF-8"?> 
    <dataTemplate name="XYZ" description="iExpenses Report" Version="1.0"> 
    <dataQuery> 
    <sqlStatement name="Q2"> 
    <![CDATA[
    

    Hi guys,.

    I was able to solve above the requirement. It was not possible to create only from SQL dynamically. Instead, I created a procedure that would create & update (attached to the data definition) XML file dynamically for each race.

    Kind regards

    Patricia K.

  • Break the dynamic SQL

    All,

    I try to print after statement in two lines

    MY NAME IS XYZ;
    GOT IT;

    I'm trying yo use code similar to the one below, but it keeps me gives error
    select 'MY NAME IS XYZ;
             GOT IT'
    from dual;
    How can I reach above in sqlplus itself?

    Hello

    When I try in SQL * Plus, it looks like SQL * Plus is to make an analysis and interprets them. at the end of a line as the end of a statement.
    Try to hide the semicolon within the line, like this:

    select 'MY NAME IS XYZ;' || '
             GOT IT'            AS txt
    from dual;
    

    Output:

    TXT
    -------------------------------
    MY NAME IS XYZ;
             GOT IT
    

    Otherwise, SQL * more seems to do this kind of analysis before it resolves the substitution variables, then the following also works:

    DEFINE sym = ";"
    
    select 'MY NAME IS XYZ&sym
             GOT IT'            AS txt
    from dual;
    
  • Export form data to a spreadsheet to repeat the rows in the dynamic table

    My form has a table near the top that has a table row that is repeated when a button is clicked. Some users of the form click this button only once and others can click twice or several times. How to export data when the same form may contain a different number of these fields?

    Hello

    Each instance of the repeating line will have its own set of columns in the worksheet. So if one of the returned forms had five instances of the repeating line, then the spreadsheet merged would have five sets of columns. When one of the returns had only a single instance, then it can only contain data in the first set of columns in the worksheet.

    Hope that helps,

    Niall

  • Using of the dynamic SQL and the cursor in a procedure

    Here is the procedure:
    create or replace
    Procedure type_paiement_total
    is
    
        cursor xbtable is select table_name from user_tables where table_name like 'XB%';
        n_table user_tables.table_name%type;
        req     varchar2(256);
        journal varchar2(2);
        mois varchar2(2);
        an varchar2(2);
      begin
        for n_table in xbtable
        loop
          execute immediate 'insert into xx_jk_xb (
          clie_code,journal, periode,origine, xb_ecri,xb_libe  ,dos_code,xb_debi,xb_cred,xb_term
    )
    select c.code,  
    substr(:1,3,2),
    substr(:1,7,2)||substr(:1,5,2)||,
    :1,  
    xb.ecri,  
    xb.libe,  
    d.code,
    xb.debi,
    xb.cred,
    xb.terme
    from                      
    '||n_table.table_name ||' xb,
    dossier d,                      
    client c                    
    where xb.cmpt=''4111''                    
    and xb.doss  =d.code                    
    and c.code   =d.clie
    and c.role=''1''' using n_table.table_name;
          execute immediate 'insert into xx_jk_logxb (recnum,xb_ref,trsf) values (seq_logmreg.nextval,:1,''OK'')' using n_table.table_name;
          commit;
          fetch xbtable into n_table;
        end loop;
      end;
    What he does (or what I intend to do)
    take the datas of a whole bunch of pictures and put them in the "XX_JK_XB" table and make a log of the tables covered in xx_jk_logxb give just the source table and the status (OK).
    Now when I run the procedure I get a "missing expression" th ' immediate «insert into xx_jk...»» »

    I just can't tell what is the problem here.

    clues?

    Seems to me that you are wrong assuming that the binding can be done by name and no position when you use immediate enforcement.

    Example:

    SQL> create table foo_tab( c1 varchar2(10), n1 number );
    
    Table created.
    
    SQL>
    SQL> begin
      2          for i in 1..10
      3          loop
      4                  execute immediate 'insert into foo_tab values( to_char(:1), :1 )' using i;
      5          end loop;
      6          commit;
      7  end;
      8  /
    begin
    *
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-06512: at line 4
    
    SQL>
    SQL>
    SQL> begin
      2          for i in 1..10
      3          loop
      4                  execute immediate 'insert into foo_tab values( to_char(:1), :1 )' using i,i;
      5          end loop;
      6          commit;
      7  end;
      8  /
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    As you can see, 1 PL/SQL block attempts to re - use bind variable: 1 new - and only link once.

    Fact does not work like that - you must link it again. Binding is done by bind - 1 position = 1 to the help of var, 2nd = 2nd bind using var, etc.. Name of the connection variable used is irrelevant and not unique.

  • How the date can be filled with timestamp in dynamic sql

    Hi all

    Below we have sql

    v_stmt: = ' MERGE IN MTH_EQUIPMENTS_EXT_B ED

    WITH THE HELP OF)

    SELECT TAG_DATA,

    EQUIPMENT_FK_KEY,

    WORKORDER_FK_KEY,

    SEGMENT_FK_KEY,

    SHIFT_WORKDAY_FK_KEY,

    HOUR_FK_KEY,

    ITEM_FK_KEY,

    READ_TIME,

    ATTR_GROUP_ID,

    RECIPE_NUM,

    RECIPE_VERSION,

    NVL (FND_GLOBAL. User_Id,-1) l_updated_by,.

    NVL (FND_GLOBAL. Login_Id,-1) l_last_update_login

    OF MTH_TAG_READINGS_T_STG

    WHERE DB_COL = ' | " ' || v_colname | " ' ||') TS

    WE (';)

    v_stmt: = v_stmt | "ED. EQUIPMENT_PK_KEY = TS. EQUIPMENT_FK_KEY AND

    ED. READ_TIME = TS. READ_TIME AND

    ED. ATTR_GROUP_ID = TS. ATTR_GROUP_ID)

    WHEN MATCHED THEN

    UPDATE

    GAME ED.'. v_colname |' = TS. TAG_DATA,

    ED. LAST_UPDATED_BY = 1, ";

    v_stmt: = v_stmt | "ED. LAST_UPDATE_LOGIN = TS.l_last_update_login

    WHEN NOT MATCHED THEN

    INSERT ('| v_colname |', EXTENSION_ID, EQUIPMENT_PK_KEY, WORKORDER_FK_KEY, SEGMENT_FK_KEY, SHIFT_WORKDAY_FK_KEY, HOUR_FK_KEY, ITEM_FK_KEY, READ_TIME, ATTR_GROUP_ID, LAST_UPDATE_DATE, LAST_UPDATED_BY,';)

    v_stmt: =.

    v_stmt | ("LAST_UPDATE_LOGIN, CREATED_BY, CREATION_DATE, RECIPE_NUM, RECIPE_VERSION)

    VALUES (TS. TAG_DATA, EGO_EXTFWK_S.NEXTVAL, TS. EQUIPMENT_FK_KEY, TS. WORKORDER_FK_KEY, TS. SEGMENT_FK_KEY, TS. SHIFT_WORKDAY_FK_KEY, TS. HOUR_FK_KEY, TS. ITEM_FK_KEY, TS. READ_TIME,';

    v_stmt: = v_stmt | "TS. ATTR_GROUP_ID,' | '''|| SYSDATE | "'| ', 1, TS.l_last_update_login, TS.l_updated_by,'|"' | SYSDATE | " ' ||', TS. RECIPE_NUM, TS. RECIPE_VERSION)';

    EXECUTE IMMEDIATE v_stmt;

    After you run the above SQL last date of update in MTH_EQUIPMENST_EXT_B is filled with sysdate but timestamp is not its always 00:00:00. Can we have timestamp also populated through dynamic sql in the last update date

    Kind regards

    Amrit

    Values to hardcode in the dynamic SQL - never use bind variables:

    v_stmt: = ' MERGE IN MTH_EQUIPMENTS_EXT_B ED

    WITH THE HELP OF)

    SELECT TAG_DATA,

    EQUIPMENT_FK_KEY,

    WORKORDER_FK_KEY,

    SEGMENT_FK_KEY,

    SHIFT_WORKDAY_FK_KEY,

    HOUR_FK_KEY,

    ITEM_FK_KEY,

    READ_TIME,

    ATTR_GROUP_ID,

    RECIPE_NUM,

    RECIPE_VERSION,

    NVL (FND_GLOBAL. User_Id,-1) l_updated_by,.

    NVL (FND_GLOBAL. Login_Id,-1) l_last_update_login

    OF MTH_TAG_READINGS_T_STG

    WHERE DB_COL =: 1) TS

    WE (';)

    v_stmt: = v_stmt | "ED. EQUIPMENT_PK_KEY = TS. EQUIPMENT_FK_KEY AND

    ED. READ_TIME = TS. READ_TIME AND

    ED. ATTR_GROUP_ID = TS. ATTR_GROUP_ID)

    WHEN MATCHED THEN

    UPDATE

    GAME ED.'. v_colname |' = TS. TAG_DATA,

    ED. LAST_UPDATED_BY = 1, ";

    v_stmt: = v_stmt | "ED. LAST_UPDATE_LOGIN = TS.l_last_update_login

    WHEN NOT MATCHED THEN

    INSERT ('| v_colname |', EXTENSION_ID, EQUIPMENT_PK_KEY, WORKORDER_FK_KEY, SEGMENT_FK_KEY, SHIFT_WORKDAY_FK_KEY, HOUR_FK_KEY, ITEM_FK_KEY, READ_TIME, ATTR_GROUP_ID, LAST_UPDATE_DATE, LAST_UPDATED_BY,';)

    v_stmt: =.

    v_stmt | ("LAST_UPDATE_LOGIN, CREATED_BY, CREATION_DATE, RECIPE_NUM, RECIPE_VERSION)

    VALUES (TS. TAG_DATA, EGO_EXTFWK_S.NEXTVAL, TS. EQUIPMENT_FK_KEY, TS. WORKORDER_FK_KEY, TS. SEGMENT_FK_KEY, TS. SHIFT_WORKDAY_FK_KEY, TS. HOUR_FK_KEY, TS. ITEM_FK_KEY, TS. READ_TIME,';

    v_stmt: = v_stmt | "TS. ATTR_GROUP_ID,: 2, 1, TS.l_last_update_login, TS.l_updated_by,: 3, TS. RECIPE_NUM, TS. RECIPE_VERSION)';

    V_stmt EXECUTE IMMEDIATE

    With the HELP of v_colname,.

    SYSDATE,

    SYSDATE;

    SY.

  • Design of the dynamic schema through SQL

    Hi all

    Is it possible to design a dynamic schema using SQL?
    Documents or links is greatly appreciated.

    Thank you

    Hello

    Sorry, I don't get you. Design of a scheme is more than dynamic SQL, you must think of tables, relationships, constraints, standardization, etc.. On the dynamic SQL statements, see [using dynamic SQL statements | http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/dynamic.htm#CACDDACH]

    Kind regards

Maybe you are looking for