I have a view t with me which has a column for table name and another column which has where clause condition.
id| name|table_in| where_clause
1 | S
@Akshay,
Please find the code below for your reference.
Create or replace procedure create_cursor is
l_statement varchar2(32767);
cursor v_records is
select * from t;
begin
for temp in v_records
loop
l_statement := 'INSERT INTO myTable (id, name) select '||temp.id||','
||temp.name|| ' from ' || temp.table1
|| ' where ' || temp.where_clause;
execute immediate l_statement;
end loop;
end;
/
You need dynamic sql to do this:
CREATE OR REPLACE PROCEDURE create_cursor
IS
l_statement VARCHAR2(32767);
CURSOR v_records
IS
SELECT * FROM t;
BEGIN
FOR temp IN v_records
LOOP
l_statement := 'INSERT INTO myTable (id, name)
select id, name from ' || temp.table ||
' where ' || temp.where_clause;
EXECUTE immediate l_statement;
END LOOP;
END;
/