Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> columns/fields dynamically accessed in PL/SQL

columns/fields dynamically accessed in PL/SQL

From: <steven.dahlin_at_gmail.com>
Date: 13 Feb 2006 10:37:00 -0800
Message-ID: <1139855820.784567.182970@g14g2000cwa.googlegroups.com>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US