Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Which is more efficient For vs FORALL

Re: Which is more efficient For vs FORALL

From: Igor Neyman <ineyman_at_perceptron.com>
Date: Mon, 04 Feb 2002 11:14:44 -0800
Message-ID: <F001.004053BF.20020204111232@fatcity.com>

Rick,

I'd suggest:

SELECT <table1_field1_name>, <table1_field2_name> BULK COLLECT INTO v_array, c_array

    FROM <table1_name>
    WHERE ... then do 'for all':

FORALL nJ IN 1..v_array.COUNT

    UPDATE <table2_name>
    SET <table2_field1_name> = v_array(nJ)     WHERE <table2_field2_name> = c_array(nJ);

Igor Neyman, OCP DBA
ineyman_at_perceptron.com

> Hi DBAs
>
> Here are 2 scenario's. Which one is more efficient?
> Assume 10,000 records to update
>
> Thanks
> Rick
>
> 1. For each record update field1 with subsquery
> Assume cursor is declared
> FOR cursor_rec IN new_patients_cur LOOP
> UPDATE <table>
> SET field1 =
> (SELECT value
> FROM table
> WHERE ...)
> WHERE ....
> END LOOP;
>
> 2. For each record load nested table with data then update all records
with
> a single FORALL
>
> t_type1 IS TABLE OF table1.field1%TYPE;
> v_type1 t_type1(10000);
>
> /* Load the PLSQL nested table */
> FOR cursor_rec IN new_patients_cur LOOP
> v_loop_ctr := v_loop_ctr + 1;
> v_type1 := cursor_rec.field1;
> END LOOP;
>
> /* INSERT all 10,000 records with on context switch */
> FORALL v_count IN 1...10000)
> UPDATE field1 = v_type1(v_count);
>
>
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author:
> INET: Rick_Cale_at_teamhealth.com
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Igor Neyman
  INET: ineyman_at_perceptron.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Mon Feb 04 2002 - 13:14:44 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US