Does anybody use dynamic sql in their Oracle stored procedures. I'm just testing it and I'm getting the following error:
ORA-00903: Invalid table name
at line 8 (open-for)
What am I doing wrong?
Thanks for any help!
Regards, Tomaz
CREATE OR REPLACE PROCEDURE cr_test(
k_test in out crystal.tip_kurzor,
table_name VARCHAR2) IS
query_str VARCHAR2(1000);
con_id NUMBER;
BEGIN
query_str := 'SELECT contract_id FROM ' || table_name || ' WHERE account_id = 301271';
OPEN k_test FOR query_str; --line 8
LOOP
FETCH k_test INTO con_id;
EXIT WHEN k_test%NOTFOUND;
END LOOP;
CLOSE k_test;
END;
ORA-00903: Invalid table name
at line 8 (open-for)
What am I doing wrong?
Thanks for any help!
Regards, Tomaz
CREATE OR REPLACE PROCEDURE cr_test(
k_test in out crystal.tip_kurzor,
table_name VARCHAR2) IS
query_str VARCHAR2(1000);
con_id NUMBER;
BEGIN
query_str := 'SELECT contract_id FROM ' || table_name || ' WHERE account_id = 301271';
OPEN k_test FOR query_str; --line 8
LOOP
FETCH k_test INTO con_id;
EXIT WHEN k_test%NOTFOUND;
END LOOP;
CLOSE k_test;
END;