Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Bulk Update too slow. Bulk Bind?

922573Mar 8 2012 — edited Mar 8 2012
I'm having problems using Bulk Bind in PL/SQL. Basically what I want is for a table(Component) to update its fieldvalue dependent on the Component_id and fieldname. All of these are passed in as paramaters (the type varchar2_nested_table is effectively and array of strings, one element for each update statement that needs to occur). So for instance if Component_id = 'Compid1' and fieldname = 'name' then fieldvalue should be updated to be 'new component name'.

I typed up the code below in relation to this http://www.oracle.com/technetwork/issue-archive/o14tech-plsql-l2-091157.html . The code works but is no faster than a simple loop that performs an update for every element in the IN parameters. So if the parameters have 1000 elements then 1000 update statements will be executed. I also realise I'm not using BULK COLLECT INTO but I didn't think I needed it as I don't need to select anything from the database, just update.

At the moment both take 4-5 seconds for 1000 updates. I assume I'm using the bulk bind incorrectly or have a misunderstanding of the subject as in examples I can find people are executing 50,000 rows in 2 seconds etc. From what I understand FORALL should improve performance by reducing the number of context switches. I have tried another method I found online using cursors and bulk binds but had the same outcome. Perhaps my performance expectations are too much? I don't think so from seeing others results. Any help would be greatly appreciated.



create or replace procedure BulkUpdate(sendSubject_in IN varchar2_nested_table_type,
fieldname_in IN varchar2_nested_table_type,fieldvalue_in IN varchar2_nested_table_type) is


TYPE component_aat IS TABLE OF component.component_id%TYPE
INDEX BY PLS_INTEGER;
TYPE fieldname_aat IS TABLE OF component.fieldname%TYPE
INDEX BY PLS_INTEGER;
TYPE fieldvalue_aat IS TABLE OF component.fieldvalue%TYPE
INDEX BY PLS_INTEGER;

fieldnames fieldname_aat;
fieldvalues fieldvalue_aat;
approved_components component_aat;


PROCEDURE partition_eligibility
IS
BEGIN
FOR indx IN sendSubject_in.FIRST .. sendSubject_in.LAST
LOOP
approved_components(indx) := sendSubject_in(indx);
fieldnames(indx):= fieldname_in(indx);
fieldvalues(indx) := fieldvalue_in(indx);
END LOOP;
END;


PROCEDURE update_components
IS
BEGIN
FORALL indx IN approved_components.FIRST .. approved_components.LAST
UPDATE Component
SET Fieldvalue = fieldvalues(indx)
WHERE Component_id = approved_components(indx)
AND Fieldname = fieldnames(indx);
END;

BEGIN
partition_eligibility;
update_components;
END BulkUpdate;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 5 2012
Added on Mar 8 2012
11 comments
1,214 views