Hi,
My objective is to get the name 'Thomas' in the variable - MValue1. I don't want to use the statement
MValue1:=MTest1.Name because, moving forward, I want to have the column name to be dynamic, taken from an array of column names, to reduce number of lines in the code.
Also, by modifying the code as given below, I am able to get MValue1='Thomas'.
declare
str1 VarChar2(1000);
MValue1 Varchar2(100);
begin
str1:='Select Name from Test1 where id=10';
execute immediate str1 into mvalue1;
dbms_output.put_line('mvalue1 '||mvalue1);
end;
But it doesn't serve my purpose, as I need to achieve it by giving only one select query to get entire record and fetch the column values one by one, by substituting the column name from an array of column names, instead of writing that many lines of code / querying that may times to the database. Hope my requirement is clear.
Thanking all,
Sreekumar.
QUOTE (burleson @ Jan 24 2012, 12:18 PM)

Hi,
>> In a select query, I want to substitute the column name from a variable (In turn from an array of column names). Details are given below. I am getting an error as mentioned below
But you're nor really changing the colimn name, you hav a mutli-use column and a flig that says what tyoes of data is in it . . . .
*****************************************
>> str1:='Select MTest1.'||str1||' from dual';
What are you trying to dio here?
>> execute immediate str1 into mvalue1;
This is not a valid INSERT statdment!See here, using dynamic SQL in PL/SQL:
http://www.dba-oracle.com/t_building_dynam...l_statement.htm