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.

Tags: Database

Similar Questions

  • 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.

  • Custom on-the-fly SQL statement

    Is it possible to build the dynamic SQL statement in the DB adapter on the fly?

    You can do bulk collect and return the collection of pl/sql procedure.

    Prasanna-

  • 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

  • Run the second sql statement only if the first sql statement is set to zero.

    Hey guys I seem to have a mental block here. I have two sql statements. I would like to than the second to run only if the first sql statement is set to zero. I know that I can use PLsql but I would really like to see if I can do this with sql upward. Your answers are very much appreciated.
    This is the first sql
      Select     ft.fund_code, 
                 ft.orgn_code, 
                 ft.acct_code, 
                 ft.amount, 
                 fb.owner_pidm, 
                 ft.prog_code      
          from ftrbremb fb , ftcractg ft
          where fb.doc_code = 'TR000038'
          and fb.ftpbport_id = ft.ftpbport_id
    second sql statement
         Select ft.fund_code, 
                 ft.orgn_code, 
                 ft.acct_code, 
                 ft.amount, 
                 fb.owner_pidm, 
                 ft.prog_code      
          from ftrbremb fb , ftcractg ft, ftprexps fx
          where fb.doc_code = 'TR000038'
          --and fb.ftpbport_id = ft.ftpbport_id
          and fx.ftrbremb_id = fb.id
          and ft.ftprexps_id = fx.id;
    How can I combine these two statements together so that when the first is null the second run. As a bonus, I want to get just the first line as well.
    Any help would be greatly appreciated. I tried to accomplish with the case statement but it dosent everything seems to work for me.
    Thank you

    Miguel,

    the idea is simple: join the two queries (via the union of all) and to change the second part as to return only the rows if the first query returns no rows by changing the NOT EXISTS (first request). Hope I made it clear... ;)

  • Zero error of iteration - the treatment of dynamic sql statements in dbms_xmlgen

    Hello

    I have a procedure that creates a dynamic sql v_sql

    cursor v_curr is
    Select *.
    of btctl_msg_log;

    BEGIN
    Select count (*) in the v_cnt of btctl_msg_log;

    IF v_cnt > 0 THEN
    C1 in v_curr
    LOOP
    v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
    Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;

    gives me an error

    ORA-19202: an error has occurred in the processing of XML
    ORA-24333: zero number of iterations
    ORA-06512: at "SYS." DBMS_XMLGEN", line 288
    ORA-06512: at line 1

    I don't know why is this error happening.
    Any help much appreciated.

    881575 wrote:
    Hello

    I have a procedure that creates a dynamic sql v_sql

    cursor v_curr is
    Select *.
    of btctl_msg_log;

    BEGIN
    Select count (*) in the v_cnt of btctl_msg_log;

    IF v_cnt > 0 THEN
    C1 in v_curr
    LOOP
    v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
    Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;

    gives me an error

    ORA-19202: an error has occurred in the processing of XML
    ORA-24333: zero number of iterations
    ORA-06512: at "SYS." DBMS_XMLGEN", line 288
    ORA-06512: at line 1

    I don't know why is this error happening.
    Any help much appreciated.

    Standard when boards (ab) use of EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the variable before passing to EXECUTE IMMEDIATE.
    COPY the statement & PASTE in sqlplus to validate its correctness.

  • Helps with the syntax of dynamic sql statements

    Hi all
    How can I pass the value of the result of my dynamic select statement to a Ref Cursor?
    I try the following statement but does not work, I get this error:
    ORA-00932: inconsistent data types: expected - was - ORA-06512: at
    Procedure getItems(v_first In number, v_second In Number, arg_Cursor IN OUT CUSTOM_REF_CURSOR) is
         sqlString varchar(3000);
         Begin
           sqlString := 'select* from bla where o.arg_1 = :1 and arg_2 = :2'; 
       
           execute immediate sqlString 
           into arg_Cursor
           using v_first, v_second;
       End getItems;
    Any ideas?
    Thank you

    Johnny
    PROCEDURE getitems (v_first IN NUMBER, v_second IN NUMBER, arg_cursor IN OUT sys_refcursor)
    IS
      sqlstring   VARCHAR (3000);
    BEGIN
      sqlstring := 'select* from bla where o.arg_1 = :1 and arg_2 = :2';
    
      OPEN arg_cursor FOR sqlstring USING v_first, v_second;
    END getitems;
    
  • GETTING AN ERROR - slider 'P_REFCUR' cannot be used in the OPEN dynamic SQL stat

    DECLARE
    create or replace procedure partial_single (p_fileid in NUMBER, p_filename IN VARCHAR2 (2000), p_temptablename IN VARCHAR2 (2000), p_temppartialtablename IN VARCHAR2 (2000), p_retval ON the NUMBER)
    --)

    p_fileid NUMBER;
    p_filename VARCHAR2 (2000);
    p_temptablename VARCHAR2 (2000);
    p_temppartialtablename VARCHAR2 (2000);
    p_retval NUMBER;
    p_refcur types_pkg.return_cur;
    v_strquery varchar2 (4000);

    BEGIN

    p_fileid: = 5080;
    p_filename: = "TAGSUR1HM2011013111160838654.000019265";
    -p_temptablename: = "TEMP_RECORDS_MED_0004";
    p_temptablename: = 'TEMP_RECORDS_MED_DATE ';
    p_temppartialtablename: = 'TEMP_MED_PARTIAL_RECORDS_0002 ';
    p_retval: = 0;


    v_strquery: = 'SELECT imsi, connectedcallingnumber, callstart MIN (calleventstarttimestamp), SUM (calleventduration), MAX (sequence_number) sequencenumber, msisdn, max (callreleasetime) callreleasetime period';
    v_strquery: = v_strquery | ' A ' | p_temppartialtablename | ' GROUP BY connectedcallingnumber, imsi, msisdn';

    OPEN p_refcur - GETTING AN ERROR - slider 'P_REFCUR' cannot be used in a dynamic OPEN SQL statement
    FOR v_strquery;

    FOR CC IN (SELECT imsi,
    connectedcallingnumber,
    Callstart MIN (calleventstarttimestamp),
    Duration of the SUM (calleventduration),
    SequenceNumber MAX (sequence_number),
    MSISDN,
    Max (callreleasetime) callreleasetime
    OF TEMP_MED_PARTIAL_RECORDS_0002
    GROUP BY connectedcallingnumber, imsi, msisdn)

    LOOP

    UPDATE TEMP_RECORDS_MED_DATE
    SET calleventstarttimestamp = cc.callstart,
    calleventduration = calleventduration + cc.duration
    WHERE connectedcallingnumber = cc.connectedcallingnumber
    AND imsi = cc.imsi
    AND sequencenumber = cc.sequencenumber + 1
    AND msisdn = cc.msisdn
    AND calleventstarttimestamp = cc.callreleasetime;


    IF SQL % ROWCOUNT > 0
    THEN
    UPDATE TEMP_MED_PARTIAL_RECORDS_0002
    SET isprocessed = 1
    WHERE connectedcallingnumber = cc.connectedcallingnumber
    AND imsi = cc.imsi
    AND msisdn = cc.msisdn;
    - AND callreleasetime = cc.callreleasetime;

    ON THE OTHER

    UPDATE TEMP_MED_PARTIAL_RECORDS_0002
    SET calleventduration = calleventduration + cc.duration
    IMSI WHERE = cc.imsi
    AND msisdn = cc.msisdn
    AND callreleasetime = cc.callreleasetime
    AND calleventduration! = cc.duration;


    END IF;

    END LOOP;


    REMOVE FROM TEMP_MED_PARTIAL_RECORDS_0002
    WHERE isprocessed = 1;


    p_retval: = 0;

    -VALIDATION;
    / * EXCEPTION
    WHILE OTHERS
    THEN
    -RESTORATION;
    p_retval: = 1;
    p3_errorlog ("partial" p_fileid, SQLERRM, |) ':' || p_filename);
    COMMIT;
    */
    END;

    Is - what your refcursor has a return type? In this case you can not open it with dynamic SQL. Change the Refcursor as a weakly typed cursor and give it a try.

  • 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.

  • problems with my dynamic sql statement

    Hello

    I'm not a pl/sql developer, but just trying to write a simple piece of pl/sql code. My intentions are simple. I want to find all tables with a specified column name, with a specific value in that column. Also, I just want to print these tables which have information in them.

    I have read the documentation on oracle to find this information, but I can't seem to get this to work, and I don't see what my problem...

    Here is the code I wrote.

    declare

    number of v_number;
    sql_statement varchar2 (200);

    cursor pick_table is
    Select the table table_name from user_tab_columns
    where upper (column_name) = upper ('md_file_id');

    Start
    because me in pick_table
    loop

    sql_statement: = ' SELECT count (*) from "| i.table_name | 'where md_file_id = 22410';
    dbms_output.put_line (sql_statement);
    EXECUTE IMMEDIATE sql_statement in v_number;
    dbms_output.put_line ('number' | v_number);

    If v_number > 0
    then
    dbms_output.put_line (i.table_name);
    end if;

    end loop;
    end;
    /

    This works perfectly well if I try not to insert the table_name dynamically using i.table_name and a writing of the database table names in the select statement. It runs also fine if I take "v_number" information on my execute immediate command.
    Of course I can't do it with logic I.

    What is happening is that the procedure is pretending to hang himself.

    I'd appreciate any help that can be given.

    Thanks in advance

    user10869417 wrote:
    ...
    What is happening is that the procedure is pretending to hang himself.

    It doesn't seem to be anything wrong with your code. It seems that you have:

    has a lot of tables in your schema with the column MD_FILE_ID (perhaps having value 22410), or
    (b) you have only a few tables but huge with this column

    In my test with only 1 db such table, your PL/SQL block is running almost instantly:

    test@XE>
    test@XE> --
    test@XE> drop table t;
    
    Table dropped.
    
    test@XE> create table t as
      2  select 22410 md_file_id from dual;
    
    Table created.
    
    test@XE>
    test@XE> set timing on
    test@XE>
    test@XE> @test.sql
    test@XE> declare
      2    v_number number;
      3    sql_statement varchar2(200);
      4    cursor pick_table is
      5      select table_name from user_tab_columns
      6      where upper(column_name) = upper('md_file_id');
      7  begin
      8    for i in pick_table
      9    loop
     10      sql_statement := 'SELECT count(*) from ' || i.table_name || ' where md_file_id = 22410';
     11      dbms_output.put_line(sql_statement);
     12      EXECUTE IMMEDIATE sql_statement into v_number;
     13      dbms_output.put_line('count returned ' || v_number);
     14      if v_number > 0
     15      then
     16        dbms_output.put_line(i.table_name);
     17      end if;
     18    end loop;
     19  end;
     20  /
    SELECT count(*) from T where md_file_id = 22410
    count returned 1
    T
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.33
    test@XE>
    test@XE>  
    

    which means that if you wait long enough, the pl/sql block will reach eventually up to completion.

    isotope

  • Char invalid when you use dynamic sql statements with cursor

    Hello guys,.
    I'm opening a following cursor with dynamic sql
     v_sql := 'SELECT OS.table_name FROM OBJECT_STATS_CONTROL OS, ALL_TABLES AT
                    WHERE OS.analyze_flag <> ''N''
                    AND OS.last_analyze < sysdate -1 AND AT.last_analyzed < sysdate - 1 '||v_1||';'; 
    my cursor statement is
    BEGIN
           OPEN v_cur FOR v_sql; 
           LOOP
           FETCH v_cur INTO v_tabname;
    ......
    I get an error message
    0911 invalid char
    can any body suggest me where I'm wrong

    Thank you

    Remove the semicolon at the end:

    ||';'  -- remove this.
    
  • Use of ROWID in the Update SQL statement

    Hi all

    I have an update statement that uses the rowid column to make the selection on the target table. Since a rowid represents the physical location of a row on disc, we know that this reference may change when various activities are conducted on the line of database/table/etc...

    Here is an example of the statement I post:

    UPDATE tabA outertab SET col1 = 'value '.
    WHERE EXISTS (SELECT 1 FROM tabA innertab WHERE outertab.) ROWID = outertab. ROWID AND...)

    Of course, the inner query is more complicated and uses other tables etc. but for the purposes of the example we don't need to include the details.

    My question is: what help rowid in a single statement SQL as a reference of a subquery in the outer statement is there a risk that outdoor activities can change the rowid and these changes be reflected in the session database that my query is executed which causes an incompatibility between the clause SQL internally and externally?

    In response to the question that will follow this post: 'why don't you just use a PK', we would like to avoid to maintain a PK on the table that we are talking about very large volumes of data and we do not want to have to appeal to a sequence, if we can avoid when we insert the data. If however there is a risk that this Update statement may fail, or update lines badly, then we might have to use a PK.

    I know there are a lot of discussions about this, but I havnt been able to find one that someone answered with any kind of confidence or clarity, any help would be appreciated.

    Thank you

    Keith

    Edited by: Turtle on March 5, 2009 05:24

    When using rowid in a single statement SQL as a reference of a subquery in the outer statement is there a risk that outdoor activities can change the rowid and these changes be reflected in the session database that my query is executed which causes an incompatibility between the clause SQL internally and externally?

    No, it's safe to use rowid in this query type. Docs

    A line assigned ROWID remains unchanged, unless the line is exported and imported using the import and export utilities. When you delete a row in a table, then commit the transaction enclosing, rowid of the deleted row can be attributed to a line inserted in a subsequent operation.

  • How to see all passed to the db sql statements?

    Is it possible to configure Jdevloper (11.1.1.4) in a way so that it shows all the sql statements in the console?

    THX in advance

    You have restarted your WLS instance in debug mode?

  • 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.

  • How to execute the pl/sql block from a file

    Hi all
    can someone tell me how to execute a pl/sql block to a file.it does contain no procedures.it is of the form
    -Start
    -says
    -end;

    Thanx

    Ok.. If the time points? :)

    See you soon!
    Bobin

Maybe you are looking for

  • IPad is disabled connect to itunes!

    After that installation of 9.3 ipad update request for access code that this ipad ever now after too much attepts ipad is disabled connect to itunes when I said that I have to enter the access code on the ipad to continue it's crazy now that I do.

  • How can I buy iphone model A1723 - free online contract? will be model a1723 works with GSM (AT SIM cards

    (1) how can I buy iphone model A1723 - free online contract? (2) A1723 model Will work with cards SIM GSM (AT & T etc.)?

  • Empty desktop computers are created when I close the lid

    Hi guys,. I'm using version: 10.11.2 (15 c 50) of El Capitan. Most of the time when I close the lid of my MacBook and open later, I notice that desktop empty 10 - 15 have been created while I was not using it. I have no idea why this is happening, bu

  • Dead MBP, even with adapter

    Im stuck - does anyone have a suggestion? Found my dark charger (with the exception of the logo on the cover), green Mbp to connector mag. Who held to the low power low 15 sec to close, then briefly pressed to start.  No response. Cannot remove batte

  • bad IP on my airport express extender

    I use an express train from the airport as an Extender for my airport extreme for the signal wireless at home.  It worked great for months and then a flashing orange started day and gives a wrong address.  I rebooted, reset / hard reset, unplugged an