Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dynamic column name in WHERE clause

Sen2008Jul 15 2014 — edited Jul 15 2014

All,

I have to pass the column name in the where clause in the below sql query.

declare

v_col varchar2(100) := 'deptId';

v_dept varchar2(100);

begin

select 1 into v_dept from department where v_col=100;

dbms_output.put_line(v_dept);

end;

for deptId=100, there is no data in the department table.  However, if I execute the query, it output as 1.  But, if the same query is replaced as

'select 1 into v_dept from department where deptId=100'  the sql throws error 'no data found'.  Where am I making the mistake? Please advice.

regards

sen

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 12 2014
Added on Jul 15 2014
1 comment
1,563 views