Skip to Main Content
  • Questions
  • Upper limit of a container (say Varray ) depends on what Parameter

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, chaitanya.

Asked: June 17, 2002 - 11:09 pm UTC

Last updated: August 28, 2013 - 6:07 pm UTC

Version: 8.1.7

Viewed 1000+ times

You Asked

Hi Tom,

Thanks for your response on rowpointer in a refcursor. It cleared my doubts.

I have a problem like this :
1. I have a Varray as below :

CREATE OR REPLACE TYPE str_test AS object(
item_NAME VARCHAR2(40),
sale_price NUMBER(15,6));

CREATE OR REPLACE TYPE pra_test IS VARRAY(10000) OF str_test;

2. I wrote a anonymous block to load data into the structure like this :

DECLARE
la_pra_Test pra_test := pra_test(); -- holds array of ln_indx number := 1;
begin
FOR ln_indx in 1..10001 LOOP
la_pra_test.EXTEND();
--dbms_output.put_line('ln_indx ='||ln_indx);
la_pra_test(ln_indx) :=
str_test('ITEM'||ln_indx,
ln_indx||01.00);

END LOOP;
end;

here the problem is if ln_indx = 10000, the block executes fine, but if it is 10001 it gives ora-06532 subscript outside of limit. Could you please let me know how is the limit defined ?

The other day i had a bigger structure and i was populating data from a table and it failed at ln_indx = 500, is it anything to do with memory defined in oracle ?

3. One more related problem is :
i would like to select all employees whose name is in a table type:
i have read the earlier questions, it works fine if used in explicit sql statements, but my requirement is , the sql statement is a dynamic one and i am executing using execute immediate it is not working ?

if query is like this :
table_type_variable is loaded with the empno's

select * from emp where
empno in (select * from THE(select CAST(table_type_vaiable)
from dual)

if my variable is like this:

var1 := 'insert into emp_test select * from emp where
empno in (select * from THE (select '|| CAST(table_type_variable) '|| ' from dual)';
execute immediate var1;

your answers will help me to know more fundamentals as allways.
Thanks
Chaitanya

and Tom said...

Umm, you put the limit on there:

CREATE OR REPLACE TYPE pra_test IS VARRAY(10000) OF str_test;

you told us 10,000 was the upper limit. Hence, 10001 is definitely out of bounds.

Nothing to do with memory -- everything to do with your definition of the type itself.

In dynamic sql you must bind the variables.


ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace type myTableType as table of number
2 /

Type created.

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> create table t ( x int );

Table created.

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> declare
2 l_data myTableType := myTableType( 1,2,3,4 );
3 begin
4 execute immediate
5 'begin insert into t select column_value from TABLE( cast(:x as myTableType) ); end;'
6 USING l_data;
7 end;
8 /

PL/SQL procedure successfully completed.

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> select * from t;

X
----------
1
2
3
4

ops$tkyte@ORA817DEV.US.ORACLE.COM>

Rating

  (2 ratings)

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

Comments

chaitanya, June 18, 2002 - 3:01 pm UTC

Hey tom,
Thanks for your reply.
I don't know how i overlooked the definition of varray and asked the question.


Max value of Varray

Jitendra Jalota, August 22, 2013 - 9:08 am UTC

Hi Tom,

could you please let me know the max value/limit we can assign for a varray.

is it 65535 ?

Thanks.

Tom Kyte
August 28, 2013 - 6:07 pm UTC

I DO NOT RECOMMEND THIS:

ops$tkyte%ORA11GR2> create type myvarray as varray(10000000) of number;
  2  /

Type created.

ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> declare
  2  x myvarray := myvarray();
  3  begin
  4  x.extend(10000000);
  5  x(1) := 1;
  6  x(10000000) := 10000000;
  7  end;
  8  /

PL/SQL procedure successfully completed.


it'll chew of ram like crazy..... varrays are not sparse!

use reasonable numbers.


ops$tkyte%ORA11GR2> drop type myvarray;

Type dropped.

ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> create type myvarray as varray(100000000) of number;
  2  /

Type created.

ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> declare
  2  x myvarray := myvarray();
  3  begin
  4  x.extend(100000000);
  5  x(1) := 1;
  6  x(100000000) := 100000000;
  7  end;
  8  /
declare
*
ERROR at line 1:
ORA-06500: PL/SQL: storage error
ORA-04030: out of process memory when trying to allocate 16328 bytes (koh-kghu
call ,pmucalm coll)
ORA-06512: at line 4



for that reason...

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