donnatronious
asked on
PLS-00364: loop index variable 'T' use is invalid
Apparently I'm doing something "illegal" here. How can I use a variable where I'm trying to use v_PRT?
Error is
Error report:
ORA-06550: line 6, column 47:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 6, column 17:
PL/SQL: SQL Statement ignored
ORA-06550: line 8, column 34:
PLS-00364: loop index variable 'T' use is invalid
ORA-06550: line 8, column 13:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
DECLARE
v_PRT varchar(30) := 'ALL_INTERNAL_MAIN_TEST_PRT';
BEGIN
FOR t IN (Select column_nm, src_nm from v_PRT)
LOOP
DBMS_OUTPUT.PUT_LINE(t.column_nm||t.src_nm);
END LOOP;
END;
/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
no, not if you want to iterate through the rows. You must use a cursor.
Also, if you have dynamic sql - that is, sql generated from a variable table you'll need "something" like the above.
if you're willing to go with static then, what you started with is ok.
Note, this is still using a cursor in the for loop (it's called a "cursor for loop")
BEGIN
FOR t IN (Select column_nm, src_nm from ALL_INTERNAL_MAIN_TEST_PRT )
LOOP
DBMS_OUTPUT.PUT_LINE(t.col umn_nm||t. src_nm);
END LOOP;
END;
Also, if you have dynamic sql - that is, sql generated from a variable table you'll need "something" like the above.
if you're willing to go with static then, what you started with is ok.
Note, this is still using a cursor in the for loop (it's called a "cursor for loop")
BEGIN
FOR t IN (Select column_nm, src_nm from ALL_INTERNAL_MAIN_TEST_PRT
LOOP
DBMS_OUTPUT.PUT_LINE(t.col
END LOOP;
END;
ASKER