Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> columns/fields dynamically accessed in PL/SQL
I have two things I would like to do: First, access/initialize the
%rowtype of a var programmatically. Instead of having to know the
particular table upfront I would like to assign it dynamically. Also I
would like to iterate the the columns/fields for the data. PL/SQL just
does not appear to have the flexibility I am looking for in iterating
thru a list of tables. An example of what I would like to do is the
following:
i number := array_tables.first;
cur sys_refcursor;
loop
exit when i is null;
<define the rowtype var here>
var_fetch ( array_tables(i).table_name )%rowtype;
open cur for array_tables(i).sql;
loop
fetch cur into var_fetch; exit when cur%notfound; <test for the column> if ( var_fetch.columns( "columnx" ) is not null ) then <access the columns/fields dynamically> if ( var_fetch( "columnx" ) > 0 ) then -- do something here end if; end if;
end loop;
end loop;
Can it be done or do I have to go the route of Java?
Thanks,
Steve
Received on Mon Feb 13 2006 - 12:37:00 CST