Execute Queries in Oracle with Dynamic input in where clause -
i have dept(deptno, dname, loc) table data.
i query departments search key dname.
i trying below, not working. can please suggest me. pretty new oracle.
dynamicdeptname varchar2(30):= 'cco'; execute immediate 'select * dept dname '%' || dynamicdeptname || '%'
use bind variables, easier better (more efficient , secure)
single quotes need doubled-up inside single-quoted string.
example:
execute immediate 'select * dept dname ''%'' || :dname || ''%''' dept_rec using dynamicdeptname;
or use q-quote syntax avoid need double-up quotes:
execute immediate q'[select * dept dname '%' || :dname || '%']' dept_rec using dynamicdeptname;
Comments
Post a Comment