Re: dynamic column name

From: J.P. <jp_boileau_at_yahoo.com>
Date: 10 May 2002 08:28:54 -0700
Message-ID: <7e388bc3.0205100728.42a37a08_at_posting.google.com>


It's dynamic SQL. Try this:

declare cursor myc is

   select

      column_name
   from

      sometable
   cid INTEGER;
begin

   for myrec in myc LOOP

      cid := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(cid, 'SELECT ' || myrec.column_name ||
         ' FROM sometable', 
         dbms_sql.v7);
      DBMS_SQL.CLOSE_CURSOR(cid);
      END LOOP;

END; JP
"M Green" <machiel2000_at_spam.home.nl> wrote in message news:<0cKC8.212635$oI.14514377_at_zwoll1.home.nl>...
> Hi All,
>
> I've looked around for the answer to my question but couldn't find a
> straight answer.
>
> Question:
> Can I use the result of a query as the column name in another query?
>
> Something like:
> SELECT (SELECT column FROM columns WHERE column like '%TEST') FROM table
>
> Thanks very much!
> Mick Green
Received on Fri May 10 2002 - 17:28:54 CEST

Original text of this message