Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Basic for loop question

Steve_74Apr 6 2017 — edited Apr 6 2017

DB version : 11.2

In bash , I can execute a for loop to loop through hard coded values a,b and c like below.

How can I do the same in PL/SQL ?

$ cat test.sh

#!/bin/bash

for i in  a b c

do

        echo $i

done

$

$ ./test.sh

a

b

c

$

I tried the following PL/SQL block. But, it didn't work. Any way how I can write the equivalent of the above shell script in PL/SQL ?

begin

for i in a b c

loop

dbms_output.put_line(i);

end loop;

end;

/

Log :

SQL> begin

for i in a b c

loop

dbms_output.put_line(i);

end loop;

end;  2    3    4    5    6

  7  /

for i in a b c

           *

ERROR at line 2:

ORA-06550: line 2, column 12:

PLS-00103: Encountered the symbol "B" when expecting one of the following:

. ( * @ % & - + / at loop mod remainder rem ..

<an exponent (**)> || multiset

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 4 2017
Added on Apr 6 2017
10 comments
438 views