Avoid calling the procedure in the cursor loop

Hi all

The following example of procedure the procedure written in cursor loop, is called each time until the end of the cursor loop...
procedure proc_main is
DECLARE
 cursor c1 is 
    select e.empno empno
           ,e.ename ename
           ,d.dname dname
           ,d.loc   loc
    from emp e,dept d
    where e.deptno = d.deptno ;
 
BEGIN
  for i in c1 LOOP
   proc_test(i.empno,i.ename,i.dname,i.loc) ;
   end loop;
END;
-----------

PROCEDURE proc_test (p_empno,p_ename,p_dname,p_loc) is
---
---
begin
 select * into v1,v2,v3 ..
  from temp_tab
   where col1 =p_empno
    ----
    ----

end;
What would be the alternative methods to write the procedure above instead to call the procedure inside the cursor for loop
My idea is to use collections... could you give me the code example using collections to meet the above criteria

Thank you

Published by: smile on February 28, 2012 15:45

The ideal would be to collect all SQL logic and put as much of it in a single SQL statement as possible. It would be also great to determine what is the final outcome of the process and use it as a starting point for your SQL. For example, if the desired result is to upgrade the salaries of the employees where they have an entry in table x, you might find that you can avoid needing to separate the logic between multiple, i.e. instead of procedures

procedure proc_main is
DECLARE
 cursor c1 is
    select e.empno empno
           ,e.ename ename
           ,d.dname dname
           ,d.loc   loc
    from emp e,dept d
    where e.deptno = d.deptno ;

BEGIN
  for i in c1 LOOP
   proc_test(i.empno,i.ename,i.dname,i.loc) ;
   end loop;
END;
-----------

PROCEDURE proc_test (p_empno,p_ename,p_dname,p_loc) is
---
---
begin
 select * into v1,v2,v3 ..
  from temp_tab
   where col1 =p_empno
    ----
    ----

    UPDATE
        emp e
    SET
        sal = v2
    WHERE
        e.empno = p_Empno;

end;

You may simply have

procedure proc_main is
BEGIN

    UPDATE
        emp e
    SET
        sal = ( SELECT
                    t.new_sal
                FROM
                    temp_tab t
                WHERE
                    t.empno = e.empno
               )
    WHERE
        EXISTS
            (   SELECT
                    NULL
                FROM
                    temp_tab t
                WHERE
                    t.empno = e.empno
            );

END;

Even if your logic is more complex, you are likely to find that you can merge several of the statements that you could be running in a loop and replace that loop with a join.

Given the particular structure of what you posted if, instead of calling the procedure in a loop, you can simply move the cursor c1 as a parameter to proc_test that is

procedure proc_main is

    lc_c1   sys_refcursor;

BEGIN

    OPEN lc_c1 FOR
    select e.empno empno
           ,e.ename ename
           ,d.dname dname
           ,d.loc   loc
    from emp e,dept d
    where e.deptno = d.deptno ;

   proc_test(c1) ;

END;
-----------

PROCEDURE proc_test (p_Cursor sys_refcursor) is

begin

    LOOP
        FETCH ....

        ...DO SOMETHING...

        EXIT WHEN p_Cursor%NOTFOUND;

    END LOOP;

    CLOSE p_Cursor;
END;

But I highly recommend that you consider trying to merge as much of your SQL before considering the approach of cursor.

HTH

David

Tags: Database

Similar Questions

  • "ORA-01555: snapshot too old" during the cursor loop

    Hello

    I have a procedure which loop the records in a table, extracted SQL stored in one of the fields and execute it. In addition, it updates the State of education.
    Here is the code in the procedure.

    PROCEDURE RunStatements (inType IN NUMBER) IS
    -Declaration of the cursor:
    CURSOR cur_stmt (vType NUMBER) IS
    SELECT stmt_id, status, sql_stmt
    OF Stmts
    WHERE stmt_type = vType
    ORDER BY stmt_order;
    BEGIN

    -loop and run the statements:
    FOR r IN cur_stmt (inType) LOOP
    -updates the State
    UPDATE stmt
    SET status = 'On '.
    WHERE stmt_id = r.stmt_id;
    COMMIT;
    -running the SQL
    EXECUTE IMMEDIATE r.sql_stmt;
    COMMIT;
    -updates the State
    UPDATE stmt
    SET status = 'Off '.
    WHERE stmt_id = r.stmt_id;
    COMMIT;
    END LOOP;

    END;

    To parallelize the execution of the instructions, they are divided into two types: type 1 and type 2. The procedure is called via DBMS_JOB twice:

    Job 1:
    call RunStatements (1)
    Job 2:
    call RunStatements (2)

    The two executions of the procedure are running simultaneously for about 3 hours at night. Everything was OK until last week when an error began to occur every day.

    Here's the problem:

    One of the instructions is executed very long - around 1.5 hours. Successfully around 20 M, it inserts records into a table. However, after his arrival, Oracle triggers the following error:
    ORA-01555: snapshot too old: rollback segment number 7 with the name ' _SYSSMU7$ ' too small
    This error is issued after that Oracle is trying to retrieve the record next to the slider.
    After that I will carry out the rest of the statements manually and there is no problem.

    Oracle lost somehow, information about data in the cursor!

    Can someone help me understand why this is happening? Is it possible that the long running operation consumes the space reserved for the cursor? Is it possible that after a certain period of time without fetch all the records Oracle decides you don't need the cursor? Is it possible that the error is caused by using two identical slider?

    I tried to increase the tablespace UNDO as stated in some articles, but the error continues to appear.

    Any help will be appreciated. We are in production and I have to wake up every morning at 04:00 to start manually non-executed statements.

    Database: Oracle 10 g 2
    OS: Enterprise Linux RH

    Thank you in advance.

    Best regards
    Beroetz

    The reading consistency mechanism, this is what triggers the ORA-1555. We will try to explain what is happening:

    -T0, you open the slider. This locks "full" all the time the extraction will be requested (all read lines will be "full" t0). Note that Oracle does not have a copy of data of the cursor. When you check out lines, Oracle will read them disk/memory for now, ask you, not before (it will logically build the image in t0 if data has been changed since).

    -At t1, you update the validation and the stmt. When you retrieve a line of the cursor after t1, Oracle will see stmt has changed since t0 and logically will build the data as it was at t0, using the rollback segment information.

    ...
    time passes
    ...

    -To the t2 (2 hours after t0), you get a new line of the cursor. Oracle attempts to logically reconstruct the data as it was at t0, but information was crushed in the rollback segment. Oracle may come back in time indefinitely. The setting for the withholding of information of cancellation you defined is too low.

    You can either increase the retention time (undo_retention), it will have the effect to say Oracle: "wait longer before overwriting the cancellation information so that I can query the data to an earlier point in time. Or you can 'save cursor data' yourself, read all the lines, while you can (as before).

    I hope that this will help you understand why you get this error.

  • calling a procedure in the loop

    I just want to know one thing:

    I call a procedure with the following parameters

    DECLARE

    PROFIT_CENTER NUMBER ;

    START

    PROFIT_CENTER : = 1109--(de même, je fais tourner le proc pour 5 profit_centers plus 1123,1132,1122,3211,1111 un par un en passant les valeurs manuellement, il prend près d'une minute pour chaque centre de profit)

    Prc_test_calc () PROFIT_CENTER);

    COMMIT;

    END;

    For each proc profit_center takes 1 minute (approx.) time.

    But when I'm putting loop to call the procedure for each profit_center, I don't know why it takes too long for each profit_center

    Please let me know is there something wrong with the loop below

    DECLARE

    PROFIT_CENTER NUMBER ;

    cursor c_profit is

    Select separate PROFIT_CENTER de plng_pc profit_center in ()1109 1123,1132,1122,3211,1111)-Plng_pc is a table where profit_center information is obtain from

    START

    For pc_rec in c_profit

    loop

    Prc_test_calc (  pc_rec . PROFIT_CENTER );

    COMMIT;

    End loop;

    END;

    Could you please sugget me if something goes wrong?

    Hello

    as suggested, have you checked the query for the cursor loop and have you tried the process with no cursor loop.

    Concerning

    André

  • For loops with the cursor line and indexing

    Hi all

    I have a question about the loops with the cursor, line and indexing.

    How can I scan via a cursor with an iterator?

    I would use an iterator as

    Whole LoopIndex;
    Whole LoopIndex2;

    for LoopIndex at the beginning of the cursor at the end of the cursor
    loop
    line =: cursor [LoopIndex];
    for LoopIndex2 of LoopIndex at the end of the cursor
    etc...
    end loop;

    I need to use an iterator because I need to use a nested for loop.



    OR


    How can I solve the following problem?

    Class name % ofClass average test Score
    1 Niobe 7 8 8.4
    1 alena 4 7 7.5
    1 9 7 8.9 Estia
    1 Lilly 10 8 9.8
    1 Sandra 6 8 8.3
    1 Melanie 8 8 8.1
    Nadia 2 8 3 4.4
    Sayuki 2 9 8 8.4
    Diasy 2 7 8 8.0
    Flower 2 7 8 6.5
    Diana 2 6 8 7.3
    3 Flora 7 8 5.8
    Sukiya 3 4 8 8.4
    Samantha 3 10 8 7.7
    Roxanne 3 7 8 6.9
    Eline 3 8 8 7.4

    I need to
    -By class, I need to recalculate each average people
    -By class, I need to calculate the % of class score (sum averages / people in the class)

    So it can be done in a nested for loop?
    Or do I just step by step?

    Well, based on this information it would be something like...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 1 as Class, 'Niobe' as Nm, 7 as Score, 8 as Tests, 8.4 as Average from dual union all
      2             select 1, 'Alena', 4, 7, 7.5 from dual union all
      3             select 1, 'Estia', 9, 7, 8.9 from dual union all
      4             select 1, 'Lilly', 10, 8, 9.8 from dual union all
      5             select 1, 'Sandra', 6, 8, 8.3 from dual union all
      6             select 1, 'Melanie', 8, 8, 8.1 from dual union all
      7             select 2, 'Nadia', 3, 8, 4.4 from dual union all
      8             select 2, 'Sayuki', 9, 8, 8.4 from dual union all
      9             select 2, 'Diasy', 7, 8, 8.0 from dual union all
     10             select 2, 'Blossom', 7, 8, 6.5 from dual union all
     11             select 2, 'Diana', 6, 8, 7.3 from dual union all
     12             select 3, 'Flora', 7, 8, 5.8 from dual union all
     13             select 3, 'Sukiya', 4, 8, 8.4 from dual union all
     14             select 3, 'Samantha', 10, 8, 7.7 from dual union all
     15             select 3, 'Roxanne', 7, 8, 6.9 from dual union all
     16             select 3, 'Eline', 8, 8, 7.4 from dual)
     17  --
     18  -- END OF TEST DATA
     19  --
     20  select class, nm as "NAME", score, tests, average
     21        ,round(((average*tests)+score)/(tests+1),1) as avg_person
     22        ,round((average / sum(average) over (partition by class))*100,1) as class_average
     23  from t
     24* order by class, nm
    SQL> /
    
         CLASS NAME          SCORE      TESTS    AVERAGE AVG_PERSON CLASS_AVERAGE
    ---------- -------- ---------- ---------- ---------- ---------- -------------
             1 Alena             4          7        7.5        7.1          14.7
             1 Estia             9          7        8.9        8.9          17.5
             1 Lilly            10          8        9.8        9.8          19.2
             1 Melanie           8          8        8.1        8.1          15.9
             1 Niobe             7          8        8.4        8.2          16.5
             1 Sandra            6          8        8.3          8          16.3
             2 Blossom           7          8        6.5        6.6          18.8
             2 Diana             6          8        7.3        7.2          21.1
             2 Diasy             7          8          8        7.9          23.1
             2 Nadia             3          8        4.4        4.2          12.7
             2 Sayuki            9          8        8.4        8.5          24.3
             3 Eline             8          8        7.4        7.5          20.4
             3 Flora             7          8        5.8        5.9            16
             3 Roxanne           7          8        6.9        6.9          19.1
             3 Samantha         10          8        7.7          8          21.3
             3 Sukiya            4          8        8.4        7.9          23.2
    
    16 rows selected.
    
  • Oracle 11g: engage inside the outer loop or loop

    Hello

    Could someone pls help in this regard.

    My PLSQL program retrieves approximately 400 000 thousand records in cursor loop and cl, it takes more than 4 hours to complete IT.

    I commit every transactions inside the cursor loop... This can affect the runtime performance?


    Also, pls suggest, can we use commit 400 000 transactions once it will be faster? (or) the performance of baskets longer than the current situation.


    My goal is to make the fastest program and expect to reduce the timing of execution of 4 hours to 1 hour...


    Appreciate your help...


    Program design: advice:

    a. Select 400 000 thousand documents in the cursor.

    b. inside cursor for loop to two new sql instructions written to get values and store it in the local variable (this value is used in the call to insert data), two sql statements are handled with no_data_found and too_may_rows logic implicit sql statements to intercept the errors of the company

    c insert statement.

    validation of d. inside the loop (batch mode: nowait)

    management at the level of the procedure using raise_application_error exception e...

    Do not use the PL/SQL for data processing. SQL is a powerful language. Get the best out of him.

    Here is an example of using INSERT ALL. This is untested code and may contain syntax and semantic errors.

    insert all
      into medicomread.aatable_permit_people
      (
            permitnum
          , lic_num
          , lic_type
          , bus_name
          , addr1
          , addr2
          , addr3
          , city
          , state
          , zip
          , ph1
          , ph2
          , fax
          , bus_lic
          , lic_original_issue_date
          , expiration_date
      )
      values
      (
            appt_ref_no
          , lic_num
          ,'Business License'
          , company_name
          , postal_address
          , null
          , null
          , null
          , emirate
          , po_box
          , telephone
          , null
          , fax
          , license_no
          , issue_date
          , expiry_date
      )
      log errors into err$_aatable_permit_people ('INSERT1: HEALTH CARD SPONSOR DETAILS') reject limit unlimited
      into medicomread.aatable_permit_people
      (
            permitnum
          , tt_contact_type
          , name
          , b1_contact_nbr
      )
      values
      (
            appt_ref_no
          , 'Applicant'
          , cname
          , userseqno
      )
      log errors into err$_aatable_permit_people ('INSERT2: HEALTH CARD BUSINESS USER DETAILS') reject limit unlimited
      into medicomread.aatable_permit_people
      (
            permitnum
          , tt_contact_type
          , B1_Contact_Nbr
          , Name
          , gender
      )
      values
      (
            appt_ref_no
          , 'Individual Health'
          , userseqno
          , patient_name
          , ***
      )
      log errors into err$_aatable_permit_people ('INSERT3: HEALTH CARD APPLICANT USER DETAILS') reject limit unlimited
    with t1
    as
    (
     select mr.appt_ref_no
          , mr.sponsor_name
          , substr(mr.PATIENT_NAME,1,79) PATIENT_NAME
          , mr.***
       from medicomdata.mc_register mr
          , medicomdata.mc_process_type_register mptr
          , medicomdata.um_users uu
          , medicomdata.um_companies uc
      where mr.patient_id     = mptr.patient_id
        and mr.pro_id         = uu.user_id
        and mr.facility_id    = mptr.facility_id
        and mr.process_type   ='OH'
        and mr.regn_status    = 5
        and mr.sponsor_name   = uc.company_name
        and uu.type_id        = 3
        and (add_months( mptr.issued_date, 12 )-1) > sysdate
    ),
    t2 as
    (
     select decode(ucr.license_category_id,'DED','DED'||uuc.license_no,uuc.license_no) lic_num
          , uuc.company_name
          , ucr.postal_address
          , ucr.emirate
          , ucr.po_box
          , ucr.telephone
          , ucr.fax
          , uuc.LICENSE_NO
          , ucr.issue_date
          , ucr.expiry_date
       from medicomdata.um_companies uuc,medicomdata.company_registration ucr
      where uuc.license_no=ucr.business_license_number
        and uuc.inactive=0
        and upper(ucr.request_status)=upper('true')
    ),
    t3 as
    (
     select uu.company_name
          , cname
       from (
             select uu.first_name ||' '|| uu.last_name cname
                  , row_number() over(partition by uu.company_name order by decode(usr.service, 'HCDC', 0, 1)) rno
               from medicomdata.um_users uu
                  , medicomdata.user_service_request usr
              where uu.user_id      = usr.user_id
                and usr.service     = 'HCDC'
                and uu.type_id      = 2
                and uu.inactive     = 0
             )
      where rno = 1
    )
    select t1.appt_ref_no
         , t1.patient_name
         , t1.***
         , t2.lic_num
         ,'Business License'
         , t2.company_name
         , t2.postal_address
         , null
         , null
         , null
         , t2.emirate
         , t2.po_box
         , t2.telephone
         , null
         , t2.fax
         , t2.license_no
         , t2.issue_date
         , t2.expiry_date
         , t3.cname
         , companyuserseq.nextval userseqno
      from t1
      join t2
        on t1.sponsor_name = t2.company_name
      join t3
        on t1.sopnsor_name = t3.company_name;
    
  • The execution of a stored procedure from inside the cursor for loop?

    I posted this in the SQL Developer forum, but I tried in SQLPlus and get the same error, so I think it's an encoding issue.
    I have a piece of code that I'm trying to write that will only be executed once. The goal: we have three tables relating to the pieces of information. Each table has a column that stores the number of site that belongs to the part. We want to copy the parts of a site to about 130 sites which don't have any info on parts. The number of site is stored in another table. So I created three stored procedures, one for each of the three tables that we, who take 2 inputs: a source and destination site. Procedure names are: ptfile_copy_fac, ptxref_copy_fac and ptvndrs_copy_fac.

    The problem I have is that I can run the procedures in a separate worksheet in SQL Developer, but when they are integrated in this cursor for loop, I get the following message from SQL Developer:

    ORA-06550: line 23, column 11:
    PLS-00103: encountered the symbol "PTFILE_COPY_FAC" during the expected in the following way:
    := . (@ %; immediate)
    The symbol ': = ' was replaced by 'PTFILE_COPY_FAC' continue.

    He repeated this for each of the three methods. I have attached the code I am trying to run below. He expects an assignment operator, but I have no idea why.

    If there is a better way to do this, by all means let me know. I'm a SQL Server guy, I'm not sure how to do what I do using PL\SQL.

    / * Declares the variables source_fac and dest_fac.
    The source_fac is the installation that we copy parts.
    The dest_fac is the installation we copy parts to.* /

    DECLARE
    source_fac facility.facility_num%type;
    INSTALLATION OF DEST_FAC. TYPE % FACILITY_NUM;

    / * Declare cursor to use loop for.
    Slider load number installation and the status of the installation.
    Is not installation of 1 or 2, since these will be
    the main source of facilities.*.

    CURSOR fac_cursor
    IS
    SELECT
    facility_num,
    div_state
    Of
    installation
    WHERE
    facility_num NOT IN (1,2);
    BEGIN
    FOR fac_row IN fac_cursor
    LOOP

    / * Test for the State of the installation. If a Canadian State, the source_fac value 2.
    Otherwise, the value source_fac 1.* installation.

    IF fac_row.div_state IN ("AB", "BC", "Mo", "NB", "NL", "NT", "NS", "NAKED", "WE", "PE",
    "QC", "SK", "YT")
    THEN
    source_fac: = 2;
    ON THE OTHER
    source_fac: = 1;
    END IF;

    / * Sets the installation of destination to the facility_num from the cursor * /.

    DEST_FAC: = FAC_ROW. FACILITY_NUM;

    / * Execute the three procedures, past of the source and dest AEC variable * /.

    run ptfile_copy_fac (source_fac, dest_fac);
    run ptxref_copy_fac (source_fac, dest_fac);
    run ptvndrs_copy_fac (source_fac, dest_fac);

    END LOOP;

    END;

    Published by: SunDevilKid on March 3, 2010 15:31
    Update the comments you make more sense of the code.

    EXECUTE is a SQLPlus command, change your code to

    dest_fac := fac_row.facility_num;
    ptfile_copy_fac(source_fac, dest_fac);
    ptxref_copy_fac(source_fac, dest_fac);
    ptvndrs_copy_fac(source_fac, dest_fac);
    END LOOP;
    

    Max
    http://oracleitalia.WordPress.com

  • Call the recursive procedure through sql

    Currently, I need to implement a report on GIS. The report should be called in a statement "select of.

    Here is the initial request, I wrote.  The query has been compiled successfully and the return of the expected values. Note that it is recursive.

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

    Recursive procedure

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

    CREATE OR REPLACE PROCEDURE FIND_RELATIONSHIP (SEARCH_CRITERIA CUST_PERSON_TABLE_TEST. CUST_ID % TYPE, INPUT_RELATIONSHIP IN VARCHAR2)

    IS

    NUMBER OF RETURN_REC;

    TYPE XYZ_1 IS REF CURSOR CUST_PERSON_TABLE_TEST RETURN % ROWTYPE;

    CURSOR_PRCI XYZ_1;

    PRCI_FIELD1 CUST_PERSON_TABLE_TEST % ROWTYPE;

    METER NUMBER;

    OUT_RELATIONSHIP VARCHAR2 (100);

    PASS_VAL CUST_PERSON_TABLE_TEST. CUST_ID % TYPE;

    BEGIN

    COUNTER: = 1;

    CURSOR_PRCI OPEN FOR SELECT * FROM CUST_PERSON_TABLE_TEST WHERE CUST_ID = SEARCH_CRITERIA;

    EXTRACT THE CURSOR_PRCI IN PRCI_FIELD1;

    LOOP

    When the output CURSOR_PRCI % NOTFOUND;

    OUT_RELATIONSHIP: = INPUT_RELATIONSHIP |'. ' || METER;

    DBMS_OUTPUT. PUT_LINE (OUT_RELATIONSHIP |') -' || PRCI_FIELD1. PERSON_RELTN_CUST_ID |' -' || PRCI_FIELD1. PERSON_RELTN_NAME |' -' || PRCI_FIELD1. CUST_RELTN_CODE);

    PASS_VAL: = PRCI_FIELD1. PERSON_RELTN_CUST_ID;

    FIND_RELATIONSHIP (PASS_VAL, OUT_RELATIONSHIP);

    EXTRACT THE CURSOR_PRCI IN PRCI_FIELD1;

    COUNTER: = COUNTER + 1;

    END LOOP;

    CLOSE CURSOR_PRCI;

    END;

    SET SERVEROUTPUT ON

    DECLARE

    BEGIN

    DBMS_OUTPUT. PUT_LINE('1.) OF1061769');

    FIND_RELATIONSHIP('OF1061769','1');

    END;

    /

    According to some articles, we cannot call a procedure with a select statement, so I had to convert to a function. It can be compiled, but when the select is a failure.

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

    Converted to a function procedure

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

    CREATE OR REPLACE PACKAGE IN THE RELATIONSHIP_PKG

    TYPE OUTPUT_RELATIONSHIP IS (RECORD

    OUT_RELATIONSHIP VARCHAR2 (100),

    PERSON_RELTN_CUST_ID VARCHAR2 (BYTE 9),

    PERSON_RELTN_NAME VARCHAR2 (80 BYTE),

    CUST_RELTN_CODE VARCHAR2 (5 BYTE));

    TYPE T_O_RELATIONSHIP IS TABLE OF THE OUTPUT_RELATIONSHIP;

    FUNCTION FIND_RELATIONSHIP (SEARCH_CRITERIA VARCHAR2, VARCHAR2 INPUT_RELATIONSHIP)

    RETURN T_O_RELATIONSHIP;

    END;

    /

    CREATE OR REPLACE PACKAGE BODY RELATIONSHIP_PKG AS

    FUNCTION FIND_RELATIONSHIP (SEARCH_CRITERIA IN VARCHAR2, INPUT_RELATIONSHIP IN VARCHAR2)

    T_O_RELATIONSHIP IS back

    FEED_DATA OUTPUT_RELATIONSHIP;

    NUMBER OF RETURN_REC;

    TYPE XYZ_1 IS REF CURSOR CUST_PERSON_TABLE_TEST RETURN % ROWTYPE;

    CURSOR_PRCI XYZ_1;

    PRCI_FIELD1 CUST_PERSON_TABLE_TEST % ROWTYPE;

    METER NUMBER;

    OUT_RELATIONSHIP VARCHAR2 (100);

    PASS_VAL CUST_PERSON_TABLE_TEST. CUST_ID % TYPE;

    BEGIN

    COUNTER: = 1;

    CURSOR_PRCI OPEN FOR SELECT * FROM CUST_PERSON_TABLE_TEST WHERE CUST_ID = SEARCH_CRITERIA;

    EXTRACT THE CURSOR_PRCI IN PRCI_FIELD1;

    LOOP

    When the output CURSOR_PRCI % NOTFOUND;

    OUT_RELATIONSHIP: = INPUT_RELATIONSHIP |'. ' || METER;

    -DBMS_OUTPUT. PUT_LINE (OUT_RELATIONSHIP |') -' || PRCI_FIELD1. PERSON_RELTN_CUST_ID |' -' || PRCI_FIELD1. PERSON_RELTN_NAME |' -' || PRCI_FIELD1. CUST_RELTN_CODE);

    SELECT OUT_RELATIONSHIP, PRCI_FIELD1. PERSON_RELTN_CUST_ID, PRCI_FIELD1. PERSON_RELTN_NAME, PRCI_FIELD1. CUST_RELTN_CODE IN DOUBLE FEED_DATA;

    -PIPE ROW (FEED_DATA);

    PASS_VAL: = PRCI_FIELD1. PERSON_RELTN_CUST_ID;

    -BACK RELATIONSHIP_PKG. FIND_RELATIONSHIP (PASS_VAL, OUT_RELATIONSHIP);

    EXTRACT THE CURSOR_PRCI IN PRCI_FIELD1;

    COUNTER: = COUNTER + 1;

    END LOOP;

    CLOSE CURSOR_PRCI;

    END FIND_RELATIONSHIP;

    END;

    /

    But when running.

    SELECT * from table (RELATIONSHIP_PKG. FIND_RELATIONSHIP('OF1061769','1'))

    I get invalid data type

    EXEC RELATIONSHIP_PKG. FIND_RELATIONSHIP('OF1061769','1');

    Above code returns Find_relationship is not a procedure or is undefined ORA06550.

    Can anyone advise me on the conversion of the work to a function procedure, as FIND_RELATIONSHIP(PASS_VAL,OUT_RELATIONSHIP) wrote in the service fails.

    Or someone help me hidden in a function that can be called in a select statement.

    What you wrote, it seems that it is possible using a hierarchical query.

    Hierarchical queries

    Why don't you start with a small "CREATE TABLE" and some "INSERT" statements followed by your desired results.

    Re: 2. How can I ask a question in the forums?

    Thank you

    MK

  • ORA-900 sql not valid reporting error while calling the optimize_index pl/sql procedure


    Hi Experts,

    I'm on Oracle 11.2.0.3 on Linux and I have installed in my database Oracle text. I want to configure annex dbms_job to optimize my oracle text index. So first, I created a pl/sql procedure to optimize indexes. It gives me error ORA-900, but the sql even if I run in sqlplus works very well! Can you please help me the question is to find:

    Here is the procedure:

    (Either incidentally CTXAPP role has been granted in the schema where these Oracle text indexes are created and where the below procedure to optimize the index is running.)

    CREATE OR REPLACE PROCEDURE optimize_ora_txt_indexes_debug
    IS
       CURSOR cur_context_indexes
       IS
            SELECT index_name
              FROM user_indexes
             WHERE index_type = 'DOMAIN'
        AND ROWNUM<2  
        ORDER BY INDEX_NAME;
       v_user         VARCHAR2 (30);
       v_pod          VARCHAR2 (30);
       v_start_time   TIMESTAMP;
       v_end_time     TIMESTAMP;
       v_elapsed      VARCHAR2 (40);
       v_msg   VARCHAR2 (1000);
       v_error_code      NUMBER;
       v_error_msg   VARCHAR2 (1000);
       v_sql VARCHAR2 (1000);
    BEGIN
    
       FOR c IN cur_context_indexes
       LOOP
          BEGIN
            v_sql:= 'ctx_ddl.optimize_index (idx_name =>'||chr(39)|| c.index_name||chr(39)||', optlevel => '||chr(39)||'FULL'||chr(39)||')';
            dbms_output.put_line(v_sql);
            execute immediate v_sql;
          EXCEPTION
             WHEN OTHERS
             THEN
                v_error_code := SQLCODE;
                v_error_msg := SQLERRM;
                v_msg :=
                      'Error while optimizing the index '
                   || c.index_name
                   || ' '
                   || TO_CHAR (v_error_code)
                   || ' '
                   || v_error_msg;
                DBMS_OUTPUT.put_line (v_msg);
    
          END;
       END LOOP;
    
    EXCEPTION
       WHEN OTHERS
       THEN
          v_error_code := SQLCODE;
          v_error_msg := SQLERRM;
          v_msg :=
                'Error while in the optimize index procedure'
             || ' '
             || TO_CHAR (v_error_code)
             || ' '
             || v_error_msg;
          DBMS_OUTPUT.put_line (v_msg);
    
    END optimize_ora_txt_indexes_debug;
    /
    
     --the procedure compiles successfully. 
     Now when I run it , I get the error:
    SQL>exec optimize_ora_txt_indexes_debug;
    ctx_ddl.optimize_index (idx_name =>'ACCESS_CLNT_IDX04', optlevel => 'FULL')
    Error while optimizing the index ACCESS_CLNT_IDX04 -900 ORA-00900: invalid SQL
    statement
    
    
     --When I run the same command from sqlplus as execute statement , it works fine:
    SQL>exec ctx_ddl.optimize_index (idx_name =>'ACCESS_CLNT_IDX04', optlevel => 'FULL');
    PL/SQL procedure successfully completed.
     
     
    
    
    

    If everything runs from sqlplus, but fails in plsql... I'll be very grateful for pointers solve the problem.

    Thanks,

    OrauserN

    Hello

    It is a problem of pl/sql syntax. A call with EXEC is the same using BEGIN... Code of... END of block;

    SO, you need to include a beginning and an end to your call:

     v_sql:= 'BEGIN ctx_ddl.optimize_index (idx_name =>'||chr(39)|| c.index_name||chr(39)||', optlevel => '||chr(39)||'FULL'||chr(39)||'); END;';
    

    That's all.

    Herald tiomela

    http://htendam.WordPress.com

  • call sub procedure for updating the table - need help

    Hi all

    I have a scneario wherein I get three values 0,2.5 and 57.
    For each value, I'll call another procedure that updates a table "sample_dest".
    The "sample_dest" table has a column "dest_nbr."

    Now, for each three values I get,
    I want to update only one record in the table 'sample_dest '.

    for example, I want to update the column "dest_nbr" with a value of 59.5 (0 + 2.5 + 57).

    I am unable to do this, because every time the procedure is called,
    the previous values are not stored. 57 is the last value I get,
    I am able to store only 57. But I want 59.5 to be updated in the table.

    How can I achieve this.
    Help, please.

    Concerning
    Rambeau.

    This should be done in a single sql statement, not in a loop of cursor (which is what it looks like you're doing). If sample_desc already contains records for samples, so it should look like:

    UPDATE sample_desc sdesc
    SET desc = (SELECT AVG(code) FROM sample_dest sdest
                WHERE sdesc.sample = sdest.sample)
    WHERE EXISTS (SELECT 1 FROM sample_dest sdest
                  WHERE sdesc.sample = sdest.sample)
    

    If sample_desc does not already contain records (unknown from your description), then it would be an insert as:

    INSERT INTO sample_desc
    SELECT sample, AVG(code)
    FROM sample_dest sdest
    GROUP BY sample
    

    John

  • How to call the procedure type table

    Hi I have the below requirement

    Created in the sub table type

    CREATE or REPLACE the TYPE char_type IS the TABLE OF VARCHAR2 (4000);

    create or replace procedure test_proc_type (p_type char_type) is

    Start

    I'm looping 1.p_type.count

    dbms_output.put_line (p_type (i));

    end loop;

    end;

    How to call the procedure with parameter as a type!

    SQL> create or replace type  char_type as table of varchar2(4000)
      2  /
    
    Type created.
    
    SQL> create or replace procedure test_proc_type (p_type char_type)
      2  is
      3  begin
      4    for i in 1..p_type.count loop
      5      dbms_output.put_line (p_type(i) ) ;
      6    end loop;
      7  end;
      8  /
    
    Procedure created.
    
    SQL> set serveroutput on
    SQL>
    SQL> exec test_proc_type(char_type('A','B','C','D','E'))
    A
    B
    C
    D
    E
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • How to pass the value of the cursor in the procedure to use as dblink

    Hello

    I have a cursor in the procedure. I am inserting some values into the destination table by querying the source table using dblink. And I'm collecting this db link in the cursor. So, my question is how I will pass on the value of dblink values read from the cursor in each iteration? This is my procedure.

    CREATE OR REPLACE
        PROCEDURE desktop_proc
        AS
          v_name VARCHAR2(10);
          v_dblink  VARCHAR2(10);
          CURSOR db_cur
          IS
            SELECT PNAME,OLTP_DBLINK
            FROM PDATA
            WHERE pname in ('RMA','RNA')
            ORDER BY PNAME;
        BEGIN
          OPEN db_cur;
          LOOP
            FETCH db_cur INTO v_name,v_dblink;
            EXIT WHEN db_cur%NOTFOUND;
            INSERT INTO desktop_lite
              (
                Datestamp,
                pname,
                Db_name,
                Company_name
              )
            SELECT Date_Range,
              v_name,   -- local variable
              dbname,
              Company_name
              FROM
              (SELECT bu.datestamp Date_Range,
                      (SELECT name FROM v$database@v_dblink) dbname,
                      bu.name Company_name
               FROM dboltp.s_org_ext@v_dblink bu
               INNER JOIN com_unique uusers ON (uusers.bu_id = bu.row_id)
              );
          END LOOP;
          CLOSE db_cur;
        END desktop_proc;
    

    Thank you

    Maybe this can work for you:

    CREATE OR REPLACE
        PROCEDURE desktop_proc
        AS
          v_name    VARCHAR2(10);
          v_dblink  VARCHAR2(10);
          v_statement varchar2(2000);
          CURSOR db_cur
          IS
            SELECT 'test_name' dual_name, 'test_dbl' dual_link
            FROM dual;
        BEGIN
          OPEN db_cur;
          LOOP
            FETCH db_cur INTO v_name,v_dblink;
            EXIT WHEN db_cur%NOTFOUND;
            v_statement := '
            INSERT INTO desktop_lite
              (
                Datestamp,
                pname,
                Db_name,
                Company_name
              )
            SELECT Date_Range,
              '''|| v_name || ''',
              dbname,
              Company_name
              FROM
              (SELECT bu.datestamp Date_Range,
                      (SELECT name FROM v$database@' || v_dblink || ') dbname,
                      bu.name Company_name
               FROM dboltp.s_org_ext@' || v_dblink || ' bu
               INNER JOIN com_unique uusers ON (uusers.bu_id = bu.row_id)
              )';
            dbms_output.put_line (v_statement);
    --            execute immediate v_statement;    -- first look at the statments you produce, then uncomment and test it
           END LOOP;
           CLOSE db_cur;
    END desktop_proc;
    /
    show err
    
    exec desktop_proc
    

    This is my result, it seems that this can work:

    INSERT INTO desktop_lite

    (

    Timestamp,

    PName,

    Db_name,

    Company_name

    )

    SELECT Date_Range,

    "test_name."

    dbname,

    Company_name

    Of

    (SELECT bu.datestamp Date_Range,

    Dbname (SELECT name FROM v$database@test_dbl).

    Bu.Name Company_name

    Dboltp.s_org_ext@test_dbl drunk

    INNER JOIN com_unique uusers ON (uusers.bu_id = bu.row_id)

    )

  • Cannot create the plsql procedure, fails at the cursor

    He was a working procedure that would take ID and then copy the data from the source to the destination parameter parameter. Now I would like to have the NAME as a parameter, I changed the code to accommodate the new settings. But I'm not able to create the procedure. I get error 3-CURSOR (in bold red). I would really appreciate if someone can take a look and let me know what the problem is.

    Thanks in advance

    3 errors

    1 PLS-00103: encountered the symbol "CUR_V_HSP_COLUMN_DETAIL" during the expected in the following way:

    := . ( @ % ;

    The symbol ': = ' was replaced by 'CUR_V_HSP_COLUMN_DETAIL' continue.

    2 PLS-00103: encountered the symbol "NUMBER" when expecting one of the following conditions:

    (

    The symbol "(" was substituted for "NUMBER" to continue.

    3 PLS-00103: encountered the symbol "NUMBER" when expecting one of the following conditions:

    (

    CREATE or REPLACE procedure EPM_PLAN_PLANSAMP. Copy_Details_test1 - Arguments

    ( IN VARCHAR2, HSP_object in_From_Version_Name.) Object_name - Version of

    in_From_Scenario_Name IN VARCHAR2, HSP_object. Object_name - scenarios of

    in_From_Year_Name IN VARCHAR2, HSP_object. Object_name - year from

    in_To_Version_Name IN VARCHAR2, HSP_object. Object_name - Version to

    in_To_Scenario_name IN VARCHAR2, HSP_object. Object_name - scenarios

    in_To_Year_Name IN VARCHAR2 - HSP_object. Object_name - year to

    )

    IS

    number of v_From_Object_Id; -Version of

    number of s_From_Object_Id; -Scenarios of

    number of y_From_Object_Id; -The year of

    number of v_To_Object_Id; -Version to

    number of s_To_Object_Id; -Scenarios to

    number of y_To_Object_Id; -The year to

    BEGIN

    Select object_id in v_From_Object_Id

    of hsp_object

    where type_objet = 35

    and object_name = in_from_version_name;

    Select object_id in s_From_Object_Id

    of hsp_object

    where type_objet = 31

    and object_name = in_from_scenario_name;

    Select object_id in y_From_Object_Id

    of hsp_object

    where type_objet = 38

    and object_name = in_from_year_name;

    Select object_id in v_To_Object_Id

    of hsp_object

    where type_objet = 35

    and object_name = in_to_version_name;

    Select object_id in s_To_Object_Id

    of hsp_object

    where type_objet = 31

    and object_name = in_to_scenario_name;

    Select object_id in y_To_Object_Id

    of hsp_object

    where type_objet = 38

    and object_name = in_to_year_name;

    -Select Details of support for the current Version

    CURSOR Cur_V_HSP_COLUMN_DETAIL (cV_From_Object_Id in NUMBER, cS_From_Object_Id number) IS

    Select DETAIL_ID in the EPM_PLAN_PLANSAMP. HSP_COLUMN_DETAIL where DIM5 = cV_From_Object_Id AND DIM1 = cS_From_Object_Id;

    li_DETAIL_ID NUMBER;

    Li_Next_DETAIL_ID NUMBER;

    FETCH_STATUS NUMBER: = 0;

    v_step_name varchar2 (200);

    v_rec_cnt number: = 0;

    number of v_cnt;

    v_err varchar2 (2000);

    -----------------------------------------Begin Copy Version ---------------------------

    BEGIN

    -Removed next version if already exists

    v_step_name: = 'delete the HSP_COLUMN_DETAIL_ITEM ";

    Remove from HSP_COLUMN_DETAIL_ITEM

    Where DETAIL_ID in (Select DETAIL_ID from HSP_COLUMN_DETAIL

    Where = v_To_Object_Id AND DIM1-DIM5 = s_To_Object_Id);

    v_cnt: = number of lines sql %;

    insert into t_copy_supporting_dtls_log values (v_step_name, v_cnt, 1, sysdate, 'success');

    v_step_name: = 'delete the HSP_COLUMN_DETAIL ";

    Remove from HSP_COLUMN_DETAIL

    where = v_To_Object_Id AND DIM1-DIM5 = s_To_Object_Id;

    v_cnt: = number of lines sql %;

    insert into t_copy_supporting_dtls_log values (v_step_name, v_cnt, 1, sysdate, 'success');

    Open Cur_V_HSP_COLUMN_DETAIL (v_From_Object_Id, s_From_Object_Id);

    v_step_name: = "Insert";

    LOOP

    Look FOR Cur_V_HSP_COLUMN_DETAIL IN li_DETAIL_ID;

    WHEN the OUTPUT Cur_V_HSP_COLUMN_DETAIL % NOTFOUND;

    -Find the next detail_id

    Select Max (DETAIL_ID) + 1 IN HSP_COLUMN_DETAIL Li_Next_DETAIL_ID;

    -Insert in the Table HSP_COLUMN_DETAIL

    Insert into HSP_COLUMN_DETAIL (DETAIL_ID, PLAN_TYPE, DIM1, DIM2, DIM3, DIM4, DIM5, 6,

    DIM7, DIM8, DIM9, DIM10, DIM11, DIM12, DIM13, DIM14, DIM15,

    DIM16, DIM17, DIM18, DIM19, DIM20)

    Select Li_Next_DETAIL_ID, PLAN_TYPE, S_To_Object_Id, DIM2, DIM3, DIM4, V_To_Object_Id, 6.

    DIM7, DIM8, DIM9, DIM10, DIM11, DIM12, DIM13, DIM14, DIM15,

    DIM16, DIM18, DIM19, DIM17, DIM20

    Of HSP_COLUMN_DETAIL

    Where DETAIL_ID = li_DETAIL_ID;

    v_rec_cnt: = v_rec_cnt + sql rowcount %;

    -Insert in the Table HSP_COLUMN_DETAIL_ITEM

    Insert into HSP_COLUMN_DETAIL_ITEM (DETAIL_ID, VALUE, POSITION, GENERATION, OPERATOR, LABEL)

    Select VALUE, POSITION, GENERATION, OPERATOR, Li_Next_DETAIL_ID, LABEL

    From HSP_COLUMN_DETAIL_ITEM where DETAIL_ID = li_DETAIL_ID;

    v_rec_cnt: = v_rec_cnt + sql rowcount %;

    END LOOP;

    Close Cur_V_HSP_COLUMN_DETAIL;

    insert into t_copy_supporting_dtls_log values (v_step_name, v_rec_cnt, 1, sysdate, 'success');

    commit;

    exception when others then

    Rollback;

    v_err: = substr (sqlerrm, 1, 2000);

    insert into t_copy_supporting_dtls_log values (v_step_name, 0, -1, v_err, sysdate);

    commit;

    END;

    END;

    /

    You DECLARE the cursor before using it.

  • Procedure failed when using bulk collect clause and works with the cursor

    Hi all

    I use "BULK collect into" clause in my procedure and it is a failure after 21 minutes and gives the error "end of file communication channel.
    After that this error comes when I tried to connect the database it gives following error.

    ORA-01034 - Oracle is not available.
    ORA - 27101-shared memory realm does not exist.
    SVR4 error: 2: no such file or directory.

    When I use the cursor instead of the COLLECTION in BULK IN the clause, it runs successfully.

    Following the code works with the slider.
    procedure work_kiosk_full (an_jobid in number, ac_sqlcode out varchar2, ac_sqlerrm out varchar2) is

    ld_curr_time Date;

    cursor cur_work_kiosk is
    Select distinct jt.jt_id AS jt_id,
    NVL ((ROUND ((jt_date_completed-jt_date_requested) * 24, 2)))
    ),
    0
    ) AS actual_hrs_to_complete,
    NVL ((ROUND ((jt_date_responded-jt_date_requested) * 24, 2)))
    ),
    0
    ) AS actual_hrs_to_respond,
    peo1.peo_name AS agent_name,
    peo1.peo_user_name AS asagent_soe_id,
    Le.lglent_desc AS ap_system,
    "" AS assign_work_request_comment,
    DECODE (jt.jt_bill_id,
    138802, 'BILLABLE CLIENT. "
    138803, "CONTRACTED"
    "138804, ' BILLABLE IN-HOUSE."
    NULL, ' '
    ) Billable.
    BL.bldg_name_cc BUILDING, bl.bldg_id_ls AS building_id,
    DECODE (bl.bldg_active_cc,
    'Y', 'ACTIVE',
    'INACTIVE '.
    ) AS building_status,
    DECODE (jt.jt_wrk_cause_id,
    141521, "STANDARD WEAR."
    141522, "NEGLIGENCE."
    141523, "ACCIDENTAL."
    141524, "MECHANICAL FAILURE."
    141525, "CONTROL."
    141526, "VANDAL."
    141527, 'STANDARD ',.
    141528, "WORK PROJECT",.
    6058229, "TEST."
    NULL, ' '
    ) AS cause_type,
    ' ' AS comments, peo3.peo_name AS completed_by,
    JT.jt_requestor_email AS contact_email,
    JT.jt_requestor_name_first
    || ' '
    || JT.jt_requestor_name_last AS contact_name,
    JT.jt_requestor_phone AS contact_phone,
    CC.cstctrcd_apcode AS corp_code,
    CC.cstctrcd_code AS cost_center,
    JT.jt_date_closed AS date_closed,
    JT.jt_date_completed AS date_completed,
    JT.jt_date_requested AS date_requested,
    JT.jt_date_responded AS date_responded,
    JT.jt_date_response_ecd AS date_response_ecd,
    JT.jt_date_scheduled AS date_scheduled,
    DECODE (jt.jt_def_id,
    139949, "WTG VENDOR RESPONSE."
    139950, "WAITING ON PARTS."
    139951, "AVAILABILITY OF THE HAND ŒUVRE."
    139952, "WORK DEFERRED-HI PRI."
    139953, "APPROVAL OF WIND TURBINES."
    139954, "FUNDING."
    139955, "ACCESS DENIED."
    139956, "WTG MATERIAL."
    NULL, ' '
    ) AS deferral_reason,
    JT.jt_description as description,
    JT.jt_date_resched_ecd IN the development of the young child,
    FMG.facility_manager AS facility_manager,
    FL.floors_text AS FLOOR, gl.genled_desc AS general_ledger,
    '' AS kiosk_date_requested,' ' AS kiosk_dispatch_confirmed.
    "" AS kiosk_dispatched,
    EQP.equip_customer_code AS linked_equipment_alias,
    EQP.equip_id AS linked_equipment_id,
    EQP.equip_text AS linked_equipment_name,
    DECODE (jt_originator_type_id,
    1000, "PROJECT MOVE REQUEST."
    138834, "CUSTOMER OPEN CORRECTION."
    138835, "OPEN REQUEST CUSTOMER."
    138836, "CORRECTIVE MAINTENANCE",.
    138837, "BOOKING CONFERENCE ROOM."
    138838, "PROJECT INITIATED REQUEST."
    138839, "PLANNED PREVENTATIVE MAINTENANCE."
    138840, "COULD START FREE APPLICATION."
    NULL, ' '
    ) AS originator_type,
    "" AS payment_terms, priority_text AS priority_code,
    swoty.sworktype_text AS problem_type,
    Prop.property_name_cc as a property,
    JT.jt_cost_quote_total AS quote_total,
    par.levels_name IN the region,
    DECODE (jt.jt_repdef_id,
    141534, 'ADJUSTED SETTING. "
    141535, "THE TRAINING OF THE END,"
    141536, "NEW REQUEST"
    141537, "NO INVESTIGATION OF REPAIR."
    141538 "REPLACED PARTS."
    141539, 'REPLACE EQUIPMEN.
    1000699, "NEW REQUEST"
    NULL, ' '
    ) AS repair_definitions,
    JT.jt_repairdesc AS MARKED_COR,
    JT.jt_requestor AS applicant, ' ' AS requestor_cost_center.
    JT.jt_requestor_email AS requestor_email,
    JT.jt_requestor_name_first AS requestor_name,
    JT.jt_requestor_phone AS requestor_phone,
    "" LIKE response_time, rm.room_name_cc ROOM,
    P1.peo_provider_code1 AS service_provider,
    P1.peo_address_1 AS service_provider_address,
    peocity.city_text service_provider_city,
    P1.peo_provider_code1 AS service_provider_code,
    peocity.city_country_name AS service_provider_country,
    peocur.currency_text AS service_provider_currency,
    P1.peo_name AS service_provider_description,
    P1.peo_dispatch_method AS serv_prov_dispatc_hmethod,
    P1.peo_rate_double AS serv_prov_double_time_rate,
    P1.peo_email AS service_provider_email,
    P1.peo_emergency_phone AS serv_prov_emergency_phone,
    P1.peo_fax AS service_provider_fax_number,
    P1.peo_home_phone AS service_provider_home_phone,
    P1.peo_rate_hourly AS service_provider_hourly_rate,
    P1.peo_title AS service_provider_job_title,
    P1.peo_method_id AS service_provider_method,
    P1.peo_cell_phone AS service_provider_mobile_phone,
    P1.peo_pager AS service_provider_pager,
    P1.peo_rate_differential AS service_provider_rates,
    P1.peo_rate_differential AS ser_prov_shift_differential,
    peocity.city_state_prov_text AS serv_prov_state_province,
    DECODE (p1.peo_active,
    'Y', 'ACTIVE',
    'INACTIVE '.
    ) AS service_provider_status,
    P1.peo_url AS serv_prov_web_site_address,
    P1.peo_phone AS service_provider_work_phone,
    P1.peo_postal_code AS serv_prov_zip_postal_code, ' ' shift, as.
    ' ' AS skill,.
    DECODE (jt.jt_bigstatus_id,
    138813, «NEWS»,
    138814 "PENDING."
    138815, 'OPEN ',.
    138816, "END."
    138817, 'CLOSED ',.
    138818, "CANCELLED."
    NULL, ' '
    ) The STATUS,
    Lev.levels_name IN the subregion, ' ' IN the trade.
    P1.peo_ls_interface_code1 AS vendor_id,
    P1.peo_fax AS vendor_purchasing_fax,
    P1.peo_vendor_site_code AS vendor_sitecode,
    JT.jt_id AS vendor_ticket, p1.peo_name AS vendor_companyname,
    JT.jt_requestor_vip AS vip, wo.wo_id AS work_order_no,
    JT.jt_id AS work_request,
    JT.jt_class_id AS work_request_class,
    woty.worktype_text AS work_type, ' ' AS wr_cost.
    JT.jt_description AS wr_description,
    "" AS wr_dispatch_method,
    DECODE (jt.jt_bigstatus_id,
    138813, «NEWS»,
    138814 "PENDING."
    138815, 'OPEN ',.
    138816, "END."
    138817, 'CLOSED ',.
    138818, "CANCELLED."
    NULL, ' '
    ) AS wr_status,
    ctrY.country_name as a country
    OF citi.jobticket jt,.
    Citi.Property prop,
    Citi.Bldg bl,
    Citi.bldg_levels bldglvl,
    civil LEVEL lev,
    civil by LEVELS.
    (SELECT crstools.stragg (peo_name) facility_manager,
    bldgcon_bldg_id
    OF citi.bldg_contacts, citi.people
    WHERE bldgcon_peo_id = peo_id
    AND IN bldgcon_contype_id (40181, 10142)
    FMG GROUP BY bldgcon_bldg_id),
    Citi.floors, fl,
    Citi.Room rm,
    Citi.general_ledger gl,
    the Citi.legal_entity
    Citi.cost_center_codes cc,
    Citi.Equipment eqp,
    Citi.workType woty,
    Citi.subworktype swoty,
    Citi.work_order wo,
    Jtwo Citi.jt_workers,
    Citi.Priority,
    Ctry Citi.Country,
    Citi.People p1,
    Citi.People peo3,
    Citi.People peo1,
    Citi.City peocity,
    Citi.Currency peocur
    WHERE jt.jt_bldg_id = bl.bldg_id
    AND bl.bldg_id = bldglvl.bldg_levels_bldg_id
    AND bldglvl.bldg_levels_levels_id = lev.levels_id
    AND lev.levels_parent = par.levels_id (+)
    AND prop.property_id = bl.bldg_property_id
    AND bl.bldg_active_ls <>' n
    AND jt.jt_floors_id = fl.floors_id (+)
    AND jt.jt_room_id = rm.room_id (+)
    AND jt.jt_bldg_id = fmg.bldgcon_bldg_id (+)
    AND jt.jt_genled_id = gl.genled_id (+)
    AND gl.genled_lglent_id = le.lglent_id (+)
    AND jt.jt_cstctrcd_id = cc.cstctrcd_id (+)
    AND jt.jt_equip_id = eqp.equip_id (+)
    AND jt.jt_id = jtwo.jtw_jt_id (+)
    AND jt.jt_worktype_id = woty.worktype_id (+)
    AND jt.jt_sworktype_id = swoty.sworktype_id (+)
    AND jt.jt_wo_id = wo.wo_id
    AND jt.jt_priority_id = priority_id (+)
    - AND jt.jt_date_requested > = ADD_MONTHS (SYSDATE,-12)
    AND jt.jt_last_update > = ADD_MONTHS (ld_curr_time-12)
    AND bl.bldg_country_id = ctry.country_id
    AND jtwo.jtw_peo_id = p1.peo_id (+)
    AND p1.peo_city_id = peocity.city_id (+)
    AND jt.jt_completed_by_peo_id = peo3.peo_id (+)
    AND p1.peo_rate_currency_id = peocur.currency_id (+)
    AND jt.jt_agent_peo_id = peo1.peo_id (+);


    BEGIN
    run immediately 'truncate table crstools.drt_bom_work_kiosk;
    Select sysdate in double ld_curr_time;
    FOR cur_rec in cur_work_kiosk LOOP
    IF MOD (cur_work_kiosk % rowcount, 10000) = 0 then
    COMMIT;
    END IF;

    INSERT INTO crstools.drt_bom_work_kiosk
    (JT_ID
    ACTUAL_HRS_TO_COMPLETE
    ACTUAL_HRS_TO_RESPOND
    AGENT_NAME
    ASAGENT_SOE_ID
    AP_SYSTEM
    ASSIGN_WORK_REQUEST_COMMENT
    BILLABLE
    BUILDING
    BUILDING_ID
    BUILDING_STATUS
    CAUSE_TYPE
    COMMENTS
    COMPLETED_BY
    CONTACT_EMAIL
    CONTACT_NAME
    CONTACT_PHONE
    CORP_CODE
    COST_CENTER
    DATE_CLOSED
    DATE_COMPLETED
    DATE_REQUESTED
    DATE_RESPONDED
    DATE_RESPONSE_ECD
    DATE_SCHEDULED
    DEFERRAL_REASON
    DESCRIPTION
    DPE
    FACILITY_MANAGER
    FLOOR
    GENERAL_LEDGER
    KIOSK_DATE_REQUESTED
    KIOSK_DISPATCH_CONFIRMED
    KIOSK_DISPATCHED
    LINKED_EQUIPMENT_ALIAS
    LINKED_EQUIPMENT_ID
    LINKED_EQUIPMENT_NAME
    ORIGINATOR_TYPE
    PAYMENT_TERMS
    PRIORITY_CODE
    PROBLEM_TYPE
    PROPERTY
    QUOTE_TOTAL
    REGION
    REPAIR_DEFINITIONS
    MARKED_COR
    APPLICANT
    REQUESTOR_COST_CENTER
    REQUESTOR_EMAIL
    REQUESTOR_NAME
    REQUESTOR_PHONE
    RESPONSE_TIME
    ROOM
    SERVICE_PROVIDER
    SERVICE_PROVIDER_ADDRESS
    SERVICE_PROVIDER_CITY
    SERVICE_PROVIDER_CODE
    SERVICE_PROVIDER_COUNTRY
    SERVICE_PROVIDER_CURRENCY
    SERVICE_PROVIDER_DESCRIPTION
    SERV_PROV_DISPATC_HMETHOD
    SERV_PROV_DOUBLE_TIME_RATE
    SERVICE_PROVIDER_EMAIL
    SERV_PROV_EMERGENCY_PHONE
    SERVICE_PROVIDER_FAX_NUMBER
    SERVICE_PROVIDER_HOME_PHONE
    SERVICE_PROVIDER_HOURLY_RATE
    SERVICE_PROVIDER_JOB_TITLE
    SERVICE_PROVIDER_METHOD
    SERVICE_PROVIDER_MOBILE_PHONE
    SERVICE_PROVIDER_PAGER
    SERVICE_PROVIDER_RATES
    SER_PROV_SHIFT_DIFFERENTIAL
    SERV_PROV_STATE_PROVINCE
    SERVICE_PROVIDER_STATUS
    SERV_PROV_WEB_SITE_ADDRESS
    SERVICE_PROVIDER_WORK_PHONE
    SERV_PROV_ZIP_POSTAL_CODE
    MAJ
    SKILLS
    STATUS
    SUBREGION
    TRADE
    VENDOR_ID
    VENDOR_PURCHASING_FAX
    VENDOR_SITECODE
    VENDOR_TICKET
    VENDOR_COMPANYNAME
    VIP
    WORK_ORDER_NO
    WORK_REQUEST
    WORK_REQUEST_CLASS
    WORK_TYPE
    WR_COST
    WR_DESCRIPTION
    WR_DISPATCH_METHOD
    WR_STATUS
    COUNTRY
    CREATE_DATE
    )
    VALUES
    (cur_rec.jt_id
    cur_rec, ACTUAL_HRS_TO_COMPLETE
    cur_rec, ACTUAL_HRS_TO_RESPOND
    cur_rec, AGENT_NAME
    cur_rec, ASAGENT_SOE_ID
    cur_rec, AP_SYSTEM
    cur_rec, ASSIGN_WORK_REQUEST_COMMENT
    BILLABLE cur_rec.
    cur_rec, BUILDING
    cur_rec, BUILDING_ID
    cur_rec, BUILDING_STATUS
    cur_rec, CAUSE_TYPE
    cur_rec.COMMENTS
    cur_rec.COMPLETED_BY
    cur_rec, CONTACT_EMAIL
    cur_rec, CONTACT_NAME
    cur_rec, CONTACT_PHONE
    cur_rec, CORP_CODE
    cur_rec, COST_CENTER
    cur_rec, DATE_CLOSED
    cur_rec, DATE_COMPLETED
    cur_rec, DATE_REQUESTED
    cur_rec, DATE_RESPONDED
    cur_rec, DATE_RESPONSE_ECD
    cur_rec, DATE_SCHEDULED
    cur_rec, DEFERRAL_REASON
    cur_rec, DESCRIPTION
    cur_rec, DEVELOPMENT OF THE YOUNG CHILD
    cur_rec, FACILITY_MANAGER
    cur_rec, FLOOR
    cur_rec, GENERAL_LEDGER
    cur_rec, KIOSK_DATE_REQUESTED
    cur_rec, KIOSK_DISPATCH_CONFIRMED
    cur_rec, KIOSK_DISPATCHED
    cur_rec, LINKED_EQUIPMENT_ALIAS
    cur_rec, LINKED_EQUIPMENT_ID
    cur_rec, LINKED_EQUIPMENT_NAME
    cur_rec, ORIGINATOR_TYPE
    cur_rec, PAYMENT_TERMS
    cur_rec, PRIORITY_CODE
    cur_rec, PROBLEM_TYPE
    cur_rec, PROPERTY
    cur_rec, QUOTE_TOTAL
    cur_rec, REGION
    cur_rec, REPAIR_DEFINITIONS
    cur_rec, MARKED_COR
    cur_rec, APPLICANT
    cur_rec, REQUESTOR_COST_CENTER
    cur_rec, REQUESTOR_EMAIL
    cur_rec, REQUESTOR_NAME
    cur_rec, REQUESTOR_PHONE
    cur_rec, RESPONSE_TIME
    cur_rec, ROOM
    cur_rec, SERVICE_PROVIDER
    cur_rec, SERVICE_PROVIDER_ADDRESS
    cur_rec, SERVICE_PROVIDER_CITY
    cur_rec, SERVICE_PROVIDER_CODE
    cur_rec, SERVICE_PROVIDER_COUNTRY
    cur_rec, SERVICE_PROVIDER_CURRENCY
    cur_rec, SERVICE_PROVIDER_DESCRIPTION
    cur_rec, SERV_PROV_DISPATC_HMETHOD
    cur_rec, SERV_PROV_DOUBLE_TIME_RATE
    cur_rec, SERVICE_PROVIDER_EMAIL
    cur_rec, SERV_PROV_EMERGENCY_PHONE
    cur_rec, SERVICE_PROVIDER_FAX_NUMBER
    cur_rec, SERVICE_PROVIDER_HOME_PHONE
    cur_rec, SERVICE_PROVIDER_HOURLY_RATE
    cur_rec, SERVICE_PROVIDER_JOB_TITLE
    cur_rec, SERVICE_PROVIDER_METHOD
    cur_rec, SERVICE_PROVIDER_MOBILE_PHONE
    cur_rec, SERVICE_PROVIDER_PAGER
    cur_rec, SERVICE_PROVIDER_RATES
    cur_rec, SER_PROV_SHIFT_DIFFERENTIAL
    cur_rec, SERV_PROV_STATE_PROVINCE
    cur_rec, SERVICE_PROVIDER_STATUS
    cur_rec, SERV_PROV_WEB_SITE_ADDRESS
    cur_rec, SERVICE_PROVIDER_WORK_PHONE
    cur_rec, SERV_PROV_ZIP_POSTAL_CODE
    cur_rec, UPDATE
    cur_rec SKILL.
    cur_rec, STATUS
    cur_rec subregion.
    cur_rec, TRADE
    cur_rec, VENDOR_ID
    cur_rec, VENDOR_PURCHASING_FAX
    cur_rec, VENDOR_SITECODE
    cur_rec, VENDOR_TICKET
    cur_rec, VENDOR_COMPANYNAME
    cur_rec, VIP
    cur_rec, WORK_ORDER_NO
    cur_rec, WORK_REQUEST
    cur_rec, WORK_REQUEST_CLASS
    cur_rec, WORK_TYPE
    cur_rec, WR_COST
    cur_rec, WR_DESCRIPTION
    cur_rec, WR_DISPATCH_METHOD
    cur_rec, WR_STATUS
    cur_rec, COUNTRY
    ld_curr_time
    );
    END LOOP;

    COMMIT;

    exception
    while others then
    Rollback;
    dbms_output.put_line('SQLCODE:'||) SQLCODE. "Error :'|| SQLERRM);

    end work_kiosk_full;

    Note: total record inserted 849000.

    The same code does not work with big collect in would adopt.

    Please help me why this is happening.


    Thanks and greetings
    Shyam ~.

    Shyam,

    I agree with Billy.

    Why are you not using an INSERT..SELECT ?
    
    Also, what are you trying to achieve by
    - incremental commits?
    - copying data from one table to another (using expensive I/O)?
    - using dynamic DML?
    
    Most of these approaches are typically wrong - and not recommended for scalable and performant Oracle applications.
    

    I could see you using a CURSOR for LOOP if you change the data inserted so that you could not encapsulate the changes in a query, but you do an insert in right in the table of your cursor. A much more effective way would be to use the following changes I made to your code sample:

    PROCEDURE WORK_KIOSK_FULL(AN_JOBID   IN NUMBER,
                              AC_SQLCODE OUT VARCHAR2,
                              AC_SQLERRM OUT VARCHAR2) IS
    BEGIN
       EXECUTE IMMEDIATE 'truncate table crstools.drt_bom_work_kiosk';
    
       /* Note:  The APPEND hint forces a Direct Path INSERT (see Link below code sample) and is combined with the NOLOGGING Hint */
       /*        To dramtically increase performance.  The Direct Path INSERT inserts records above the High-Water Mark on the table. */
    
       INSERT /*+ APPEND NOLOGGING */ INTO CRSTOOLS.DRT_BOM_WORK_KIOSK
          (JT_ID
          ,ACTUAL_HRS_TO_COMPLETE
          ,ACTUAL_HRS_TO_RESPOND
          ,AGENT_NAME
          ,ASAGENT_SOE_ID
          ,AP_SYSTEM
    --      ,ASSIGN_WORK_REQUEST_COMMENT     /* I commented out this COLUMN because it doesn't make sense to me to insert */
          ,BILLABLE                          /* a couple of space characters into a table.   If the intent is to leave the column NULL */
          ,BUILDING                          /* don't include it in your INSERT statement and it will be NULL.  If there is a valid reason */
          ,BUILDING_ID                       /* for inserting the spaces, then remove the "line comments" from the insert and select statments */
          ,BUILDING_STATUS
          ,CAUSE_TYPE
    --      ,COMMENTS
          ,COMPLETED_BY
          ,CONTACT_EMAIL
          ,CONTACT_NAME
          ,CONTACT_PHONE
          ,CORP_CODE
          ,COST_CENTER
          ,DATE_CLOSED
          ,DATE_COMPLETED
          ,DATE_REQUESTED
          ,DATE_RESPONDED
          ,DATE_RESPONSE_ECD
          ,DATE_SCHEDULED
          ,DEFERRAL_REASON
          ,DESCRIPTION
          ,ECD
          ,FACILITY_MANAGER
          ,FLOOR
          ,GENERAL_LEDGER
    --      ,KIOSK_DATE_REQUESTED
    --      ,KIOSK_DISPATCH_CONFIRMED
    --      ,KIOSK_DISPATCHED
          ,LINKED_EQUIPMENT_ALIAS
          ,LINKED_EQUIPMENT_ID
          ,LINKED_EQUIPMENT_NAME
          ,ORIGINATOR_TYPE
    --      ,PAYMENT_TERMS
          ,PRIORITY_CODE
          ,PROBLEM_TYPE
          ,PROPERTY
          ,QUOTE_TOTAL
          ,REGION
          ,REPAIR_DEFINITIONS
          ,REPAIR_DESCRIPTION
          ,REQUESTOR
    --      ,REQUESTOR_COST_CENTER
          ,REQUESTOR_EMAIL
          ,REQUESTOR_NAME
          ,REQUESTOR_PHONE
    --      ,RESPONSE_TIME
          ,ROOM
          ,SERVICE_PROVIDER
          ,SERVICE_PROVIDER_ADDRESS
          ,SERVICE_PROVIDER_CITY
          ,SERVICE_PROVIDER_CODE
          ,SERVICE_PROVIDER_COUNTRY
          ,SERVICE_PROVIDER_CURRENCY
          ,SERVICE_PROVIDER_DESCRIPTION
          ,SERV_PROV_DISPATC_HMETHOD
          ,SERV_PROV_DOUBLE_TIME_RATE
          ,SERVICE_PROVIDER_EMAIL
          ,SERV_PROV_EMERGENCY_PHONE
          ,SERVICE_PROVIDER_FAX_NUMBER
          ,SERVICE_PROVIDER_HOME_PHONE
          ,SERVICE_PROVIDER_HOURLY_RATE
          ,SERVICE_PROVIDER_JOB_TITLE
          ,SERVICE_PROVIDER_METHOD
          ,SERVICE_PROVIDER_MOBILE_PHONE
          ,SERVICE_PROVIDER_PAGER
          ,SERVICE_PROVIDER_RATES
          ,SER_PROV_SHIFT_DIFFERENTIAL
          ,SERV_PROV_STATE_PROVINCE
          ,SERVICE_PROVIDER_STATUS
          ,SERV_PROV_WEB_SITE_ADDRESS
          ,SERVICE_PROVIDER_WORK_PHONE
          ,SERV_PROV_ZIP_POSTAL_CODE
    --      ,SHIFT
    --      ,SKILL
          ,STATUS
          ,SUBREGION
    --      ,TRADE
          ,VENDOR_ID
          ,VENDOR_PURCHASING_FAX
          ,VENDOR_SITECODE
          ,VENDOR_TICKET
          ,VENDOR_COMPANYNAME
          ,VIP
          ,WORK_ORDER_NO
          ,WORK_REQUEST
          ,WORK_REQUEST_CLASS
          ,WORK_TYPE
    --      ,WR_COST
          ,WR_DESCRIPTION
    --      ,WR_DISPATCH_METHOD
          ,WR_STATUS
          ,COUNTRY
          ,CREATE_DATE
          )
       VALUES
          (SELECT DISTINCT
              JT.JT_ID AS JT_ID
             ,NVL((ROUND((JT_DATE_COMPLETED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_COMPLETE
             ,NVL((ROUND((JT_DATE_RESPONDED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_RESPOND
             ,PEO1.PEO_NAME AS AGENT_NAME
             ,PEO1.PEO_USER_NAME AS ASAGENT_SOE_ID
             ,LE.LGLENT_DESC AS AP_SYSTEM
    --         ,' ' AS ASSIGN_WORK_REQUEST_COMMENT
             ,DECODE(JT.JT_BILL_ID,138802,'CLIENT BILLABLE'
                                  ,138803,'CONTRACTED'
                                  ,138804,'INTERNAL BILLABLE',NULL,' ') AS BILLABLE
             ,BL.BLDG_NAME_CC AS BUILDING
             ,BL.BLDG_ID_LS AS BUILDING_ID
             ,DECODE(BL.BLDG_ACTIVE_CC, 'Y', 'ACTIVE', 'INACTIVE') AS BUILDING_STATUS
             ,DECODE(JT.JT_WRK_CAUSE_ID,141521,'STANDARD WEAR AND TEAR'
                                       ,141522,'NEGLIGENCE'
                                       ,141523,'ACCIDENTAL'
                                       ,141524,'MECHANICAL MALFUNCTION'
                                       ,141525,'OVERSIGHT'
                                       ,141526,'VANDAL'
                                       ,141527,'STANDARD'
                                       ,141528,'PROJECT WORK'
                                       ,6058229,'TEST',NULL,' ') AS CAUSE_TYPE
    --         ,' ' AS COMMENTS
             ,PEO3.PEO_NAME AS COMPLETED_BY
             ,JT.JT_REQUESTOR_EMAIL AS CONTACT_EMAIL
             ,JT.JT_REQUESTOR_NAME_FIRST || ' ' ||JT.JT_REQUESTOR_NAME_LAST AS CONTACT_NAME
             ,JT.JT_REQUESTOR_PHONE AS CONTACT_PHONE
             ,CC.CSTCTRCD_APCODE AS CORP_CODE
             ,CC.CSTCTRCD_CODE AS COST_CENTER
             ,JT.JT_DATE_CLOSED AS DATE_CLOSED
             ,JT.JT_DATE_COMPLETED AS DATE_COMPLETED
             ,JT.JT_DATE_REQUESTED AS DATE_REQUESTED
             ,JT.JT_DATE_RESPONDED AS DATE_RESPONDED
             ,JT.JT_DATE_RESPONSE_ECD AS DATE_RESPONSE_ECD
             ,JT.JT_DATE_SCHEDULED AS DATE_SCHEDULED
             ,DECODE(JT.JT_DEF_ID,139949,'WTG VENDOR RESPONSE'
                                 ,139950,'WAITING ON PARTS'
                                 ,139951,'LABOR AVAILABILITY'
                                 ,139952,'DEFERRED- HI PRI WORK'
                                 ,139953,'WTG APPROVAL'
                                 ,139954,'FUNDING REQUIRED'
                                 ,139955,'ACCESS DENIED'
                                 ,139956,'WTG MATERIAL',NULL,' ') AS DEFERRAL_REASON
             ,JT.JT_DESCRIPTION AS DESCRIPTION
             ,JT.JT_DATE_RESCHED_ECD AS ECD
             ,FMG.FACILITY_MANAGER AS FACILITY_MANAGER
             ,FL.FLOORS_TEXT AS FLOOR
             ,GL.GENLED_DESC AS GENERAL_LEDGER
    --         ,' ' AS KIOSK_DATE_REQUESTED
    --         ,' ' AS KIOSK_DISPATCH_CONFIRMED
    --         ,' ' AS KIOSK_DISPATCHED
             ,EQP.EQUIP_CUSTOMER_CODE AS LINKED_EQUIPMENT_ALIAS
             ,EQP.EQUIP_ID AS LINKED_EQUIPMENT_ID
             ,EQP.EQUIP_TEXT AS LINKED_EQUIPMENT_NAME
             ,DECODE(JT_ORIGINATOR_TYPE_ID,1000,'PROJECT MOVE REQUEST'
                                          ,138834,'CUSTOMER INITIATED CORRECTION'
                                          ,138835,'CUSTOMER INITIATED REQUEST'
                                          ,138836,'CORRECTIVE MAINTENANCE'
                                          ,138837,'CONFERENCE ROOM BOOKING'
                                          ,138838,'PROJECT INITIATED REQUEST'
                                          ,138839,'PLANNED PREVENTIVE MAINTENANCE'
                                          ,138840,'SELF INITATED REQUEST',NULL,' ') AS ORIGINATOR_TYPE
    --         ,' ' AS PAYMENT_TERMS
             ,PRIORITY_TEXT AS PRIORITY_CODE
             ,SWOTY.SWORKTYPE_TEXT AS PROBLEM_TYPE
             ,PROP.PROPERTY_NAME_CC AS PROPERTY
             ,JT.JT_COST_QUOTE_TOTAL AS QUOTE_TOTAL
             ,PAR.LEVELS_NAME AS REGION
             ,DECODE(JT.JT_REPDEF_ID,141534,'ADJUSTED SETTING'
                                    ,141535,'TRAINING FOR END'
                                    ,141536,'NEW REQUEST'
                                    ,141537,'NO REPAIR REQUIR'
                                    ,141538,'REPLACED PARTS'
                                    ,141539,'REPLACE EQUIPMEN'
                                    ,1000699,'NEW REQUEST',NULL,' ') AS REPAIR_DEFINITIONS
             ,JT.JT_REPAIRDESC AS REPAIR_DESCRIPTION
             ,JT.JT_REQUESTOR AS REQUESTOR
    --         ,' ' AS REQUESTOR_COST_CENTER
             ,JT.JT_REQUESTOR_EMAIL AS REQUESTOR_EMAIL
             ,JT.JT_REQUESTOR_NAME_FIRST AS REQUESTOR_NAME
             ,JT.JT_REQUESTOR_PHONE AS REQUESTOR_PHONE
    --         ,' ' AS RESPONSE_TIME
             ,RM.ROOM_NAME_CC AS ROOM
             ,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER
             ,P1.PEO_ADDRESS_1 AS SERVICE_PROVIDER_ADDRESS
             ,PEOCITY.CITY_TEXT SERVICE_PROVIDER_CITY
             ,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER_CODE
             ,PEOCITY.CITY_COUNTRY_NAME AS SERVICE_PROVIDER_COUNTRY
             ,PEOCUR.CURRENCY_TEXT AS SERVICE_PROVIDER_CURRENCY
             ,P1.PEO_NAME AS SERVICE_PROVIDER_DESCRIPTION
             ,P1.PEO_DISPATCH_METHOD AS SERV_PROV_DISPATC_HMETHOD
             ,P1.PEO_RATE_DOUBLE AS SERV_PROV_DOUBLE_TIME_RATE
             ,P1.PEO_EMAIL AS SERVICE_PROVIDER_EMAIL
             ,P1.PEO_EMERGENCY_PHONE AS SERV_PROV_EMERGENCY_PHONE
             ,P1.PEO_FAX AS SERVICE_PROVIDER_FAX_NUMBER
             ,P1.PEO_HOME_PHONE AS SERVICE_PROVIDER_HOME_PHONE
             ,P1.PEO_RATE_HOURLY AS SERVICE_PROVIDER_HOURLY_RATE
             ,P1.PEO_TITLE AS SERVICE_PROVIDER_JOB_TITLE
             ,P1.PEO_METHOD_ID AS SERVICE_PROVIDER_METHOD
             ,P1.PEO_CELL_PHONE AS SERVICE_PROVIDER_MOBILE_PHONE
             ,P1.PEO_PAGER AS SERVICE_PROVIDER_PAGER
             ,P1.PEO_RATE_DIFFERENTIAL AS SERVICE_PROVIDER_RATES
             ,P1.PEO_RATE_DIFFERENTIAL AS SER_PROV_SHIFT_DIFFERENTIAL
             ,PEOCITY.CITY_STATE_PROV_TEXT AS SERV_PROV_STATE_PROVINCE
             ,DECODE(P1.PEO_ACTIVE, 'Y', 'ACTIVE', 'INACTIVE') AS SERVICE_PROVIDER_STATUS
             ,P1.PEO_URL AS SERV_PROV_WEB_SITE_ADDRESS
             ,P1.PEO_PHONE AS SERVICE_PROVIDER_WORK_PHONE
             ,P1.PEO_POSTAL_CODE AS SERV_PROV_ZIP_POSTAL_CODE
    --         ,' ' AS SHIFT
    --         ,' ' AS SKILL
             ,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
                                       ,138814,'PENDING'
                                       ,138815,'OPEN'
                                       ,138816,'COMPLETED'
                                       ,138817,'CLOSED'
                                       ,138818,'CANCELLED',NULL,' ') AS STATUS
             ,LEV.LEVELS_NAME AS SUBREGION
    --         ,' ' AS TRADE
             ,P1.PEO_LS_INTERFACE_CODE1 AS VENDOR_ID
             ,P1.PEO_FAX AS VENDOR_PURCHASING_FAX
             ,P1.PEO_VENDOR_SITE_CODE AS VENDOR_SITECODE
             ,JT.JT_ID AS VENDOR_TICKET
             ,P1.PEO_NAME AS VENDOR_COMPANYNAME
             ,JT.JT_REQUESTOR_VIP AS VIP
             ,WO.WO_ID AS WORK_ORDER_NO
             ,JT.JT_ID AS WORK_REQUEST
             ,JT.JT_CLASS_ID AS WORK_REQUEST_CLASS
             ,WOTY.WORKTYPE_TEXT AS WORK_TYPE
    --         ,' ' AS WR_COST
             ,JT.JT_DESCRIPTION AS WR_DESCRIPTION
    --         ,' ' AS WR_DISPATCH_METHOD
             ,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
                                       ,138814,'PENDING'
                                       ,138815,'OPEN'
                                       ,138816,'COMPLETED'
                                       ,138817,'CLOSED'
                                       ,138818,'CANCELLED',NULL,' ') AS WR_STATUS
             ,CTRY.COUNTRY_NAME AS COUNTRY
             ,SYSDATE --LD_CURR_TIME
         FROM CITI.JOBTICKET JT,
              CITI.PROPERTY PROP,
              CITI.BLDG BL,
              CITI.BLDG_LEVELS BLDGLVL,
              CITI.LEVELS LEV,
              CITI.LEVELS PAR,
              (SELECT CRSTOOLS.STRAGG(PEO_NAME) FACILITY_MANAGER,
                      BLDGCON_BLDG_ID
                 FROM CITI.BLDG_CONTACTS, CITI.PEOPLE
                WHERE BLDGCON_PEO_ID = PEO_ID
                  AND BLDGCON_CONTYPE_ID IN (40181, 10142)
                GROUP BY BLDGCON_BLDG_ID) FMG,
              CITI.FLOORS FL,
              CITI.ROOM RM,
              CITI.GENERAL_LEDGER GL,
              CITI.LEGAL_ENTITY LE,
              CITI.COST_CENTER_CODES CC,
              CITI.EQUIPMENT EQP,
              CITI.WORKTYPE WOTY,
              CITI.SUBWORKTYPE SWOTY,
              CITI.WORK_ORDER WO,
              CITI.JT_WORKERS JTWO,
              CITI.PRIORITY,
              CITI.COUNTRY CTRY,
              CITI.PEOPLE P1,
              CITI.PEOPLE PEO3,
              CITI.PEOPLE PEO1,
              CITI.CITY PEOCITY,
              CITI.CURRENCY PEOCUR
        WHERE JT.JT_BLDG_ID = BL.BLDG_ID
          AND BL.BLDG_ID = BLDGLVL.BLDG_LEVELS_BLDG_ID
          AND BLDGLVL.BLDG_LEVELS_LEVELS_ID = LEV.LEVELS_ID
          AND LEV.LEVELS_PARENT = PAR.LEVELS_ID(+)
          AND PROP.PROPERTY_ID = BL.BLDG_PROPERTY_ID
          AND BL.BLDG_ACTIVE_LS = 'N'
          AND JT.JT_FLOORS_ID = FL.FLOORS_ID(+)
          AND JT.JT_ROOM_ID = RM.ROOM_ID(+)
          AND JT.JT_BLDG_ID = FMG.BLDGCON_BLDG_ID(+)
          AND JT.JT_GENLED_ID = GL.GENLED_ID(+)
          AND GL.GENLED_LGLENT_ID = LE.LGLENT_ID(+)
          AND JT.JT_CSTCTRCD_ID = CC.CSTCTRCD_ID(+)
          AND JT.JT_EQUIP_ID = EQP.EQUIP_ID(+)
          AND JT.JT_ID = JTWO.JTW_JT_ID(+)
          AND JT.JT_WORKTYPE_ID = WOTY.WORKTYPE_ID(+)
          AND JT.JT_SWORKTYPE_ID = SWOTY.SWORKTYPE_ID(+)
          AND JT.JT_WO_ID = WO.WO_ID
          AND JT.JT_PRIORITY_ID = PRIORITY_ID(+)
             --AND jt.jt_date_requested >= ADD_MONTHS (SYSDATE, -12)
          AND JT.JT_LAST_UPDATE >= ADD_MONTHS(LD_CURR_TIME, -12)
          AND BL.BLDG_COUNTRY_ID = CTRY.COUNTRY_ID
          AND JTWO.JTW_PEO_ID = P1.PEO_ID(+)
          AND P1.PEO_CITY_ID = PEOCITY.CITY_ID(+)
          AND JT.JT_COMPLETED_BY_PEO_ID = PEO3.PEO_ID(+)
          AND P1.PEO_RATE_CURRENCY_ID = PEOCUR.CURRENCY_ID(+)
          AND JT.JT_AGENT_PEO_ID = PEO1.PEO_ID(+)
          );
    
       COMMIT;
    
    EXCEPTION
       WHEN OTHERS THEN
          ROLLBACK;
          DBMS_OUTPUT.PUT_LINE('SQLCODE :' || SQLCODE || ' Error :' || SQLERRM);
    
    END WORK_KIOSK_FULL;
    

    Here is the link for infor the [Oracle Direct - Path INSERT | http://download.oracle.com/docs/cd/B10501_01/server.920/a96524/c21dlins.htm#10778].

    Also, if you are really wanting to use a CURSOR for LOOP COLLECTION in BULK, I suggest you read the article by Steven Feuerstein [PL/SQL practices: GEM VRAC | http://www.oracle.com/technology/oramag/oracle/08-mar/o28plsql.html].

    I hope this helps.
    Craig...

    If my response or response from another person was helpful, please mark accordingly

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

  • Cursors open loop (the cursor as a variable name)

    Hello

    I have a problem:
    In my home, I said 200 sliders.
    Now, I want to open, extract, and close a loop.
    I think of a table containing the names of all of the cursor.

    That's what I have (example maybe stupid but just to explain the problem):

    DECLARE
    v_empno VARCHAR2 (10);
    v_empname VARCHAR2 (10);

    Cursor c1 IS
    SELECT EMPNO '1', 'Adam' EMPNAME
    DOUBLE;
    Cursor c2 IS
    SELECT EMPNO '2', 'John' EMPNAME
    DOUBLE;
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO v_empname, v_empno;
    OUTPUT WHEN c1% NOTFOUND;
    dbms_output.put_line (v_empno |) » '|| v_empname);
    END LOOP;
    CLOSE c1;

    OPEN c2;
    LOOP
    C2-FETCH INTO v_empname, v_empno;
    OUTPUT WHEN c2% NOTFOUND;
    dbms_output.put_line (v_empno |) » '|| v_empname);
    END LOOP;
    CLOSE C2;
    END;

    And that's what I want to achieve:

    DECLARE
    v_empno VARCHAR2 (10);
    v_empname VARCHAR2 (10);

    TYPE cursors_tab IS TABLE OF varchar (5);
    t_cursors cursors_tab: = cursors_tab ('c1', 'c2');

    Cursor c1 IS
    SELECT EMPNO '1', 'Adam' EMPNAME
    DOUBLE;
    Cursor c2 IS
    SELECT EMPNO '2', 'John' EMPNAME
    DOUBLE;

    BEGIN
    for me in t_cursors.first... loop of t_cursors. Last
    OPEN: t_cursors (i);
    LOOP
    FETCH: t_cursors (i) INTO v_empno, v_empname;
    EXIT WHEN t_cursors (i) % NOTFOUND;
    dbms_output.put_line (v_empno |) » '|| v_empname);
    END LOOP;
    CLOSE: t_cursors (i);
    end loop;
    END;

    Is this possible? I am trying to solve it, but I'm losing hope ;)
    DECLARE
    v_empno VARCHAR2(10);
    v_empname VARCHAR2(10);
    
    TYPE stmt_tab IS TABLE OF VARCHAR(32767);
    t_stmt stmt_tab := stmt_tab(
                                'SELECT ''1'' EMPNO,''Adam'' EMPNAME FROM dual',
                                'SELECT ''2'' EMPNO,''John'' EMPNAME FROM dual'
                               );
    t_cur sys_refcursor;
    BEGIN
    for i in t_stmt.first .. t_stmt.last loop
    OPEN t_cur for t_stmt(i);
    LOOP
    FETCH t_cur INTO v_empno, v_empname;
    EXIT WHEN t_cur%NOTFOUND;
    dbms_output.put_line (v_empno||' '|| v_empname);
    END LOOP;
    CLOSE t_cur;
    end loop;
    END;
    /
    1 Adam
    2 John
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

Maybe you are looking for