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: Substitution of column names

Re: Substitution of column names

From: Thomas J. Kyte <tkyte_at_us.oracle.com>
Date: 1997/02/13
Message-ID: <33027a1b.3731856@nntp.mediasoft.net>#1/1

try:

select fund, orgn, acct,

       decode( :UserInput, 1, total_01_budg,
                           2, total_02_budg,
                           3, total_03_budg, 
                           .....
                           12, total_12_budg ) total_budg
from mytable
/

Bind in the value for UserInput when you open the cursor. decode is sort of like a case statement in sql....

On Wed, 12 Feb 1997 08:49:51 -0900, "Maureen T. English" <snmte_at_orca.alaska.edu> wrote:

>Hi Everyone,
>
>I there a simple way to select a column from a table, based on what
>a user inputs?
>
>My table has the following columns
> FUND
> ORGN
> ACCT
> TOTAL_01_BUDG
> TOTAL_02_BUDG
> TOTAL_03_BUDG
> .
> .
> .
> TOTAL_12_BUDG
>
>My select statement is
> SELECT FUND, ORGN, ACCT, TOTAL_nn_BUDG
> FROM MYTABLE;
>
>Every month the select statement changes. Is there a way to have the
>user input the cycle (01, 02, ... 12) and then insert what the user
>inputs into the column name? Otherwise, every month I have to edit the
>script to change the 01s to 02s, or the 02s to 03s, etc.
>
>I have thought of creating a temporary table, and of having 12 select
>statements in the script...I'm just curious if there's a way to
>substitute with what the user inputs.
>
>Thanks for any suggestions.
>
>- Maureen English
> Systems Analyst
> University of Alaska
> snmte_at_orca.alaska.edu

Thomas Kyte
Oracle Government
tkyte_at_us.oracle.com                          

http://govt.us.oracle.com


statements and opinions are mine and do not necessarily reflect the opinions of Oracle Corporation Received on Thu Feb 13 1997 - 00:00:00 CST

Original text of this message

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