Re: PL/SQL Cursor with Parameter for Column Name

From: Jusung Yang <JusungYang_at_yahoo.com>
Date: 17 Dec 2002 14:51:24 -0800
Message-ID: <130ba93a.0212171451.6b7081d2_at_posting.google.com>


Cann't do that. You just ask ORACLE to

select 'cost' from <table> where .....;

So that's what you get. Try dynamic SQL instead.

  • Jusung Yang

gabi_at_gambita.de (Gabi) wrote in message news:<17bcd487.0212171004.4a4e8728_at_posting.google.com>...
> Hi all,
>
> i would like to build a select statement for a cursor and want to
> provide the column name for which the value is to be extracted as a
> parameter. All provided fields are NUMBERs. So I do something like:
>
> CURSOR c_data (sField VARCHAR2)
> IS
> SELECT sField
> FROM <tablename>
> WHERE <condition>
> ;
>
> when I call the cursor with some value for sField, let's say
>
> open c_data('COSTS');
> ...
> FETCH c_data INTO value_field; -- value_field is NUMBER
>
> I get an error. When I switch value_field to VARCHAR2, I get:
>
> COSTS (just the name in varchar!)
>
> as selected value from the select statement and not the value in the
> column 'COSTS' just as if the column didn't exist in the table....
>
> what's wrong?
> (i would even prefer to read all fields from the table at once and
> then address them by using something like c_data.column_name, looping
> over the column_names... but this doesn't work either :-( )
>
> Thanks a lot...
> Gabi
Received on Tue Dec 17 2002 - 23:51:24 CET

Original text of this message