PLS-00394 - Using collections

Oracle 9i
I get the following error when I run the below stored procedure.
PLS-00394: wrong number of values in the INTO list of FETCH statement.
CREATE OR REPLACE procedure TEST_PROC
is
cnt number := 1;
type my_record is record
a varchar2(20),
b number(10),
c varchar2(50),
d varchar2(10),
e number(2),
l char(2) :='ll',
m varchar2(2) :='mm',
n varchar2(2) :='nn',
s varchar2(2) :='ss'
type tab_my_rec is table of my_record;
tab_rec tab_my_rec;
cursor cur is
select a,b,c,d,e from table2;
begin
open cur;
loop
fetch cur bulk collect into tab_rec limit 100;
forall t in 1.. tab_rec.count
insert into (select a,b,c,d,e,l,m,n....s from table1) values tab_rec(t);
-- Commit every 100 records
cnt := cnt+1;
if mod(cnt, 100) = 0 THEN
     COMMIT;
end if;
EXIT WHEN tab_rec.COUNT = 0;
end loop;
commit;
close cur;
end;
If I specify a default value in the select clause then it works
cursor cur
is
select a,b,c,d,e,'ll','mm',.,.,.,.,'ss' from table2;
Question:
1) I need to insert default values to the last columns(column 7 .....column 10) of a table1. Should i specify it in the cursor or can i do only by defining it at the record level? I do not want to define it in the select statement.
Should the number of columns selected in the SELECT query match the number of variables used in the fetch statement?
2) I am using records to group related data items from table2 & load it into table1 with some additional constant fields. Using RECORDS an ideal approach?
Thanks in advance.

Thanks for the reply.
Yes you are right I do have a workaround. But it goes back to my original question were i didn't want to define the constant values in the cursor declaration section but wanted to specify it while inserting the values. I don't think its possible to do it directly in oracle 9i or 10g becuase of the restriction stated above.
This works
forall t in 1.. tab_rec.count
insert into (select a,b,c,d,e,l,m,n....s from table1) values tab_rec(t);
This doesn't
forall t in 1.. tab_rec.count
insert into (select a,b,c,d,e,l,m,n....s from table1) values (tab_rec(t).a,tab_rec(t).b,tab_rec(t).c,tab_rec(t).d,tab_rec(t).e,'ll','mm','nn',....,'ss');
Can not reference individual attributes of records with FORALL in (oracle 9i or 10g).
I think the only solution is to define the constant values in the cursor select statement & in the record declartion to hold these values and insert them all. Like this
forall t in 1.. tab_rec.count
insert into (select a,b,c,d,e,l,m,n....s from table1) values tab_rec(t);
Committing once at the end of all the inserts might not works as I have 1 million records to insert.
Solomon is right my code for commit is not efficient. If I have 1 million records to commit then is it good to commit for every 1000 or 10000 records? How do I code it more efficiently?
Thanks in advance. Appreciate your input.

Similar Messages

  • PLS-00642: local collection types not allowed in SQL statements

    Hi,
    I want to retrieve empno in plsql table.
    Now based on the empno in plsql table I want to retrieve thier deptno in another plsql table/varray.
    SQL> declare
      2   type vdeptno  is table of number;
      3    v_deptno vdeptno;
      4    TYPE e_tab is table of  PLS_INTEGER INDEX BY PLS_INTEGER;
      5    empno_tab e_tab;
      6   Begin
      7  Select empno bulk collect into empno_tab FROM emp;
      8  FOR i in empno_tab.FIRST..empno_tab.LAST
      9  LOOP
    10   dbms_output.put_line(empno_tab(i));
    11   Select deptno into v_deptno
    12   FROM emp
    13    where empno=empno_tab(i);
    14   END loop;
    15  END;
    16  /
    Select deptno into v_deptno
    ERROR at line 11:
    ORA-06550: line 11, column 21:
    PLS-00642: local collection types not allowed in SQL statementsAny other way to do the same.
    Twinkle

    When you use this method ...
    type vdeptno is table of number;
    v_deptno vdeptno;
    You need to allocate space to the object prior to inserting into it , (use .EXTENDS for this). Or you need to initialize it while declaring it.
    or try the following
    SQL> declare
    2 type vdeptno is table of number;
    3 v_deptno vdeptno;
    4 TYPE e_tab is table of PLS_INTEGER INDEX BY PLS_INTEGER;
    5 empno_tab e_tab;
    6 Begin
    7 Select empno bulk collect into empno_tab FROM emp;
    8 FOR i in empno_tab.FIRST..empno_tab.LAST
    9 LOOP
    10 dbms_output.put_line(empno_tab(i));
    11 Select deptno bulk collect into v_deptno
    12 FROM emp
    13 where empno=empno_tab(i);
    14 END loop;
    15 END;
    16 /
    Edited by: user9276238 on Jun 14, 2010 3:26 AM

  • PLS-00394 error

    Hi
    i have create a procedure to retrieve data and when i compile i receive an error with this
    "PLS-00394- wrong number of values in the INTO list of a FETCH statement"
    here is the code
    vLine VARCHAR2(4000);
    CURSOR CurseurCRC
    IS
    SELECT
    O.OPPORTUNITY_ID
    , R.RA_CMPGN_NAME
    , I.BO_ID_CUST
    , R.START_DATE
    , O.EST_CLOSE_DT
    , O.ROW_ADDED_DTTM
    , O.ROW_LASTMANT_DTTM
    , CASE WHEN O.ROW_LASTMANT_OPRID IS NULL THEN ' '
    WHEN LENGTH(O.ROW_LASTMANT_OPRID)=6 THEN UPPER(SUBSTR(O.ROW_LASTMANT_OPRID,0,5))
    ELSE UPPER(O.ROW_LASTMANT_OPRID)
    END
    , O.OPPORTUNITY_STATUS
    , MAX(I.ROW_ADDED_DTTM)
    , MAX(I.INTERACT_STATUS) keep (DENSE_RANK LAST ORDER BY I.ROW_ADDED_DTTM)
    , TO_CHAR(O.ROW_ADDED_DTTM,'YYYY')
    FROM
    SYSADM.PS_RSF_OPPORTUNITY O
    , SYSADM.PS_RI_INTERACTION I
    , SYSADM.PS_RA_CAMPAIGN R
    , SYSADM.PS_RI_STATUS_TBL S
    WHERE
    O.RA_CAMPAIGN_ID = R.RA_CAMPAIGN_ID
    AND R.RA_CAMPAIGN_ID = I.RA_CAMPAIGN_ID
    AND S.RB_MCF_STATUS = I.INTERACT_STATUS
    AND O.BO_ID_CUST=I.BO_ID_CUST
    AND O.RA_CAMPAIGN_ID NOT LIKE (' ')
    AND O.ROW_ADDED_DTTM > TO_DATE(vLASTRUN, 'YYYYMMDD')
    AND O.ROW_ADDED_DTTM < TO_DATE(vCURRENTRUN, 'YYYYMMDD')
    AND O.OPPORTUNITY_ID IN (
    SELECT DISTINCT OPPORTUNITY_ID
    FROM SYSADM.PS_RSF_OPPORTUNITY OPP, SYSADM.PS_BGL_CALL_LST CLST
    WHERE OPP.BO_ID_CUST = CLST.BO_ID_CUST
    AND OPP.ROW_ADDED_DTTM = CLST.ROW_ADDED_DTTM
    AND OPP.RA_CAMPAIGN_ID = CLST.RA_CAMPAIGN_ID
    AND CLST.ROW_ADDED_DTTM > TO_DATE(vLASTRUN, 'YYYYMMDD')
    AND CLST.ROW_ADDED_DTTM < TO_DATE(vCURRENTRUN, 'YYYYMMDD')
    group by
    O.OPPORTUNITY_ID
    , R.RA_CMPGN_NAME
    , I.BO_ID_CUST
    , R.START_DATE
    , O.EST_CLOSE_DT
    , O.ROW_ADDED_DTTM
    , O.ROW_LASTMANT_DTTM
    , O.ROW_LASTMANT_OPRID
    , O.OPPORTUNITY_STATUS
    , TO_CHAR(O.ROW_ADDED_DTTM,'YYYY');
    OPEN CurseurCRC;
    LOOP
    FETCH CurseurCRC INTO vLine;
    EXIT WHEN CurseurCRC%NOTFOUND;
    BEGIN
    sys.utl_file.put_line(vFileExport,vLine);
    COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
    vCrcErrCount:=vCrcErrCount+1;
    ROLLBACK;
    END;
    vCrcCount:=vCrcCount+1;
    END LOOP;
    CLOSE CurseurCRC;
    thanks for your help
    Edited by: user534160 on Sep 8, 2011 11:35 PM
    Edited by: user534160 on Sep 8, 2011 11:35 PM

    Your cursor query select clause has apprximate 12 columns selected and you are using only one variable to fetch them.. this is why you are getting this error.
    As a fix,
    either use same number of variables to fetch value of each column selected in cursor query ,
    or join all the columns using string concatenation operator to make them one string as shown in below example:
    DECLARE
         vLine VARCHAR2(4000);
         CURSOR C
         IS
         SELECT
              TO_CHAR(NUMBER_ID) || ' ' ||
              STRCOLUM_1 || ' ' ||
              STRCOLUM_2
         FROM TABLE_NAME     ;
    BEGIN
         /*your script is reused in this example*/
         OPEN C;
         LOOP
              FETCH C INTO vLine;
              EXIT WHEN C%NOTFOUND;
              BEGIN
                   sys.utl_file.put_line(vFileExport,vLine);
                   COMMIT;
              EXCEPTION
                   WHEN OTHERS THEN
                        vCrcErrCount:=vCrcErrCount+1;
                        ROLLBACK;
              END;
              vCrcCount:=vCrcCount+1;
         END LOOP;
         CLOSE C;          
    END;Regards,
    Dipali

  • PLS-00394 Error message when deploying a mapping

    Hi all,
    Using Warehouse Builder 10.1.0.4.0 I created a mapping to add one row to a dimension. This dimension contains three columns. In my mapping I created two constants, each mapped to one column. There is also one sequence, the nextval is mapped to the third column. The data is merged to the target dimension.
    When I generate the intermediate result I see the desired merge statement. But when I try to deploy the mapping, the package is invalid because of a "PLS-00394: wrong number of values in the INTO list of a FETCH statement".
    The SQL causing the error is a fetch from a cursor, selecting the two constants and the nextval of the sequence. However, the INTO clause of the fetch only contains a variable for the nextval of the sequence, not for the two constants.
    Can anyone tell me what I am doing wrong here?
    Thanks in advance.
    Paul

    I'm also running SOA Suite 11g ( on 64bit RH 5.4 )
    Just looking at my SOAServer's command line where the policy is referenced
    -Dweblogic.Name=SOAServer1 -Djava.security.policy=/orclapps/oracle/middleware/wlserver_10.3/server/lib/weblogic.policy
    The policy file on my server is 9426 bytes, and it does reference some FMW elements within - do you see the same in yours?
    // For Oracle JRF to load OPSS Policy provider
    grant codeBase "file:${oracle.home}/modules/oracle.jps_${jrf.version}/*" {
    permission java.security.AllPermission;
    //grant to alternative location as well for some FMW install
    grant codeBase "file:${common.components.home}/modules/oracle.jps_${jrf.version}/*" {
    permission java.security.AllPermission;
    // For Oracle JRF to load Oracle Wallet
    grant codeBase "file:${oracle.home}/modules/oracle.pki_${jrf.version}/*" {
    permission java.security.AllPermission;
    //grant to alternative location as well for some FMW install
    grant codeBase "file:${common.components.home}/modules/oracle.pki_${jrf.version}/*" {
    permission java.security.AllPermission;
    };

  • PLS-00394: wrong number of values

    Hi,
    I have this
    SET SERVEROUT ON
    DECLARE
    v_line varchar2(100);
    Cursor C_TBS is
    Select A.tablespace_name,
         A.total_size "Taille totale Ko",
         B.Free_space "Space disponible Ko",
    ((A.total_size-B.Free_space)*100/A.total_size) "% Occupied Espace "
    From
              (select tablespace_name, sum(BYTES)/1024 total_size
              from dba_data_files
              group by tablespace_name) A ,
              (select tablespace_name, sum(BYTES)/1024 Free_space
              from dba_free_space
              group by tablespace_name) B
    where a.tablespace_name = b.tablespace_name
    AND
    ((A.total_size-B.Free_space)*100/A.total_size) > 80;
    BEGIN
    DBMS_OUTPUT.ENABLE(10000);
    Open C_TBS;
    Loop
    Fetch C_TBS into v_line;
    DBMS_OUTPUT.PUT_LINE('TABLESPACE8NAME is : '||v_line);
    EXIT WHEN c_TBS%NOTFOUND;
    END LOOP;
    END;
    With this error :
    Fetch C_TBS into v_line;
    ERROR at line 23:
    ORA-06550: line 23, column 4:
    PLS-00394: wrong number of values in the INTO list of a FETCH statement
    How do I define v_line variable to avoid PLS-00394 error ?
    Many thanks.

    Hi!
    When you have a cursor retrieving more than one column you need to define a record to fetch the row like:
    v_line C_TBS%rowtype;
    but in your dbms_output you have to use
    DBMS_OUTPUT.PUT_LINE('TABLESPACE8NAME is : '||v_line.tablespace_name);
    because you have to refer to the individual column in the record.
    Regards,
    Petra

  • In Oracle 10g Error while using COLLECT

    I getting error while using collect in 10g
    SQL> ed
    Wrote file afiedt.buf
    1 SELECT deptno
    2 , COLLECT(ename) AS emps
    3 FROM emp
    4 GROUP BY
    5* deptno
    SQL> /
    , COLLECT(ename) AS emps
    ERROR at line 2:
    ORA-00932: inconsistent datatypes: expected NUMBER got -
    Please give me the solution.

    you are using old version of SQL*Plus. if you use later version it will give you correct result.
    Edited by: unus on Mar 14, 2010 4:25 AM

  • Problem  in using COLLECT statment

    Hi experts,
    getting problem in using COLLECT statement.  attaching my code below.
    LOOP AT it_final1 INTO wa_final1.
         LOOP AT it_final INTO wa_final WHERE vagrp = wa_final1-vagrp AND verwmerkm = wa_final1-verwmerkm.
           wa_final1-anzwertg = wa_final-anzwertg.
           COLLECT wa_final1 INTO it_final1.
         ENDLOOP.
         CLEAR: wa_final1, wa_final.
       ENDLOOP.
    here , i want to use collect statement only for  "anzwertg" field from internal table. but 2 more fields also getting  compressed .
    attaching screen shot
    here, original_input and max fields also getting compressed.
    could anybody please help me out in this.
    Thanks in advance.
    Regards
    satish

    Hi satish....
    collect statement works based on char fields..
    by default it will taken char fields as a key fields .........
    if any char field is repeated then corresponding numc values will be added....
    other wise it will act as a APPEND statement......
    Here in ur code there is no char field then how it will caliculate that values...
    just check it once..
    Regards,
    Vamsi....

  • How to use collect statement for below

    data : begin of itab,
             n(3) type c,
          n1 type n,
          k(5) type c,
          end of itab.
    select n n1 from into itab table /zteest.
    *internal table has
    n      n1    k
    gar    100  uji
    hae    90   iou
    gar    90   uji
    hae    87   iou
    I want
    gar 190
    hae 177
    How to use collect statement as n1 is n ..?
    let me know..
    Thanks

    try this..
    DATA : BEGIN OF itab OCCURS 0,
    n(3) TYPE c,
    n1(3) TYPE p DECIMALS 2,
    k(5) TYPE c,
    END OF itab.
    itab-n = 'gar'.
    itab-n1 = 100.
    itab-k = 'uji'.
    COLLECT itab .CLEAR itab.
    itab-n = 'hae'.
    itab-n1 = 90.
    itab-k = 'iou'.
    COLLECT itab .CLEAR itab.
    itab-n = 'gar'.
    itab-n1 = 90.
    itab-k = 'uji'.
    COLLECT itab .CLEAR itab.
    itab-n = 'hae'.
    itab-n1 = 87.
    itab-k = 'iou'.
    COLLECT itab .CLEAR itab.

  • Using COLLECT on a internal table

    Hello,
    I have fetched records from a table into my internal table through, " SELECT * FROM .... INTO TABLE FOR ALL ENTRIES IN ...... "
    There are two columns in my internal table against which i need a total of the column. COLLECT sums the amounts . But how can i use COLLECT in this scenario ?
    Can anyone kindly guide me ...Thanks
    Shehryar Dahar

    Hi,
    COLLECT add the numeric entries for the corresponding table keys..
    Example.
    DATA: BEGIN OF ITAB OCCURS 0,
    MATNR TYPE MATNR,
    COUNT TYPE I,
    END OF ITAB.
    ITAB-MATNR = 'ABC'.
    ITAB-COUNT = 2.
    COLLECT ITAB.
    ITAB-MATNR = 'ABC'.
    ITAB-COUNT = 1.
    COLLECT ITAB.
    ITAB-MATNR = 'ABCD'.
    ITAB-COUNT = 2.
    COLLECT ITAB.
    ITAB-MATNR = 'ABCD'.
    ITAB-COUNT = 3.
    COLLECT ITAB.
    LOOP AT ITAB.
    WRITE: / ITAB-MATNR, ITAB-COUNT.
    ENDLOOP.
    For more information on Collect, check this site:
    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/collect.htm
    Hope this would help you out.
    Regards,
    Varun.

  • Need a function to calcultate value using collections

    Hi
    I have a main table ab ( sno,empid,joindate,sal_mth, sal_yr ,run_date)
    a stage table cd (sno,empid,joindate,sal_mth).
    Now the catch is for every run( every day run), I need to get all data from ab and roll fwd them to the run date ( only change would be run_date)
    Also If in stage table cd we receive data for the combination sno,empid,joindate,sal_mth which is present in ab, we would
    change the sal_yr in ab - criteria would be sal_yr:=sal_yr + cd.sal_mth
    I have done it but in primitive way using union etc. Would prefer a function to do this using collection.
    Any suggestions?
    Regards
    SHUBH

    Something like below ? (to be turned into function as you didn't mention what to return)
    procedure roll_fwd(p_run_date in date) is
    begin
      insert into ab
      select a.sno,a.empid,a.joindate,a.sal_mth,a.sal_yr + nvl(c.sal_mth,0) sal_yr,p_run_date
        from ab a,cd c
       where a.run_date = p_run_date - 1
         and a.sno = c.sno(+)
         and a.empid = c.empid(+)
         and a.joindate = c.joindate(+)
         and a.sal_mth = c.sal_mth(+);
    end;Regards
    Etbin
    Edited by: Etbin on 20.2.2011 17:14
    No action taken on cd data - if they're lucky, they may get another increase next day ;)

  • How to acheive this scnerio in PL/SQl using collections

    Hi All,
    In my apllication we are handling two types of procedures which runs based on the jobs.
    Due to some problem few records where got missed in prouduction.
    We have tried to run this jobs manaually one by one and it is taking time to execute..
    I have got a suggetsion from my senior to do in a collection and run this packages at a time..
    Here is my exact scenerio, can you please help me out to implemnet in collections..
    Steps:
    Populate the missing records namely ordered, event sequence, Start date, end date, region in to plsql table/collection. ( Hard-coded since this will run the code
    for a date which will take less time and take less record).
    looping the plsqltable/collection for missing records
    Running the procedure p_Daily with startdate and end date parameter
    -- if the above executed successfully we need to execute second procedure i.e p_Region procedure by checking records in f_daily_report exist/relevant table
    (Id and sequence).
    Running the procedure p_region with start date and region id ( checking whether id and sequece is exist f_daily_report table).
    end loop
    The above steps which i have explained needs to achievd thru collections, can anybody helps me out on this.
    Note:
    1. All the missing jobs wil fal under differnt date rane groups.
    2. For second job i.e p_region i have mentioned that it will run based on start date and region id..This job will run on three differnt region id's..We can find the
    region id based on by joining f_region and d_region table. It seems that these misisng records belongs to all three regions
    Hope u all understand my scenrio. can you please help me out..
    Thanks in advance,
    Anoo..

    Anoo wrote:
    Hi,
    Hope you have not clear my question..The reason is i want to know how we can achieve my problem in collection
    rather than select statement.. Even though if we can get in simple statement is not advisible in my case..That is the reason why i was looking collections...
    Rather than providing data is it possible to how we can proceed in collections.That's like saying you want to write poor code that performs slowly rather than fast and performant code.
    Without clear explanations and examples of data and output, there doesn't appear to be a valid reason for using collections. The reason you're not getting many responses on your thread is because you're not explaining clearly what is required with examples. Please read {message:id=9360002} for an idea of what people need from you in order to help you.

  • Best practices when using collections in LR 2

    How are you using collections and collection sets? I realize that each photographer uses them differently, but I'm looking some inspiration because I have used them only very little.
    In LR 1 I used collections a bit like virtual Folders, but it doesn't anymore work as naturally in LR2.
    In LR 1 it was like:
    Travel (1000 images, all Berlin images)
    Travel / Berlin trip (400 images, all Berlin trip images)
    Travel / Berlin trip / web (200 images)
    Travel / Berlin trip / print (100 images)
    In LR 2 it could be done like this, but this somehow feels unnatural.
    Travel (Collection Set)
    Travel / Berlin trip (CS)
    Travel / Berlin trip / All (collection, 400 images)
    Travel / Berlin trip / web (collection, 200 images)
    Travel / Berlin trip / print (collection, 100 images)
    Or is this kind of use stupid, because same could be done with keywords and smart collections, and it would be more transferable.
    Also, how heavily are you using Collections? I'm kind of on the edge now (should I start using them heavily or not), because I just lost all my collections because I had to build my library from scratch because of weird library/database problems.

    Basically, i suggest not to use collections to replicate the physical folder structure, but rather to collect images independent of physical storage to serve a particular purpose. The folder structure is already available as a selection means.
    Collections are used to keep a user defined selection of images as a persistent collection, that can be easily accessed.
    Smart collections are based on criteria that are understood by the application and automatically kept up to date, again as a persistent collection for easy access. If this is based on a simple criterium, this can also, and perhaps even easier, done by use of keywords. If however it is a set of criteria with AND, OR combinations, or includes any other metadata field, the smart collection is the better way to do it. So keywords and collections in Lightroom are complementary to eachother.
    I use (smart)collections extensively, check my website  www.fromklicktokick.com where i have published a paper and an essay on the use of (smart)collections to add controls to the workflow.
    Jan R.

  • Interactive Reports using collections - How to control column headings

    Hi,
    I found a link in the forum somewhere that showed a step by step how to to use collections with Interactive Reports so you can dynamically build the SQL and also control the column headings. Does anyone know where the How-To is ??
    If not, I know how to build the SQL dynamically but what is the best way to control the column headings.
    Sometimes the report will have 17 columns and other times up to 30 columns.
    Thank you, Bill

    Hi Bill,
    Without knowing more about the PL/SQL code, the underlying tables and the select statements used, it is difficult to say.
    I would firstly check that I had indexes on the right column or combination of columns. One minute sounds a lot for a query to me, but that may be ok if the tables are very large and the PL/SQL has to do a fair bit to construct the output. You could also do an Explain Plan for any query to check to see if indexes are being used if they exist - this would also show up any part of a query that takes an inordinate amount of time.
    I assume that the PL/SQL is only run once even if the page is reloaded multiple times? However, once the collection has been created, the report itself should be fairly quick as it should be just a simple select over the collection data. Switching on the debug mode should help identify which part is taking the time.
    Andy

  • Using collections to insert

    Hi ,
    To improve the performance of the insert statement i was adviced to use the collections.
    I'm not getting any idea on how to use collection concept in my code.
    Could you please give me a skelton approach to do that.
    The following is the sample code (the logic is same in prod code,instead of for 1 -100000 we have cursor in prod) without using collections
    create table pop_tab (     col1 number ,col2 number ,col3 number ,col4 number ) 
    create or replace package test_collect
    is
      procedure proc_lvl_ld ;
      procedure proc_pop_tab (v_var1 number ,v_var2 number ,v_var3 number ,v_var4 number) ;
    end test_collect;
    create or replace package body test_collect
    is
       procedure proc_lvl_ld
        is
          v_cnt number := 1 ;
          v_var1 NUMBER ;
          v_var2 NUMBER ;
          v_var3 NUMBER ;
          v_var4 NUMBER;
         begin
          for i in 1 .. 100000 loop
            v_var1 := v_cnt + 1;
            v_var2 := v_cnt + 2;
            v_var3 := v_cnt + 3;
            v_var4 := v_cnt + 4;
            v_cnt  := v_cnt + 1;
          proc_pop_tab (v_var1 ,v_var2,v_var3,v_var4);
         end loop;
          commit;
          exception when others then
           DBMS_OUTPUT.PUT_LINE ( 'proc_lvl_load'||sqlcode||','||sqlerrm );
        end proc_lvl_ld;
         procedure proc_pop_tab (v_var1 number ,v_var2 number ,v_var3 number ,v_var4 number)
          is
           begin
             insert into pop_tab (col1,col2,col3,col4)
                     values (v_var1,v_var2,v_var3,v_var4) ;
           exception when others then
           DBMS_OUTPUT.PUT_LINE ( 'proc_pop_tab'||sqlcode||','||sqlerrm );             
           end proc_pop_tab;
    end test_collect;Now i tried a bit using colliection to improve the insert performance and stuck how to use the collections
    create or replace package body test_collect
    is
       procedure proc_lvl_ld
        is
           TYPE numtab1 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
           data1    numtab1;
           TYPE numtab2 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
           data2    numtab2;
           TYPE numtab3 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
           data3    numtab3;
           TYPE numtab4 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
           data4    numtab4;
          v_cnt number := 1 ;
         begin
          for i in 1 .. 100000 loop
            data1(data1.count +1) := v_cnt + 1;
            data2(data2.count +1) := v_cnt + 1;
            data3(data3.count +1) := v_cnt + 1;
            data4(data4.count +1) := v_cnt + 1;
            v_cnt  := v_cnt + 1;
          --proc_pop_tab (v_var1 ,v_var2,v_var3,v_var4);
         end loop;
           forall j in 1 ..data1.count
             insert into pop_tab
                 values (  --- How to use  the above collection variables here
          commit;
          exception when others then
           DBMS_OUTPUT.PUT_LINE ( 'proc_lvl_load'||sqlcode||','||sqlerrm );
        end proc_lvl_ld;
    end;Could you please help me out in this and let me know if i'm not clear
    Edited by: Smile on Sep 7, 2012 11:37 AM

    Use:
           forall j in 1 ..data1.count
             insert into pop_tab
                 values (data1(j),data2(j),data3(j),data4(j));       Now:
    SQL> create or replace package body test_collect
      2   is
      3     procedure proc_lvl_ld
      4      is
      5     TYPE numtab1 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
      6     data1    numtab1;
      7     TYPE numtab2 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
      8     data2    numtab2;
      9     TYPE numtab3 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
    10     data3    numtab3;
    11     TYPE numtab4 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
    12     data4    numtab4;
    13    v_cnt number := 1 ;
    14   begin
    15    for i in 1 .. 100000 loop
    16      data1(data1.count +1) := v_cnt + 1;
    17      data2(data2.count +1) := v_cnt + 1;
    18      data3(data3.count +1) := v_cnt + 1;
    19      data4(data4.count +1) := v_cnt + 1;
    20      v_cnt  := v_cnt + 1;
    21        --proc_pop_tab (v_var1 ,v_var2,v_var3,v_var4);
    22       end loop;
    23     forall j in 1 ..data1.count
    24       insert into pop_tab
    25       values (data1(j),data2(j),data3(j),data4(j));  
    26    commit;
    27    exception when others then
    28     DBMS_OUTPUT.PUT_LINE ( 'proc_lvl_load'||sqlcode||','||sqlerrm );
    29   
    30      end proc_lvl_ld;
    31  end;
    32  /
    Package body created.
    SQL> exec test_collect.proc_lvl_ld;
    proc_lvl_load-6502,ORA-06502: PL/SQL: numeric or value error: number precision too large
    PL/SQL procedure successfully completed.
    SQL> Why? You declared associative arrays as NUMBER(4) while values you are trying to assign their elements are in range:
    for i in 1 .. 100000 loopIf I change it to:
    for i in 1 .. 9998 loopThen:
    SQL> create or replace package body test_collect
      2   is
      3     procedure proc_lvl_ld
      4      is
      5     TYPE numtab1 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
      6     data1    numtab1;
      7     TYPE numtab2 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
      8     data2    numtab2;
      9     TYPE numtab3 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
    10     data3    numtab3;
    11     TYPE numtab4 IS TABLE OF NUMBER (4) INDEX BY BINARY_INTEGER;
    12     data4    numtab4;
    13    v_cnt number := 1 ;
    14   begin
    15    for i in 1 .. 9998 loop
    16      data1(data1.count +1) := v_cnt + 1;
    17      data2(data2.count +1) := v_cnt + 1;
    18      data3(data3.count +1) := v_cnt + 1;
    19      data4(data4.count +1) := v_cnt + 1;
    20      v_cnt  := v_cnt + 1;
    21        --proc_pop_tab (v_var1 ,v_var2,v_var3,v_var4);
    22       end loop;
    23     forall j in 1 ..data1.count
    24       insert into pop_tab
    25       values (data1(j),data2(j),data3(j),data4(j));  
    26    commit;
    27    exception when others then
    28     DBMS_OUTPUT.PUT_LINE ( 'proc_lvl_load'||sqlcode||','||sqlerrm );
    29   
    30      end proc_lvl_ld;
    31  end;
    32  /
    Package body created.
    SQL> exec test_collect.proc_lvl_ld;
    PL/SQL procedure successfully completed.
    SQL> select count(*) from pop_tab
      2  /
      COUNT(*)
          9998
    SQL> SY.

  • How to use collect?

    hi all ,
    i want to add net value of all the line items which are in the same group
    am using collect but am unable to do that.
    plz suggest me what to do?
    DATA: BEGIN OF del_grp_data occurs 0,
            vbeln like vbap-vbeln,  " Sales document
            grkor like vbap-grkor,  " Delivery group
            netwr like vbap-netwr, "net value
            posnr like vbap-posnr,  " Sales document item
             End OF del_grp_data.
    SELECT vbeln grkor pstyv netwr
        posnr
       FROM   vbap
        INTO corresponding fields of  TABLE del_grp_data
        FOR ALL ENTRIES IN orders_vbeln
        WHERE vbeln eq orders_vbeln-vbeln.
    loop at del_grp_data.
    collect ord_grp_data .
    endloop.
    Regards,
    Amit.

    Basic form
    COLLECT [wa INTO] itab.
    Addition:
    ... SORTED BY f
    Cannot Use Short Forms in Line Operations.
    Effect
    COLLECT allows you to create unique or summarized datasets. The system first tries to find a table entry corresponding to the table key. (See also Defining Keys for Internal Tables). The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area wa. The line type of itab must be flat - that is, it cannot itself contain any internal tables. All the components that do not belong to the key must be numeric types ( ABAP Numeric Types).
    If the system finds an entry, the numeric fields that are not part of the table key (see ABAPNumeric Types) are added to the sum total of the existing entries. If it does not find an entry, the system creates a new entry instead.
    The way in which the system finds the entries depends on the type of the internal table:
    STANDARD TABLE:
    The system creates a temporary hash administration for the table to find the entries. This means that the runtime required to find them does not depend on the number of table entries. The administration is temporary, since it is invalidated by operations like DELETE, INSERT, MODIFY, SORT, ...). A subsequent COLLECT is then no longer independent of the table size, because the system has to use a linear search to find entries. For this reason, you should only use COLLECT to fill standard tables. U
    SORTED TABLE:
    The system uses a binary search to find the entries. There is a logarithmic relationship between the number of table entries and the search time.
    HASHED TABLE:
    The system uses the internal hash administration of the table to find records. Since (unlike standard tables), this remains intact even after table modification operations, the search time is always dependent on the number of table entries.
    For standard tables and SORTED TABLEs, the system field SY-TABIX contains the number of the existing or newly-added table entry after the APPEND. With HASHED TABLEs, SY-TABIX is set to 0.
    Notes
    COLLECT allows you to create a unique or summarized dataset, and you should only use it when this is necessary. If neither of these characteristics are required, or where the nature of the table in the application means that it is impossible for duplicate entries to occur, you should use INSERT [wa INTO] TABLE itab instead of COLLECT. If you do need the table to be unique or summarized, COLLECT is the most efficient way to achieve it.
    If you use COLLECT with a work area, the work area must be compatible with the line type of the internal table.
    If you edit a standard table using COLLECT, you should only use the COLLECT or MODIFY ... TRANSPORTING f1 f2 ... statements (where none of f1, f2, ... may be in the key) enthalten sein). Only then can you be sure that:
    -The internal table actually is unique or summarized
    -COLLECT runs efficiently. The check whether the dataset
    already contains an entry with the same key has a constant
    search time (hash procedure).
    If you use any other table modification statements, the check for entries in the dataset with the same key can only run using a linear search (and will accordingly take longer). You can use the function module ABL_TABLE_HASH_STATE to test whether the COLLECT has a constant or linear search time for a given standard table.
    Example
    Summarized sales figures by company:
    TYPES: BEGIN OF COMPANY,
            NAME(20) TYPE C,
            SALES    TYPE I,
          END OF COMPANY.
    DATA: COMP    TYPE COMPANY,
          COMPTAB TYPE HASHED TABLE OF COMPANY
                                    WITH UNIQUE KEY NAME.
    COMP-NAME = 'Duck'.  COMP-SALES = 10. COLLECT COMP INTO COMPTAB.
    COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB.
    COMP-NAME = 'Duck'.  COMP-SALES = 30. COLLECT COMP INTO COMPTAB.
    Table COMPTAB now has the following contents:
               NAME    | SALES
              Duck    |   40
              Tiger   |   20
    Addition
    ... SORTED BY f
    Effect
    COLLECT ... SORTED BY f is obsolete, and should no longer be used. It only applies to standard tables, and has the same function as APPEND ... SORTED BY f, which you should use instead. (See also Obsolete Language Elements).
    Note
    Performance:
    Avoid unnecessary assignments to the header line when using internal tables with a header line. Whenever possible, use statements that have an explicit work area.
    For example, " APPEND wa TO itab." is approximately twice as fast as " itab = wa. APPEND itab.". The same applies to COLLECT and INSERT.
    The runtime of a COLLECT increases with the width of the table key and the number of numeric fields whose contents are summated.
    Note
    Non-Catchable Exceptions:
    COLLECT_OVERFLOW: Overflow in an integer field during addition
    COLLECT_OVERFLOW_TYPE_P: Overflow in a type P field during addition.
    TABLE_COLLECT_CHAR_IN_FUNCTION: COLLECT on a non-numeric field.
    Related
    APPEND, WRITE ... TO, MODIFY, INSERT
    Additional help
    Inserting SummarizedTable Lines

Maybe you are looking for

  • "Photoshop" Waiting for Bridge CS6... on a MAC BOOK PRO help

        I have a Mac book Pro, with retina display running on OS X version 10.9.4. and I cannot get mini-bridge to run.  Adobe first told me the problem was with Apple, I contacted Apple and the problem was not with them.  Adobe told me the problem was w

  • Mapping debug - target node not being created

    Hi Gurus, I have an issue in my mapping. Let's say I have a source structure: ><body> >  <maintag> >    <value>1</value> >  </maintag> >  <maintag> >    <value>2</value> >  </maintag> ><body> I need to map maintag->target node but only in case if val

  • How much data is actually sent to the client?

    Hi, On the web application stuff I'm doing, I have a somewhat complex class structure for my objects. For example: I have a Project class and a Concept class, and technically you can access a Project object's assocated Concept object, but to do so yo

  • Still the Blog is visible,when get removal message

    Hi Moderator, yesterday i have reported about a blog post , stating that it has not any new values that will reflect to the community to get something new, after that i got a moderator message as shown in the screen shot , but still i can see this bl

  • My Iphone 4 is downloading my entire outlook inbox including "read" messages.

    My new Iphone is downloading from my outlook account.  But it is downloading my entire inbox (even read messages) how do I stop it and just download messages from today forward.  I have over 6000 "read" messages in my inbox.  Do i have to delete each