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

Home -> Community -> Usenet -> c.d.o.misc -> Re: dbms_random&varray

Re: dbms_random&varray

From: Maxim Demenko <mdemenko_at_gmail.com>
Date: Sun, 15 Apr 2007 14:35:55 +0200
Message-ID: <46221C2B.7070502@gmail.com>


Ora_PL schrieb:
> Michel Cadot napisaƂ(a):
>

>> | Yes, but if you set serverout on, you should get less friendly answer.
>>
>> I don't understand your answer.
>>
>> Regards
>> Michel Cadot
>>
>>

>
> If you set 'serveroutput on' and use this method:
>
> DBMS_OUTPUT.PUT_LINE(TO_CHAR(V_TABLE(1))||'|'||TO_CHAR(V_TABLE(2))||'|'||TO_CHAR(V_TABLE(3)));
>

Why should one use this method? Only to prove himself, that if a varray is initialized with only *one* element
(v_table := TABLE_v(V_IN);)
any attempt to access this varray by subscripts greater than number of elements (i.e, 2 is greater than 1, 3 is greater than 1) (DBMS_OUTPUT.PUT_LINE(TO_CHAR(V_TABLE(1))||'|'||TO_CHAR(V_TABLE(2))||'|'||TO_CHAR(V_TABLE(3))); )
will unavoidable result in ORA-06533 ?
( well, maybe you suppose, VARRAY(3) automagically initialize varray with 3 empty slots - in that case this is wrong assumption)

Best regards

Maxim

>
> you get error ORA-06533.
>
> try:
>
> set serveroutput on
>
> DECLARE
>
> V_IN NUMBER(2);
> TYPE table_v IS VARRAY(3) OF NUMBER;
> V_TABLE TABLE_v;
>
> BEGIN
>
> v_in := dbms_random.VALUE(1,3);
> v_table := TABLE_v(V_IN);
>
> DBMS_OUTPUT.PUT_LINE(TO_CHAR(V_TABLE(1))||'|'||TO_CHAR(V_TABLE(2))||'|'||TO_CHAR(V_TABLE(3)));
>
> --or
> for idx in v_table.first..v_table.last loop
> DBMS_OUTPUT.PUT_LINE(TO_CHAR(v_Table(idx)));
> end loop;
>
> END;
>
> /
Received on Sun Apr 15 2007 - 07:35:55 CDT

Original text of this message

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