Home » SQL & PL/SQL » SQL & PL/SQL » Restrictions in accessing collections values (Oracle 10g)
Restrictions in accessing collections values [message #606760] Wed, 29 January 2014 01:33 Go to next message
anilkln
Messages: 7
Registered: August 2012
Junior Member
Hi I would like to know is there is any restrictions

declare
  type ta_v  is table of varchar2(10);
name varchar2(10);
  var_ta  table_varchar;
begin
  var_ta  := ta_v('SMITH', 'ANIL', 'JONES', 'FORD');

  for i in 1 .. var_ta.count loop
Begin
select ename into name from emp where ename in var_ta(i);
dbms_output.put_line(name);
exception
when others then
dbms_output.put_line('Skipped values'|| ': ' || var_ta(i));
var_ta(i):=var_ta.next(i);
end;
end loop;
end;
/



How many values can i assign to var_ta. Please explain
Re: Restrictions in accessing collections values [message #606761 is a reply to message #606760] Wed, 29 January 2014 02:06 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
From the docs :

Quote:
•For nested tables, 1 .. 2147483647 (the upper limit of PLS_INTEGER).


Read Referencing Collection Elements


In your code, this is wrong :

var_ta  table_varchar;


What is table_varcahr?

I modified it to :

SQL> set serveroutput on;
SQL> 
SQL> DECLARE
  2     TYPE TA_V IS TABLE OF VARCHAR2(10);
  3     NAME   VARCHAR2(10);
  4     VAR_TA TA_V;
  5  BEGIN
  6     --VAR_TA := TA_V('SMITH', 'ANIL', 'JONES', 'FORD');
  7     FOR I IN (SELECT ENAME FROM EMP) LOOP
  8        VAR_TA := TA_V(I.ENAME);
  9  
 10        FOR I IN 1 .. VAR_TA.COUNT LOOP
 11           BEGIN
 12              SELECT ENAME INTO NAME FROM EMP WHERE ENAME IN VAR_TA(I);
 13              DBMS_OUTPUT.PUT_LINE(NAME);
 14           EXCEPTION
 15              WHEN OTHERS THEN
 16                 DBMS_OUTPUT.PUT_LINE('Skipped values' || ': ' || VAR_TA(I));
 17                 VAR_TA(I) := VAR_TA.NEXT(I);
 18           END;
 19        END LOOP;
 20     END LOOP;
 21  END;
 22  /
 
KING
BLAKE
CLARK
JONES
SCOTT
FORD
SMITH
ALLEN
WARD
MARTIN
TURNER
ADAMS
JAMES
MILLER
 
PL/SQL procedure successfully completed
Re: Restrictions in accessing collections values [message #606762 is a reply to message #606761] Wed, 29 January 2014 02:34 Go to previous messageGo to next message
anilkln
Messages: 7
Registered: August 2012
Junior Member
Hi Lalit,

Thanks for the reply. and it was a typo.
what i exactly wanted is i want to keep some values in TA_V
like TA_V('SMITH', 'ANIL', 'JONES', 'FORD');

How many values can i keep is there any limit. Please explain
Re: Restrictions in accessing collections values [message #606764 is a reply to message #606762] Wed, 29 January 2014 02:59 Go to previous message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

It seems you don't understand:

Quote:
For nested tables, 1 .. 2147483647 (the upper limit of PLS_INTEGER)


So I will put it clearly: you can keep 2147483647 elements... if your process memory allows it.

Previous Topic: Extracting sub-string in reverse way
Next Topic: Selecting top records
Goto Forum:
  


Current Time: Tue Apr 23 03:32:06 CDT 2024