Re: Select table column dynamically.

From: AMARENDRA B NETTEM <nettama_at_charlie.cns.iit.edu>
Date: 1997/08/25
Message-ID: <3401F6D2.73C5_at_charlie.cns.iit.edu>#1/1


YyWong wrote:
>
> I want to write a PL/SQL to select values from a specified column.
> However, I don't know how can I do this. Can anyone help me?
>
> The question is:
>
> Suppose I have a table TEST created as
> create table TEST
> (ID NUMBER NOT NULL,
> A1 VARCHAR2(5) NULL,
> A2 VARCHAR2(5) NULL,
> A3 VARCHAR2(5) NULL);
>
> and I want to select the column 'A1', 'A2', 'A3' dynamically in
> a PL/SQL procedure. Example,
>
> select A? from TEST;
>
> where ? represents a number 1, 2, or 3 which is assigned from the
> program at runtime.
>
> Is it possible to do this?
> --
Write a stored procedure by passing column names as IN parameters.

CREATE OR REPLACE PROCEDURE SQL_STMT(A IN VARCHAR2) AS

BEGIN
 SELECT A FROM TEST;
END;
/



SQL> EXECUTE SQL_STMT('COL1,COL2,COL3');

Hope this Helps

AMARENDRA B NETTEM

-- 
*********************************************************************
AMARENDRA B NETTEM			5039 N E River Road, Apt. 1A
Certified Oracle DBA			NORRIDGE, IL 60656
Whittman-Hart Inc., 
Chicago, IL 60656.  

Ph.No. (708) 583 9870 (H)             E-mail:
nettama_at_charlie.cns.iit.edu
       (312) 813 6758 (W)                     anettem_at_whittman-hart.com

Homepage: http://www.iit.edu/~nettama

**********************************************************************
Received on Mon Aug 25 1997 - 00:00:00 CEST

Original text of this message