Variable uses and placement

Posted on 16th Feb 2014 by admin

I'm new to PL/SQL and am trying to learn about variable valid uses/placement (any pointers to any docs is appreciated...)
All of the docs I've looked only mention declaration and assignment not valid placement.

When I use an input parameter to a cursor placement matters . I just don't understand why...

example... using the value "SCOTT" as an input parm to the c10 cursor replaces the "str_in" variable correctly and works...

1 declare
2 cursor c10(str_in IN varchar2) is
3 select username
4 from dba_users where username=str_in ;
5 begin
6 for r_c10 in c10('SCOTT') loop
7 dbms_output.put_line(r_c10.username);
8 end loop;
9* end;
SQL> /
SCOTT

PL/SQL procedure successfully completed.

However, when trying to replace another "word" it won't resolve the reference...

example... attempting to replace the from table_name as an input parm, no go...

1 declare
2 cursor c10(str_in IN varchar2) is
3 select username
4 from str_in where username='SCOTT' ;
5 begin
6 for r_c10 in c10('DBA_USERS') loop
7 dbms_output.put_line(r_c10.username);
8 end loop;
9* end;
SQL> /
from str_in where username='SCOTT' ;
*
ERROR at line 4:
ORA-06550: line 4, column 6:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 3, column 1:
PL/SQL: SQL Statement ignored
ORA-06550: line 7, column 26:
PLS-00364: loop index variable 'R_C10' use is invalid
ORA-06550: line 7, column 5:
PL/SQL: Statement ignored

Why can't it resolve the string ?

Any help is appreciated
dumb newbie...

Other forums