I am trying to run plsql anonymous block using execute immediate and the plsql block contains a bind variable for which the value is a sql select statement. But it seems this does not work. Is there any solution for to solve this. E.g.
BEGIN
V_SQL:='SELECT emp_id FROM emp WHERE dept_id=10;
PLSQL_BLOCK:='DECLARE
type emp_type
IS
TABLE OF NUMBER;
emp_id emp_type;
BEGIN
EXECUTE IMMEDIATE :1 BULK COLLECT INTO emp_id;
END';
EXECUTE IMMEDIATE PLSQL_BLOCK USING V_SQL;
If I understand well, you need to run an entire dynamic PLSQL block by using as SQL query as a bind variable; if so, you can try this way: