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 -> Re: PL/SQL question

Re: PL/SQL question

From: Matthias Kleinicke <Matthias.Kleinicke_at_gmx.de>
Date: Fri, 16 Sep 2005 22:48:25 +0200
Message-ID: <dgfb1c$li3$1@online.de>


Rolf Johnny van der Zwart schrieb:
> Hello,
>
> Is it possible to use a variable in the select statement which holds
> the column I want to select?
>
> So:
>
> declare
> range number;
> column_name varchar2(10);
> begin
> for range in 1..48 loop
> column_name := halfhour||range;
> select column_name from some_table;
> end loop;
> end;
> /
>

For this approach dynamic SQL is needed, as Marc stated.
>
> I need this to select a column halfhour1 until halfhour48, so I need
> to give the number at the end of the column_name.
>
> Any idea's?
>

Why not select the whole Row and decode later. Your example then could look like:

declare

      whole_row some_table%ROWTYPE; begin

     select * into whole_row from some_table;
     ...

end;
/

The fields could be accessed by whole_row.halfhour1..48.

hth

Matthias Received on Fri Sep 16 2005 - 15:48:25 CDT

Original text of this message

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