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!

How to bind a column logic using bind variable in dynamic SQL ?

UtsavJun 26 2018 — edited Jun 26 2018

I've a SQL, whose where the predicate is well binded using bind varaible.

Now, I've a column whom I want to be used a bind variable.

But, the column which I am trying to bind uses a logic (case when statements) which will get change frequently.

I believe if I pass the column name as bind variable it'll be treated as string literal not as a column logic any workaround or suggestions

SQL> set serveroutput on;

SQL> declare

  2  l_sql varchar2(200);

  3  l_col  varchar2(200);

  4  l_where number:=1;

  5

  6  l_var1 varchar2(200);

  7  l_var2 varchar2(200);

  8  begin

  9    l_col:='ceil(0.9) as col2 ';

10    l_sql:='select 1 as cola, :col2 from dual where 1 = :p1';

11    execute immediate l_sql into l_var1,l_var2 using l_col,l_where;

12    dbms_output.put_line(l_var1||'---'||l_var2);

13  end;

14  /

1---ceil(0.9) as col2

PL/SQL procedure successfully completed.

SQL>

This post has been answered by Cookiemonster76 on Jun 26 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 24 2018
Added on Jun 26 2018
2 comments
1,060 views