473,698 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array selection and update.

Greetings,

I am working on a project and we need to write a conversion script to
initialize a new field on a table. The number of records on this table
is on the order of millions so routine selection and update takes a
long time.

I am tasked with writing a pl/sql proc that utilizes array processing
to update the column.

Since all of the fields I am going to update are null, does it pay to
create a array-based select prior to updating? I was thinking of
array-selecting and then array updating 5000 at a crack. Or should I
just write a single update statement? Does the former approach (think
F-former F-first) perhaps give us the ability to commit where the
later (l-later l-last) does not?

What I have tried to do is bulk select the key fields into appropriate
arrays, I then bind those arrays to the update fields. Then I call the
update statement. These steps are performed in a while loop until the
number of records retrieved is less than the the max number to
fetch/pass.

If you have a small little example of what I am trying to do, please
post it.

Thank You
}\/{ark
Jul 19 '05 #1
3 10442

"Mark A Framness" <fa****@netnet. net> wrote in message
news:81******** *************** ***@posting.goo gle.com...
Greetings,

I am working on a project and we need to write a conversion script to
initialize a new field on a table. The number of records on this table
is on the order of millions so routine selection and update takes a
long time.

I am tasked with writing a pl/sql proc that utilizes array processing
to update the column.

Since all of the fields I am going to update are null, does it pay to
create a array-based select prior to updating? I was thinking of
array-selecting and then array updating 5000 at a crack. Or should I
just write a single update statement? Does the former approach (think
F-former F-first) perhaps give us the ability to commit where the
later (l-later l-last) does not?

What I have tried to do is bulk select the key fields into appropriate
arrays, I then bind those arrays to the update fields. Then I call the
update statement. These steps are performed in a while loop until the
number of records retrieved is less than the the max number to
fetch/pass.

If you have a small little example of what I am trying to do, please
post it.

Thank You
}\/{ark


Why not
update mytable set myField=Whateve rYouWantTheFiel dToBe;
commit;
That will be fastest.
Jim
Jul 19 '05 #2
Hi,

Pls refere "Taking Advantage of Bulk Binds" chapter of PL/SQL User's
Guide and Reference Release 8.1.X for more deatails.
How Do Bulk Binds Improve Performance?
=============== =============== ========
The assigning of values to PL/SQL variables in SQL statements is
called binding. The binding of an entire collection at once is called
bulk binding. Bulk binds improve performance by minimizing the number
of context switches between the PL/SQL and SQL engines. With bulk
binds, entire collections, not just individual elements, are passed
back and forth. For example, the following DELETE statement is sent to
the SQL engine just once, with an entire nested table:

DECLARE
TYPE NumList IS TABLE OF NUMBER;
mgrs NumList := NumList(7566, 7782, ...); -- manager numbers
BEGIN
...
FORALL i IN mgrs.FIRST..mgr s.LAST
DELETE FROM emp WHERE mgr = mgrs(i);
END;
In the example below, 5000 part numbers and names are loaded into
index-by tables. Then, all table elements are inserted into a database
table twice. First, they are inserted using a FOR loop, which
completes in 38 seconds. Then, they are bulk-inserted using a FORALL
statement, which completes in only 3 seconds.

SQL> SET SERVEROUTPUT ON
SQL> CREATE TABLE parts (pnum NUMBER(4), pname CHAR(15));

Table created.

SQL> GET test.sql
1 DECLARE
2 TYPE NumTab IS TABLE OF NUMBER(4) INDEX BY BINARY_INTEGER;
3 TYPE NameTab IS TABLE OF CHAR(15) INDEX BY BINARY_INTEGER;
4 pnums NumTab;
5 pnames NameTab;
6 t1 CHAR(5);
7 t2 CHAR(5);
8 t3 CHAR(5);
9 PROCEDURE get_time (t OUT NUMBER) IS
10 BEGIN SELECT TO_CHAR(SYSDATE ,'SSSSS') INTO t FROM dual; END;
11 BEGIN
12 FOR j IN 1..5000 LOOP -- load index-by tables
13 pnums(j) := j;
14 pnames(j) := 'Part No. ' || TO_CHAR(j); 15 END LOOP;
16 get_time(t1);
17 FOR i IN 1..5000 LOOP -- use FOR loop
18 INSERT INTO parts VALUES (pnums(i), pnames(i));
19 END LOOP;
20 get_time(t2);
21 FORALL i IN 1..5000 -- use FORALL statement
22 INSERT INTO parts VALUES (pnums(i), pnames(i));
23 get_time(t3);
24 DBMS_OUTPUT.PUT _LINE('Executio n Time (secs)');
25 DBMS_OUTPUT.PUT _LINE('---------------------');
26 DBMS_OUTPUT.PUT _LINE('FOR loop: ' || TO_CHAR(t2 - t1));
27 DBMS_OUTPUT.PUT _LINE('FORALL: ' || TO_CHAR(t3 - t2));
28* END;
SQL> /
Execution Time (secs)
---------------------
FOR loop: 38
FORALL: 3

PL/SQL procedure successfully completed.
To bulk-bind input collections, use the FORALL statement. To bulk-bind
output collections, use the BULK COLLECT clause.

Cheers!
Dhana

fa****@netnet.n et (Mark A Framness) wrote in message news:<81******* *************** ****@posting.go ogle.com>...
Greetings,

I am working on a project and we need to write a conversion script to
initialize a new field on a table. The number of records on this table
is on the order of millions so routine selection and update takes a
long time.

I am tasked with writing a pl/sql proc that utilizes array processing
to update the column.

Since all of the fields I am going to update are null, does it pay to
create a array-based select prior to updating? I was thinking of
array-selecting and then array updating 5000 at a crack. Or should I
just write a single update statement? Does the former approach (think
F-former F-first) perhaps give us the ability to commit where the
later (l-later l-last) does not?

What I have tried to do is bulk select the key fields into appropriate
arrays, I then bind those arrays to the update fields. Then I call the
update statement. These steps are performed in a while loop until the
number of records retrieved is less than the the max number to
fetch/pass.

If you have a small little example of what I am trying to do, please
post it.

Thank You
}\/{ark

Jul 19 '05 #3
Jan
adding some extra procedural code into single update statment would
probably not speed up the updation.

What you can do is to think about parallel update (if your machine has
more then 2 processors) - either by using Oracle parallelism - e.g.

update /*+ parallel(my_tab le, 4) */ my_table
set ....

or split table into n logical parts (by rowid) and schedule n jobs
with update procedure for a particular part of the table.
dh**********@db .com (Dhana) wrote in message news:<b6******* *************** ****@posting.go ogle.com>...
Hi,

Pls refere "Taking Advantage of Bulk Binds" chapter of PL/SQL User's
Guide and Reference Release 8.1.X for more deatails.
How Do Bulk Binds Improve Performance?
=============== =============== ========
The assigning of values to PL/SQL variables in SQL statements is
called binding. The binding of an entire collection at once is called
bulk binding. Bulk binds improve performance by minimizing the number
of context switches between the PL/SQL and SQL engines. With bulk
binds, entire collections, not just individual elements, are passed
back and forth. For example, the following DELETE statement is sent to
the SQL engine just once, with an entire nested table:

DECLARE
TYPE NumList IS TABLE OF NUMBER;
mgrs NumList := NumList(7566, 7782, ...); -- manager numbers
BEGIN
...
FORALL i IN mgrs.FIRST..mgr s.LAST
DELETE FROM emp WHERE mgr = mgrs(i);
END;
In the example below, 5000 part numbers and names are loaded into
index-by tables. Then, all table elements are inserted into a database
table twice. First, they are inserted using a FOR loop, which
completes in 38 seconds. Then, they are bulk-inserted using a FORALL
statement, which completes in only 3 seconds.

SQL> SET SERVEROUTPUT ON
SQL> CREATE TABLE parts (pnum NUMBER(4), pname CHAR(15));

Table created.

SQL> GET test.sql
1 DECLARE
2 TYPE NumTab IS TABLE OF NUMBER(4) INDEX BY BINARY_INTEGER;
3 TYPE NameTab IS TABLE OF CHAR(15) INDEX BY BINARY_INTEGER;
4 pnums NumTab;
5 pnames NameTab;
6 t1 CHAR(5);
7 t2 CHAR(5);
8 t3 CHAR(5);
9 PROCEDURE get_time (t OUT NUMBER) IS
10 BEGIN SELECT TO_CHAR(SYSDATE ,'SSSSS') INTO t FROM dual; END;
11 BEGIN
12 FOR j IN 1..5000 LOOP -- load index-by tables
13 pnums(j) := j;
14 pnames(j) := 'Part No. ' || TO_CHAR(j); 15 END LOOP;
16 get_time(t1);
17 FOR i IN 1..5000 LOOP -- use FOR loop
18 INSERT INTO parts VALUES (pnums(i), pnames(i));
19 END LOOP;
20 get_time(t2);
21 FORALL i IN 1..5000 -- use FORALL statement
22 INSERT INTO parts VALUES (pnums(i), pnames(i));
23 get_time(t3);
24 DBMS_OUTPUT.PUT _LINE('Executio n Time (secs)');
25 DBMS_OUTPUT.PUT _LINE('---------------------');
26 DBMS_OUTPUT.PUT _LINE('FOR loop: ' || TO_CHAR(t2 - t1));
27 DBMS_OUTPUT.PUT _LINE('FORALL: ' || TO_CHAR(t3 - t2));
28* END;
SQL> /
Execution Time (secs)
---------------------
FOR loop: 38
FORALL: 3

PL/SQL procedure successfully completed.
To bulk-bind input collections, use the FORALL statement. To bulk-bind
output collections, use the BULK COLLECT clause.

Cheers!
Dhana

fa****@netnet.n et (Mark A Framness) wrote in message news:<81******* *************** ****@posting.go ogle.com>...
Greetings,

I am working on a project and we need to write a conversion script to
initialize a new field on a table. The number of records on this table
is on the order of millions so routine selection and update takes a
long time.

I am tasked with writing a pl/sql proc that utilizes array processing
to update the column.

Since all of the fields I am going to update are null, does it pay to
create a array-based select prior to updating? I was thinking of
array-selecting and then array updating 5000 at a crack. Or should I
just write a single update statement? Does the former approach (think
F-former F-first) perhaps give us the ability to commit where the
later (l-later l-last) does not?

What I have tried to do is bulk select the key fields into appropriate
arrays, I then bind those arrays to the update fields. Then I call the
update statement. These steps are performed in a while loop until the
number of records retrieved is less than the the max number to
fetch/pass.

If you have a small little example of what I am trying to do, please
post it.

Thank You
}\/{ark

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1734
by: Emmett Power | last post by:
Hi, I have a form with a table with two fields SelectionID and Experience. I am posting the data to a database using an array function. I have set out the code below. The problem I am having is where the Experience field is blank I get an Microsoft OLE DB Provider for ODBC Drivers error '80040e21'. It makes sense that a null value would cause the function problems.
5
2212
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as 1,1,2,4. I have narrowed it down to the sort function. I'm almost positive
2
2460
by: kimimaro | last post by:
hi I wonder if array can be work along with structure? Below are the declaration of my structure struct employee{ char ID; char Name; char Department;
4
2209
by: bienwell | last post by:
Hi all, Data displayed on the datalist control is bound by the column name of the dataset like this : <%# DataBinder.Eval(Container.DataItem, "title")%> Could I use an element of the array (i.e. index=0) which has the name "title" in place of it ? For example:
4
1437
by: William | last post by:
My first time posting to clj , I have already read http://jibbering.com/faq/#FAQ2_3 before posting. javascript function in question: saveText() is as follows: function saveText( scroll_list, t_area, listToBeUpdated ) { alert( listToBeUpdated.name ); // need to know which list to add the value in textarea back into
2
1721
by: dmot | last post by:
I need to save the information from hotel rooms to an array. This array then needs to be saved to a file and then accessed again. Could anyone give me any tips on how to do this? #include <conio.h> /*Console I/O Header*/ #include <stdlib.h> /*Standard Library Header*/ #include <stdio.h> /*Standard I/O Header*/ #include <ctype.h> /*C Library*/ #include <string.h> /*String Header*/
6
3677
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
4
4339
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on "selectedValues" from next page for php variable this is my javascript code saved on "sendValue.js" file, <script> function updateRecordEntry(requestValue){
2
2639
by: julie18881 | last post by:
I may be being really stupid here, i have spent the last 3 hours looking round your site and some other for answers to my problem, but have not had much luck (possibly cuase my brain just isn't working today) I have EasyPHP2.0b1 Apache/MySQL server installed on my Windows XP(SP2) machine. This runs Apache 2.2.3, MySQL 5.0.27 and PHP 5.2.0 I have a PHP code filled listbox, which allows multiple selections. Actual Values are "rcd_no, cn_no"...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7738
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.