Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: column name passed as a variable
Look at Dynamic methods 3 & 4 in the Pro*C docs.
-- Ron Reidy Oracle DBA Sandy wrote:Received on Wed Feb 19 2003 - 14:58:29 CST
> I am new to Oracle application programming. We are using Oracle Pro C/C++ and
> and Oracle 7 database. I am trying to pass a column name into a SQL EXEC statement.
> If I explicitly name the column, the query returns the expected results. However,
> if I try to pass variable, the returned value is the column name.
> Can someone tell me what I am doing wrong?
>
> Thanks,
>
> EXEC SQL BEGIN DECLARE SECTION;
> char in_FieldName[40];
> char in_SubsystemId[15];
> char fieldValue[5];
> static short nullind;
> EXEC SQL END DECLARE SECTION;
>
>
>
> strcpy(fieldValue,'\0');
> strcpy(in_FieldName,FieldName);
> strcpy(in_SubsystemId,'\0');
> sprintf(in_SubsystemId,"%.0f",SubsystemId);
>
> EXEC SQL
> SELECT :in_FieldName
> INTO :fieldValue :nullind
> FROM LND
> WHERE LND.SubsystemId = :in_SubsystemId;