Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can PL/SQL FOR IN used with strings?

7,200 views
Skip to first unread message

Yong Huang

unread,
Sep 20, 2000, 3:00:00 AM9/20/00
to
Can I use PL/SQL For Loop on an array of strings instead of numbers?

SQL> begin
2 for i in 'some string', 'another string' loop
3 dbms_output.put_line(i);
4 end loop;
5 end;
6 /
for i in 'some string', 'another string' loop
*
ERROR at line 2:
ORA-06550: line 2, column 24:
PLS-00103: Encountered the symbol "," when expecting one of the following:
. ( * @ % & - + / loop mod range rem .. an exponent (**) ||
The symbol ". was inserted before "," to continue.

If the for loop index only works as a number, I believe the only way to loop
through an array of string is to put those strings in a PL/SQL table first.
Any advice is appreciated.

Yong Huang
yhu...@indigopool.com

Daniel Blonski

unread,
Nov 17, 2000, 3:00:00 AM11/17/00
to Yong Huang

The for loop has always an integer index (and the incrment is always
one). If you want to loop through a string list you need in fact a
PL/SQL-Table:

declare
type string_list is table of varchar2(50);
my_list string_list := string_list('some string', 'another string');
begin
for i in my_list.first .. my_list.last loop
dbms_output.put_line( my_list(i) );
end loop;
end;
/

doganay_n

unread,
Feb 21, 2014, 3:47:21 AM2/21/14
to
17 Kasım 2000 Cuma 10:00:00 UTC+2 tarihinde Daniel Blonski yazdı:
Thanks Daniel :=)

Mark D Powell

unread,
Feb 25, 2014, 11:33:52 AM2/25/14
to
Kasim, A little late but here is the reference if you need more information on creating and using PL/SQL tables: http://docs.oracle.com/cd/E11882_01/appdev.112/e10830/ch_five.htm#BABEEDGH

HTH -- Mark D Powell --
0 new messages