How do I create Dynamic Rowtype References?
Please see below for the sample procedure that I've. Please excuse me if I'm not abiding the rules of posting questions.
The first cursor(c2) will have a list of all table names.
Then I've the ref cursor(r_cursor) that executes a SQL statement formed using the table_name from the first cursor.
The problem is that I need to form a dynamic rowtype refrence of each table as and when the table name changes in the first cursor.
Right now I've it as tab client%rowtype; which defines a CLIENT rowtype. Now when the first cursor loops and goes to the next table is it possible for me to use the same 'tab' variable to declare rowtype of the new table. Is this a valid question or is it not possible to do this.
If not possible can anybody suggest a way to do this??
Thanks
CREATE OR REPLACE procedure samp2
as
cursor c2 is
select table_name from user_tables where table_name = 'CLIENT';
v2 c2%rowtype;
type r_cursor is REF CURSOR;
c_cln r_cursor;
tab client%rowtype;
sql_stmt varchar2(200);
begin
open c2;
loop
fetch c2 into v2;
exit when c2%notfound;
sql_stmt := 'select from '||v2.table_name||' where id =64';*
EXECUTE IMMEDIATE sql_stmt;
* open c_cln for sql_stmt;*
* loop*
* FETCH c_cln INTO tab;*
* exit when c_cln%notfound;*
* *
* dbms_output.put_line(tab.first_nam_d);*
* end loop;*
* close c_cln;*
end loop;
close c2;
end;
*/*