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: Using a variable in a Select Clause

Re: Using a variable in a Select Clause

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Tue, 03 Nov 1998 17:43:38 GMT
Message-ID: <3644407b.16180055@192.86.155.100>


A copy of this was sent to dosberg7268_at_my-dejanews.com (if that email address didn't require changing) On Tue, 03 Nov 1998 17:31:56 GMT, you wrote:

>I'm building a cursor to execute several actions inside of a procedure. But I
>need to retrieve a value from a dictionary table in order to do a SELECT..INTO
>statement. The part I'm having trouble with would look like this:
>
> Declare
> x Varchar2(25);
> s Varchar2(25);
> Begin
> x:='CustId';
> Select x into s from Orders Where OrderId = 1234;
> End;
>

short of using DBMS_SQL to dynamically build, prepare, execute and fetch from a cursor, you could:

   x := 'custid';
   select decode( upper(x), 'CUSTID', custid, 'ANOTHER_COLUMN_NAME', another_column, .... ) into S from orders where orderid = 1234;

So, you could use decode to pick the column you really want.

>As I loop through the cursor I want to constantly be resetting X and insert a
>value into S. But the Select statement doesn't interpret the value of X as the
>literal string. I just get the value of X into the variable S. I figure there
>has got to be some way to do this. I would appreciate any advice.
>
>David Osberg
>dosberg_at_yahoo.com
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
 

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA

--
http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Tue Nov 03 1998 - 11:43:38 CST

Original text of this message

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