Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, User.

Asked: September 23, 2015 - 5:16 am UTC

Last updated: September 28, 2015 - 3:35 am UTC

Version: 10.2.0.1

Viewed 10K+ times! This question is

You Asked

If i execute a stored procedure from a scheduled job and if the procedure has lot of sqls then what will be the array size these sqls will run with?
Thanks in advance.

and Connor said...

It depends on the code you write and optimization levels. Here's some examples to get you started.

1) simple one row select

select col
into x
from MY_TABLE
where ...

Obviously arraysize of no real consequence here, we are getting 1 row

2) simple cursor

for i in ( select * from MY_TABLE ) loop
...
end loop;

We'll do an array fetch size of 100 for you, even though the code doesnt seem to suggest it

3) DML

insert into MY_TABLE select * from OTHER_TABLE

PL/SQL has no 'participation' in this command, so it will run like a normal SQL and arraysize is not of relevance

4)

declare
cursor C is ...
begin
open C;
loop
fetch C into ...
exit when c%notfound;
end loop;

Will do arrayfetch 1 row at a time... probably a bad idea. Better to recast as

for i in C loop

5) explcit

declare
cursor C is ...
begin
open C;
loop
fetch C bulk collect into xxx limit nnn;
exit when c%notfound;
end loop;

arraysize is 'nnn';

6) simple multi row select

select col
bulk collect into my_array
from MY_TABLE
where ...

Arraysize as big as the rows picked up.

Hope this helps.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

User, September 26, 2015 - 7:51 am UTC

Thanks for this nice explanation. I have a doubt. If i run a query like Insert into my_table select * from emp in sqlplus then to best of my knowledge the sql will execute with a array size as set by arraysize=nnn environment variable. If this is true then what will be the array size the sql will execute if i write it within a procedure and call the procedure from sqlplus. I guess it would run with the array size as defined by arraysize=nnn.
Thanks and regards.
Connor McDonald
September 28, 2015 - 3:35 am UTC

"If i run a query like Insert into my_table select * from emp in sqlplus then to best of my knowledge the sql will execute with a array size as set by arraysize=nnn environment variable"

No that is not true. 'arraysize' is the database returning records to the *client*, in this case, sqlplus.

insert into T1 select * from T2;

never "leaves" the database, so arraysize is not relevant. It will be done by extracting rows from blocks, and will be efficient as possible.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library