bulk collect line IDs

Hello world

I'm doing a big collect of the row ID in order to group my lines by pieces and then dealt with separately.

My problem at present is that I can't seem to know what to put in my definition of type for the line id then it will work.

the only way I get it to compile, I know it's wrong, and when I run it I get:

ORA-21700: object does not exist or is marked for deletion

I decided to ask here after that I went through this two positions but did not find my answer, or at least I think not.

ORA-21700: object does not exist or is marked for deletion - nested table

collect/rowid problem in bulk

my code is something like this:

  type    t_rid_tab                               is table of rowid;

      with migr as (
        select rowid                        rid
              ,ceil(rownum/i_chunk_size)   chunk_nr
        from TABLE m
      )
      select cast(collect(rid) as t_rid_tab)  rid_tab
      bulk collect
      into   l_row_id_tab
      from   migr
      group by chunk_nr
      ;

to be honest the code part is not the biggest problem, eventually can be changed until it works.

My two questions are:

1 - Why do a compilation error data type in this code for my t_rid_tab (PLS-00531: not supported type in a type VARRAY of the TABLE: "ROWID")

2 even just to execute the query in my sql developer does not work with something simple like: does not work, can someone just give me a first pointer?

I am trying to run a small debug program to see what I get in my big, but I can't make it work... should be something pretty basic-no?

I can't seem to run until I understand how can I declare my table of rowid type

declare
    l_tab t_rid_tab;
begin
      with migr as (
        select rowid                        rid
              ,ceil(rownum/100)   chunk_nr
        from   TABLE m
      )
      select cast(collect(rid) as rowid)  rid_tab
      bulk collect
      into   l_tab
      from   migr
      group by chunk_nr
      ;

        debug(l_tab(1));
     
end;
/

Thank you

It is more clear what you want now and why you want it!

create table test_cmg (column number (5));

/

insert into test_cmg

Select the level

of the double

connect by level<>

/

Create the type TROWIDCharTable is table of the varchar2 (100)

/

declare

type of TRec's record)

Whole piece,

RIDTable TROWIDCharTable

);

type TRecTable is table of the TRec;

vRecTable TRecTable;

Start

with Rahul like)

Select ceil(rownum/100) chunk_nr,

Cast (cost vires (ROWIDTOCHAR (rowid)) as TROWIDCharTable) ridtable

of test_cmg m

ceil(rownum/100) group

)

Select chunk_nr, ridtable

bulk collect into vRecTable

of Rahul.

-A loop around your data...

end;

/

Tags: Database

Similar Questions

  • Bulk collect treats all lines not containing the LIMIT clause.

    Hi all

    I was referring the Oracle Site for COLLECTION in BULK.

    http://www.Oracle.com/technology/oramag/Oracle/08-Mar/o28plsql.html

    In the following code, I found and I ran the same.

    I just want to know why motor Pl - SQL is not processing or recital 27 last lines when I use % NOTFOUND cursot attribute.


    PROCEDURE process_all_rows_foi_test (p_limit PLS_INTEGER DEFAULT 100)
    IS
       CURSOR c1
       IS
          SELECT *
            FROM all_objects
           WHERE ROWNUM <= 227;
    
       TYPE foi_rec IS TABLE OF c1%ROWTYPE
          INDEX BY PLS_INTEGER;
    
       v_foi_rec   foi_rec;
       v_number    NUMBER  := 1;
    BEGIN
       OPEN c1;
    
       LOOP
          FETCH c1
          BULK COLLECT INTO v_foi_rec LIMIT p_limit;
    
          EXIT WHEN v_foi_rec.COUNT = 0;--------EXIT WHEN c1%NOTFOUND;--->Here is the issue
          DBMS_OUTPUT.put_line (v_number);
          v_number := v_number + 1;
       END LOOP;
    
       CLOSE c1;
    END;
    Please guide me on this.

    Thank you
    Arun

    % NOTFOUND will have the value TRUE when it gets below the limit

    (it is documented)

    But your workaround works fine

    SQL> declare
      2     CURSOR c1
      3     IS
      4        SELECT *
      5          FROM all_objects
      6         WHERE ROWNUM <= 227;
      7
      8     TYPE foi_rec IS TABLE OF c1%ROWTYPE
      9        INDEX BY PLS_INTEGER;
     10
     11     v_foi_rec   foi_rec;
     12     v_number    NUMBER  := 1;
     13  BEGIN
     14     OPEN c1;
     15
     16     LOOP
     17        FETCH c1
     18        BULK COLLECT INTO v_foi_rec LIMIT 100; --p_limit;
     19
     20        EXIT WHEN v_foi_rec.COUNT = 0;--------EXIT WHEN c1%NOTFOUND;--->Here is the issue
     21        DBMS_OUTPUT.put_line (v_foi_rec.count);
     22        v_number := v_number + 1;
     23     END LOOP;
     24
     25     CLOSE c1;
     26  END;
     27  /
    100
    100
    27
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    Another option would be to place the EXIT right before your END LOOP;

  • Subsequentes IN BULK COLLECT in the collection truncates existing lines?

    T_tab_prds TYPE IS the % TYPE my_cursor TABLE;

    v_tab_prds t_tab_prds;

    OPEN my_cursor;
    Fetch the my_cursor COLLECT in BULK IN v_tab_prds;
    NARROW My_cursor

    another session can change/remove lines

    OPEN my_cursor;
    Fetch the my_cursor COLLECT in BULK IN v_tab_prds; -V_tab_prds VA be zapped before second READING or lines will be mixed? I have to
    -manually remove lines of v_tab_prds before the second EXTRACTION?
    NARROW My_cursor

    I answered Yes initially "later in BULK collect into collection truncate existing lines. Then I noticed "another session can change or remove rows" in your message. The collection is in the object memory with PL/SQL unit scope, it is stated in which is obviously not covered by sessions. So even if the collection belongs to the same unit of PL/SQL (package, SP, etc.) in different sessions, it's a different chunk of memory. So the final answer is:

    Later in BULK COLLECT in the collection to the breast within the same instance of PL/SQL unit truncates existing lines. But obviously subsequent TO BULK COLLECT into the collection in another session won't affect collection in the first session.

    SY.

    Published by: Solomon Yakobson, October 13, 2009 14:20

  • Using bulk collect into with assistance from the limit to avoid the TEMP tablespace error run out?

    Hi all

    I want to know if using bulk collect into limit will help to avoid the TEMP tablespace error run out.

    We use Oracle 11 g R1.

    I am assigned to a task of creating journal facilitated for all tables in a query of the APEX.

    I create procedures to execute some sql statements to create a DEC (Create table select), and then fires on these tables.

    We have about three tables with more than 26 million records.

    It seems very well running until we reached a table with more than 15 million record, we got an error says that Miss tablespace TEMP.

    I googled on this topic and retrieve the tips:

    Use NO LOG

    Parallel use

    BULK COLLECT INTO limited

    However, the questions for those above usually short-term memory rather than running out of TEMPORARY tablespace.

    I'm just a junior developer and does not have dealed with table more than 10 million documents at a time like this before.

    The database support is outsourced. If we try to keep it as minimal contact with the DBA as possible. My Manager asked me to find a solution without asking the administrator to extend the TEMP tablespace.

    I wrote a few BULK COLLECT INTO to insert about 300,000 like once on the development environment. It seems.

    But the code works only against a 000 4000 table of records. I am trying to add more data into the Test table, but yet again, we lack the tablespace on DEV (this time, it's a step a TEMP data)

    I'll give it a go against the table of 26 million records on the Production of this weekend. I just want to know if it is worth trying.

    Thanks for reading this.

    Ann

    I really need check that you did not have the sizes of huge line (like several K by rank), they are not too bad at all, which is good!

    A good rule of thumb to maximize the amount of limit clause, is to see how much memory you can afford to consume in the PGA (to avoid the number of calls to the extraction and forall section and therefore the context switches) and adjust the limit to be as close to that amount as possible.

    Use the routines below to check at what threshold value would be better suited for your system because it depends on your memory allocation and CPU consumption.  Flexibility, based on your limits of PGA, as lines of length vary, but this method will get a good order of magnitude.

    CREATE OR REPLACE PROCEDURE show_pga_memory (context_in IN VARCHAR2 DEFAULT NULL)

    IS

    l_memory NUMBER;

    BEGIN

    SELECT st. VALUE

    IN l_memory

    SYS.v_$ session se, SYS.v_$ sesstat st, SYS.v_$ statname nm

    WHERE se.audsid = USERENV ('SESSIONID')

    AND st.statistic # nm.statistic = #.

    AND themselves. SID = st. SID

    AND nm.NAME = 'pga session in memory. "

    Dbms_output.put_line (CASE

    WHEN context_in IS NULL

    THEN NULL

    ELSE context_in | ' - '

    END

    || 'Used in the session PGA memory ='

    || To_char (l_memory)

    );

    END show_pga_memory;

    DECLARE

    PROCEDURE fetch_all_rows (limit_in IN PLS_INTEGER)

    IS

    CURSOR source_cur

    IS

    SELECT *.

    FROM YOUR_TABLE;

    TYPE source_aat IS TABLE OF source_cur % ROWTYPE

    INDEX BY PLS_INTEGER;

    l_source source_aat;

    l_start PLS_INTEGER;

    l_end PLS_INTEGER;

    BEGIN

    DBMS_SESSION.free_unused_user_memory;

    show_pga_memory (limit_in |) "- BEFORE"); "."

    l_start: = DBMS_UTILITY.get_cpu_time;

    OPEN source_cur.

    LOOP

    EXTRACTION source_cur

    LOOSE COLLECTION l_source LIMITED limit_in;

    WHEN l_source EXIT. COUNT = 0;

    END LOOP;

    CLOSE Source_cur;

    l_end: = DBMS_UTILITY.get_cpu_time;

    Dbms_output.put_line (' elapsed time CPU for limit of ')

    || limit_in

    || ' = '

    || To_char (l_end - l_start)

    );

    show_pga_memory (limit_in |) "- AFTER");

    END fetch_all_rows;

    BEGIN

    fetch_all_rows (20000);

    fetch_all_rows (40000);

    fetch_all_rows (60000);

    fetch_all_rows (80000);

    fetch_all_rows (100000);

    fetch_all_rows (150000);

    fetch_all_rows (250000);

    -etc.

    END;

  • Bulk collect using some different column insert a table

    Hi all

    I gave an example of emp table in my original 100 million table record are I need to change group (IE deptno) 10 to 20 copy the same records

    about these codes, I get exception

    ORA-06550: line 11, column 53:

    PLS-00386: concordance that is 'EMP_TAB' between FETCH cursor and IN variables of type

    can help me please for these

    declare

    type row_tab is table emp % rowtype

    INDEX BY PLS_INTEGER;

    emp_tab row_tab;

    cursor cur_emp is select ENAME, 20 DEPTNO, HIREDATE, emp COMM EMPNO;

    Start

    Open cur_emp;

    loop

    Cur_emp fetch bulk collect in the limit emp_tab 2000;

    ForAll i in 1.emp_tab. COUNTY

    Insert / * + APPEND * / into emp (EMPNO, ENAME, DEPTNO, HIREDATE, COMM)

    values (emp_tab (i). EMPNO, emp_tab (i). Ename, emp_tab (i). DEPTNO, emp_tab (i). HIREDATE, emp_tab (i). COMM.) ;

    When the output cur_emp % notfound;

    END LOOP;

    close cur_emp;

    end;

    /

    Thank you

    VSM

    I use the user define the type of record to over come error

    declare

    type emp_rt is record (empno, ename emp.ename%type,deptno NUMBER (2) emp.empno%type, hiredate emp.hiredate%type,comm emp.comm%type);

    TYPE row_type IS the emp_rt INDEX TABLE OF pls_integer;

    emp_tab row_type;

    cursor cur_emp is select empno, ename, 20 deptno, hiredate, comm from emp where deptno = 10;

    Start

    Open cur_emp;

    loop

    Cur_emp fetch bulk collect in the emp_tab limit 2;

    ForAll i in 1.emp_tab. COUNTY

    Insert / * + APPEND * / into EMP (EMPNO, ENAME, DEPTNO, HIREDATE, COMM)

    values (emp_tab (i). EMPNO, emp_tab (i). ENAME, emp_tab (i). DEPTNO, emp_tab (i). HIREDATE, emp_tab (i). COMM.)

    ;

    When the output cur_emp % notfound;

    END LOOP;

    close cur_emp;

    end;

    /

    records are successful inserted, I do not know is not the right approach for 100 million documents?

    Thank you

    VM

  • Get 'not enough values error' in bulk collect

    I want to insert all the rows in the employees table in the tmp table which has the structure.

    Purpose: Try just feature fired block to create a return to the top of a table.

    Problem: My code is to not "enough of values" error please report if mistaken.

    structure of the employees table:

    SQL > desc employee;

    Name                                      Null?    Type

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

    EMPLOYEE_ID NOT NULL NUMBER (6)

    FIRST NAME VARCHAR2 (20)

    LAST_NAME NOT NULL VARCHAR2 (25)

    EMAIL NOT NULL VARCHAR2 (25)

    PHONE_NUMBER VARCHAR2 (20)

    HIRE_DATE NOT NULL DATE

    JOB_ID NOT NULL VARCHAR2 (10)

    SALARY NUMBER (8.2)

    COMMISSION_PCT NUMBER (2.2)

    MANAGER_ID NUMBER (6)

    DEPARTMENT_ID NUMBER 4

    tmp table structure:

    SQL > tmp desc;

    Name                                      Null?    Type

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

    EMPLOYE_ID NUMBER (6)

    FIRST NAME VARCHAR2 (20)

    LAST_NAME NOT NULL VARCHAR2 (25)

    EMAIL NOT NULL VARCHAR2 (25)

    PHONE_NUMBER VARCHAR2 (20)

    HIRE_DATE NOT NULL DATE

    JOB_ID NOT NULL VARCHAR2 (10)

    SALARY NUMBER (8.2)

    COMMISSION_PCT NUMBER (2.2)

    MANAGER_ID NUMBER (6)

    DEPARTMENT_ID NUMBER 4

    SQL > select * from tmp;

    no selected line

    Code:

    declare

    type rec is the employee table % rowtype

    index by pls_integer;

    a rec;

    Start

    Select * bulk collect in a

    employees;

    ForAll i in a.first... a.Last

    Insert into tmp values (a (i));

    end;

    /

    Result:

    SQL > declare

    2

    3 type rec is the employee table % rowtype

    4 index of pls_integer;

    5 a rec;

    6

    7. start

    8 remove tmp;

    9 select * bulk collect in a

    10 employees;

    11 ForAll i in a.first... a.Last

    12 insert into tmp values (a (i));

    13 end;

    14.

    Insert into tmp values (a (i));

    *

    ERROR on line 12:

    ORA-06550: line 12, column 13:

    PL/SQL: ORA-00947: not enough values

    ORA-06550: line 12, column 1:

    PL/SQL: SQL statement ignored

    Remove parentheses

    insert into tmp values a(i);
    

    or call the individual columns

    insert into tmp( employee_id, first_name, ... )
     values( a(i).employee_id, a(i).first_name, ... );
    

    Justin

  • PLS-00201: identifier 'i' must be declared when using BULK COLLECT with FORALL to insert data in 2 tables?

    iHi.

    Declare
       cursor c_1
       is
        select col1,col2,col3,col4
        from table1
    
    
       type t_type is table of c_1%rowtype index by binary_integer;
       v_data t_type;
    BEGIN
       OPEN c_1;
       LOOP
          FETCH c_1 BULK COLLECT INTO v_data LIMIT 200;
          EXIT WHEN v_data.COUNT = 0;
          FORALL i IN v_data.FIRST .. v_data.LAST
             INSERT INTO xxc_table
               (col1,
                col3,
                col4
               )
                SELECT v_data (i).col1,
                       v_data (i).col3,
                       v_data (i).col4
                  FROM DUAL
                 WHERE NOT EXISTS
                              (SELECT 1
                                 FROM xxc_table a
                                WHERE col1=col1
                                      .....
                              );
                         --commit;
             INSERT INTO xxc_table1
               (col1,
               col2,
              col3,
              col4
               )
                SELECT v_data (i).col1,
                       v_data (i).col2,
                       v_data (i).col3,
                       'Y'
                  FROM DUAL
                 WHERE NOT EXISTS
                              (SELECT 1
                                 FROM xxc_table1 a
                                WHERE col1=col1
          .....
         );
    
    
           --exit when c_1%notfound;
       END LOOP;
       CLOSE c_1;
       commit;
    END;
    
    
    
    
    
    
    
    

    I get 40/28-PLS-00201: identifier 'I' must be declared what the problem in the above code please help me and I have lakhs of data

    Thank you

    Post edited by: Rajesh123 I changed IDX

    Post edited by: Rajesh123 changed t_type c_1 in Fetch

    But by using a SET of INSERT to insert into two tables at once in the same query would do the job without any collection of bulk of PL and avoid to query two times too.

    for example, as a single INSERT...

    SQL > create table table1 as
    2. Select 1 as col1, col2 of 1, 1 as col3, 1 as col4 Union double all the
    3 select 2,2,2,2 of all the double union
    4 Select 3,3,3,3 Union double all the
    5 Select 4,4,4,4 of all the double union
    6 select 5,5,5,5 of all the double union
    7 select 6,6,6,6 of all the double union
    8 select 7,7,7,7 of all the double union
    9 select 8,8,8,8 of all the double union
    10. Select 9,9,9,9 to the Union double all the
    11. Select double 10,10,10,10
    12.

    Table created.

    SQL > create table xxc_table like
    2. Select 1 as col1, col3 2, 3 as col4 Union double all the
    3. Select the 3, 4, 5 Union double all the
    4. Select the 5, 6, 7 double
    5.

    Table created.

    SQL > create table xxc_table1 like
    2. Select 3 as col1, col2, col3, 5 4 "n" as col4 Union double all the
    3. Select the 6, 7, 8, double "n"
    4.

    Table created.

    SQL > insert all
    2 when the xt_insert is null then
    3 in xxc_table (col1, col3, col4)
    4 values (col1, col3, col4)
    5 when the xt1_insert is null then
    6 in xxc_table1 (col1, col2, col3, col4)
    7 values (col1, col2, col3, 'Y')
    8. Select t1.col1 t1.col2, t1.col3, t1.col4
    9, xt.col1 as xt_insert
    10, xt1.col1 as xt1_insert
    11 from table1 t1
    12 left join external xxc_table xt (t1.col1 = xt.col1)
    13 left xt1 xxc_table1 outer join (t1.col1 = xt1.col1)
    14.

    15 rows created.

    SQL > select * from xxc_table by 1.
    COL1 COL3 COL4
    ---------- ---------- ----------
    1          2          3
    2          2          2
    3          4          5
    4          4          4
    5          6          7
    6          6          6
    7          7          7
    8          8          8
    9          9          9
    10-10-10

    10 selected lines.

    SQL > select * from xxc_table1 by 1.

    COL1 COL2 COL3 C
    ---------- ---------- ---------- -
    1          1          1 Y
    2          2          2 Y
    3          4          5 N
    4          4          4 Y
    5          5          5 Y
    6          7          8 N
    7          7          7 Y
    8          8          8 Y
    9          9          9 Y
    10-10-10

    10 selected lines.

    SQL >

  • Bulk Collect and Millions of records.

    Hey guys,.

    I did experiences autour with big collect in GR 11, 2...

    I have millioms of files with very large tables.

    In fact, my question is this. How do you use bulk collect when you have millions of records?

    Everytime I try to use it for bulk collect into, I have run out of memory.

    So should I stick with the SQL engine when it comes to manipulate millions

    folders? Is maninly bulk collect for insert, updates to use for applications?

    Summer banging my head for awhile with it. Can a Pl/SQL pro if you please

    Give me some advice on this?

    In most cases SQL insert/update engine will end up more quickly then PL/SQL select + Insert/Update. Normally, you would use PL/SQL, if there is a complex logic that is based on calculations of several rows that can be easily made in SQL. If you must use BULK COLLECT many or / and wide lines, you can divide it into segments using LIMIT.

    SY.

  • On bulk collect forall vs fusion simple statement

    I understand that a single DML statement is better that use bulk collect to have all the intermediary undertakes. My only concern is that if I load a large amount of data as a record 100 million records in a 800 million table with foreign keys and indexes and the session is killed, the cancellation may take some time which is not acceptable. Using bulk collect forall with interval of validations is slower than a declaration unique fusion straight, but in the case of dead session, the restore time will be not too bad and a reload of the not yet committed data will be not as bad. For the design of a load of recoverable data which may not be affected as badly, is in bulk collect + for all the right approach?

    So if I chunk it upward in 50 lines, the child table must be loaded to its matching when records the parent table loaded and validate them.

    ... and then create a procedure that takes care of the parent AND child data at the same time.

    SQL for DBMS_PARALLEL_EXECUTE would be:

    "start load_parent_and_child (: start_id,: end_id); end; »

    PS - you don't want to run ECD and DML PARALLEL at the same time...

    MK

  • Bulk collect using Order by

    Greeetings,

    Version:-8i

    {code}

    Select * bulk collect into collection_test where d_id = 4 order by e_id;

    {code}

    Can the above code collect data in the order defined by our query? or he will seek lines in an order any.

    Thanks in advance...

    Yes, he'll get it sorted. For more information, see this link http://www.oracle-developer.net/display.php?id=428

  • Bulk collect with sequence Nextval

    Hello


    Oracle Database 10 g Enterprise Edition Release 10.2.0.4.0 - 64 bit


    Had a doubt about the collection in bulk with nextval sequence. You need to update a table with a sequence of Nextval.

    where should I place select below in the proc is this before or after the loop


    < font color = "red" > SELECT prop_id_s.nextval INTO v_prop_id FROM dual; < / make >
    CREATE OR REPLACE PROCEDURE  (state IN varchar2)
    AS
       
       CURSOR get_all
       IS
          SELECT                              /*+ parallel (A, 8) */
                A .ROWID
                from Loads A WHERE A.Prop_id IS NULL;
    
       TYPE b_ROWID
       IS
          TABLE OF ROWID
             INDEX BY BINARY_INTEGER;
    
       
       lns_rowid          b_ROWID;
    BEGIN
    
    
       OPEN Get_all;
    
       LOOP
          FETCH get_all BULK COLLECT INTO   lns_rowid LIMIT 10000;
    
          FORALL I IN 1 .. lns_rowid.COUNT
             UPDATE   loads a
                SET   a.prop_id= v_prop_id (I)
              WHERE   A.ROWID = lns_rowid (I) AND a.prop_id IS NULL;
    
          
          COMMIT;
          EXIT WHEN get_all%NOTFOUND;
       END LOOP;
    
       
    
       CLOSE Get_all;
    END;
    /
    Published by: 960736 on January 23, 2013 12:51

    Hello

    It depends on what results you want. All updated rows would take the same value, or should all get unique values?

    Whatever it is, you don't need the sliders and loop. Just a simple UPDATE statement.

    If each line requires a unique value of the sequence, then

    UPDATE  loads
    SET     prop_id     = prod_id_s.NEXTVAL
    WHERE     prop_id     IS NULL
    ;
    

    If all the lines that have a need to the same value null, then:

    SELECT     prod_id_s.nextval
    INTO     v_prop_id
    FROM     dual;
    
    UPDATE  loads
    SET     prop_id     = v_prop_id
    WHERE     prop_id     IS NULL
    ;
    

    Don't forget to declare v_prop_id as a NUMBER.

    I hope that answers your question.
    If not, post a small example of data (instructions CREATE and INSERT, only relevant columns) for all the tables and the involved sequences and also publish outcomes from these data.
    If you ask on a DML statement, such as UPDATE, the sample data will be the content of the or the tables before the DML, and the results will be the State of the or the tables changed when it's all over.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • bulk collect into with limit

    Hi all
    I was reading [http://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:5918938803188] of Tom Kyte site on bulk collect within limits. The code uses the % notfound cursor to exit the recovery loop. What I do in this situation is using exists, method of table rather than cursor attribute.
    create or replace procedure p1 is
    type num_list_type is table of number index by pls_integer;
    num_list num_list_type;
    
    cursor c1 is select temp from test;
    
    begin
    open c1;
    loop
      fetch c1 bulk collect into num_list limit 2;
      if num_list.exists(1)=false then
        exit;
      end if;
      for i in num_list.first..num_list.last 
      loop
        dbms_output.put_line(num_list(i));
      END LOOP;
    end loop;
    
    end;
    Since when I do this:
    exit wen c1%notfound  
    It will close when the cursor retrieves only less than the limit, leaving a few rows. If the code works properly.
    Question:
    1. is the Exit statement properly, is there another way (I'm a little skeptical because I'm not using the cursor)?
    2 How to decide on the size limit based on what we have in the hardware settings and oracle? All of the guidelines?
    3 - is the best practice when it comes with the cursor and several lines that still use bulk collect into?

    Best regards
    Val

    Valerie Debonair wrote:
    Hi all
    I was reading [http://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:5918938803188] of Tom Kyte site on bulk collect within limits. The code uses the % notfound cursor to exit the recovery loop. What I do in this situation is using exists, method of table rather than cursor attribute.

    create or replace procedure p1 is
    type num_list_type is table of number index by pls_integer;
    num_list num_list_type;
    
    cursor c1 is select temp from test;
    
    begin
    open c1;
    loop
    fetch c1 bulk collect into num_list limit 2;
    if num_list.exists(1)=false then
    exit;
    end if;
    for i in num_list.first..num_list.last
    loop
    dbms_output.put_line(num_list(i));
    END LOOP;
    end loop;
    
    end;
    

    Since when I do this:

    exit wen c1%notfound  
    

    It will close when the cursor retrieves only less than the limit, leaving a few rows. If the code works properly.
    Question:
    1. is the Exit statement properly, is there another way (I'm a little skeptical because I'm not using the cursor)?
    2 How to decide on the size limit based on what we have in the hardware settings and oracle? All of the guidelines?
    3 - is the best practice when it comes with the cursor and several lines that still use bulk collect into?

    Best regards
    Val

    Hello

    1. Yes, in above code statement EXIT will work correctly. The other way is % NOTFOUND CURSOR attribute usage.
    2. There is no precise way to decide the size limit.
    3 depends on number of records. If you have a lot of records always use LIMIT that improves performance.

    After reading the link that was posted by Blu, I am to edit this post.

    1. do not use CURSOR attribute when you use collections within a cursor. Use methods of collection such as COUNT or EXIST etc.

    @Blu,

    Thanks much for the link.

    Thank you
    Suri

    Published by: Suri on January 26, 2012 20:38

  • Bulk collect and inserts

    Hello, I'm quite new to PLSQL and need some advice...

    I have several procedures that work well and do what I want to do.

    My question is, am I'm going in the right direction or would you all another way? If there were millions of records that would be the fastest way?

    All comments/comments would be greatly appreciated.

    Procedure 1:

    declare

    type membera is the table of the gym_members_payment_details.member_id%type;
    payment type is the gym_members_payment_details.payment_plan%type table;
    type date_payment_recieved is table of the gym_members_payment_details.date_payment_recieved%type;

    v_member membera;
    v_payment payment;
    v_date_payment_recieved date_payment_recieved;
    date of v_date_due;

    cursor c1 is select member_id, payment_plan, gym_members_payment_details date_payment_recieved;

    Start

    Open c1;

    collect the fetch c1 into bulk in v_member, v_payment, v_date_payment_recieved;

    Close c1;

    I'm in v_member.first... v_member. Last

    loop



    If v_payment (i) = "daily" then update gym_members_payment_details set date_payment_due = v_date_payment_recieved (i) where member_id = v_member (i);
    elsif v_payment (i) is "weekly" then update gym_members_payment_details set date_payment_due = v_date_payment_recieved (i) + 7 where member_id = v_member (i);.
    elsif v_payment (i) is "monthly" then update gym_members_payment_details set date_payment_due = v_date_payment_recieved (i) + 30 where member_id = v_member (i);.
    end if;


    end loop;

    end;

    Procedure 2

    declare

    Bench type is the gym_members_lifts.bench_kg%type table;
    squat type is the gym_members_lifts.squat_kg%type table;
    type of death is the gym_members_lifts.deadlift_kg%type table;
    type membera is the table of the gym_members_lifts.member_id%type;
    type bodyw is table of the gym_members_lifts.body_weight_kg%type;

    V_bench bench;
    v_squat squat;
    v_dead dead;
    v_body bodyw;
    number of v_total;
    number of v_ratio;
    v_member membera;

    cursor c1 is select bench_kg, squat_kg, deadlift_kg, member_id, gym_members_lifts body_weight_kg;


    Start

    / * bulk collect * /.

    Open c1;
    collect the fetch c1 into loose in v_bench, v_squat, v_dead, v_member, v_body;

    Close c1;

    / * Update gym_members elevators table with combined lifts and body weight to lift rates rounded to 2 places * /.

    I'm in v_member.first... v_member. Last
    loop


    v_total: = v_bench (i) + v_squat (i) + v_dead (i);
    Update gym_members_lifts set total_lift_kg = v_total where v_member (i) = member_id;
    v_ratio: = round ((v_bench (i) + v_squat (i) + v_dead (i)) / v_body (i), 2);
    Update gym_members_lifts set bodyweight_strength_ratio = v_ratio where v_member (i) = member_id;


    end loop;

    end;

    Published by: 882839 on November 29, 2011 14:25

    882839 wrote:

    My question is, am I'm heading in the right direction

    It depends on the type of film you make. Your direction may work for a movie comedy or a disaster, perhaps.

    or you would do any differently?

    Completely different.

    If there were millions of records that would be the fastest way?

    The fastest way is to do the absolute minimum of work to achieve the desired results.

    You do not have to shake the SQL data in a detour by the PL/SQL engine. Bulk processing is slow.

    While processing bulk is faster than 'normal' treatment - but for one reason only. Reduction in switching between SQL and PL/SQL engines.

    The cost of treatment in bulk increases PGA - using more private process memory (the most expensive type of memory of the server). More extraction in bulk, the PGA TOUR more is consumed. Very large bed can crash the Oracle db server to the risk of exhausting all the free server memory and give rise to serious swap space trashing.

    And that's all. Treatment in bulk does not run the SQL cursor all faster. Treatment in bulk does not reduce the IO very expensive and slow. There is no that activate more lines have to be extracted from the SQL cursor by context switch and thus reduce the change of context.

    In this regard, what is optimal? No change at all in context.

    How is this achieved? No treatment in bulk. It is obtained by eliminating the need to change entirely in context. This means no PL/SQL. This means that SQL.

    Optimize SQL. Minimize the PL/SQL.

    Do not use the PL/SQL engine to do the things that the SQL engine is perfectly capable of doing.

    Simplistic example in the sense of your first PL/SQL procedure:

    SQL> create table foo( id number, payment varchar2(1), due date );
    
    Table created.
    
    SQL>
    SQL> insert into foo select level, 'D', null from dual connect by level <= 5;
    
    5 rows created.
    
    SQL> insert into foo select level+5, 'W', null from dual connect by level <= 5;
    
    5 rows created.
    
    SQL>
    SQL> update     foo
      2  set        due = (
      3                  case
      4                          when payment = 'D' then trunc(sysdate+1)  --// daily payment's due date calc
      5                          when payment = 'W' then trunc(sysdate+7) --// weekly payment's due date calc
      6                  end
      7          );
    
    10 rows updated.
    
    SQL>
    SQL> select * from foo;
    
            ID P DUE
    ---------- - -------------------
             1 D 2011/12/01 00:00:00
             2 D 2011/12/01 00:00:00
             3 D 2011/12/01 00:00:00
             4 D 2011/12/01 00:00:00
             5 D 2011/12/01 00:00:00
             6 W 2011/12/07 00:00:00
             7 W 2011/12/07 00:00:00
             8 W 2011/12/07 00:00:00
             9 W 2011/12/07 00:00:00
            10 W 2011/12/07 00:00:00
    
    10 rows selected.
    
    SQL>
    
  • Using the slider for and BULK COLLECT INTO

    Hi all
    in this case we prefer to use the cursor AND the cursor with the LOOSE COLLECTION? The following contains two block this same query where used FOR the slider, the other is using COLLECT LOOSE. The task that is running better given in the existing? How do we measure performance between these two?

    I use the example of HR schema:
    declare
    l_start number;
    BEGIN
    l_start:= DBMS_UTILITY.get_time;
    dbms_lock.sleep(1);
    FOR employee IN (SELECT e.last_name, j.job_title FROM employees e,jobs j 
    where e.job_id=j.job_id and  e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name)
    LOOP
      DBMS_OUTPUT.PUT_LINE ('Name = ' || employee.last_name || ', Job = ' || employee.job_title);
    END LOOP;
    DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
    END;
    /
     
    declare
    l_start number;
    type rec_type is table of varchar2(20);
    name_rec rec_type;
    job_rec rec_type;
    begin
    l_start:= DBMS_UTILITY.get_time;
    dbms_lock.sleep(1);
    SELECT e.last_name, j.job_title bulk collect into name_rec,job_rec FROM employees e,jobs j 
    where e.job_id=j.job_id and  e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name;
    for j in name_rec.first..name_rec.last loop
      DBMS_OUTPUT.PUT_LINE ('Name = ' || name_rec(j) || ', Job = ' || job_rec(j));
    END LOOP;
    DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
    end;
    /
    In this code, I put a timestamp in each block, but they are useless, since they both launched virtually instantaneous...

    Best regards
    Val

    (1) bulk fired fresh primary use is to reduce the change of context between sql and pl sql engine.
    (2), you should always use LIMIT when it comes with bulk collect, this does not increase the load on the PGA.
    (3) and the ideal number of BOUNDARY lines is 100.

    Also if you really want to compare performance improvements between the two different approaches to sql pl try to use the package of runstats tom Kyte

    http://asktom.Oracle.com/pls/Apex/asktom.download_file?p_file=6551378329289980701

  • make exception when using BUlk collect

    Hi all

    version of DB 10 g

    I've written a procedure as below
    create or replace procedure test_proc2 is
    
    type v_emp_rec is record 
    (empno number,
    ename varchar2 (200));
    
    type v_emp_tab is table of v_emp_rec index by binary_integer;
    
    v_tab v_emp_tab;
    
    begin
    
    select empno,ename
    into v_tab(0)
    from emp
    where empno = 7369;
    
    dbms_output.put_line (v_tab(0).ename);
    
    exception 
    when no_data_found then
    dbms_output.put_line ('I am in no data found exception');
    end;
    now, I tried to perform the procedure below
    begin
    test_proc2;
    end;
    the foregoing is works well, but I want to use the functionality of collection in bulk so I use as below
    create or replace procedure test_proc2 is
    
    type v_emp_rec is record 
    (empno number,
    ename varchar2 (200));
    
    type v_emp_tab is table of v_emp_rec index by binary_integer;
    
    v_tab v_emp_tab;
    
    begin
    
    select empno,ename bulk collect
    into v_tab
    from emp
    where empno = 7369;
    
    dbms_output.put_line (v_tab(0).ename);
    
    exception 
    when no_data_found then
    dbms_output.put_line ('I am in no data found exception');
    end;
    the foregoing gives me exception, please someone can explain why it is not in the exception block.

    Thanks in advance.

    The obvious answer is because an exception no_data_found is raised.
    The question is there.

    It's either select it because there is no data where empno = 7369.

    Or is the .ename of v_tab (0), because there is no element 0. Automatic collection of indexing starts at 1.

    for example

    SQL>  declare
      2    type t1 is table of pls_integer index by pls_integer;
      3    v1 t1;
      4   begin
      5    v1(1) := 1;
      6    dbms_output.put_line(v1(0));
      7   end;
      8  /
     declare
    *
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 6
    
    SQL> 
    

    If you catch the exceptions and do not spread them properly, then hide you all information kind of useful as a line number, etc..

Maybe you are looking for

  • Cannot reduce the width of the window of Bluetooth File Exchange

    The width of the window of the Bluetooth File Exchange application can not narrowed, has increased. How can I reduce the width of the window or reset default window width? I use the Bluetooth File Exchange to browse files on a device (in my case, a W

  • III - issue of serial port Advanced Port Replicator.

    Hi, I have a few apps that do not work with usb to serial adapters. I need to know if the serial port on an advanced port replicator will not work unless the serial port was "integrated" to the computer, as they used to be in older laptops. Are the d

  • 15ce156nr: usable physical memory (ram available)

    my laptop has 6 GB of ram and boot manu specification, it shows only3.89 GB of ram is usable. .. Why?... .pls SNA...

  • SSD on Satellite L50-A-1CU

    I read the post about the problems (SATA compatibility slow with the latest firmwares); Now is the time, for me, buy an SSD, but this problem keeps me at all. No answers from Toshiba about it?It does not consider a noticeable defect?

  • Thermometer indicator has a high-water mark attribute?

    Can the indicator thermometer place a mark at the highest temperature recorded so far?  My request concerns a fluctuating temperature. I would like to draw a line at the maximum temperature achieved so far. The thermometer 'mercury' will continue to