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 escape ' in dynamic sql

Dinesh Rajasekharan-OracleOct 27 2011 — edited Nov 22 2012
Dear Experts ,

I am trying to escape single quote(') in dynamic sql but could not find a way , I used escape character / and two single quotes '' but it did not work .

The following is dynamic SQL I am try to generate :

SQL> select 'exec dbms_stats.gather_index_stats(ownname=>\'SYSADM\', indname=>\''||iname||'\', estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE);' from test_missing_index;
select 'exec dbms_stats.gather_index_stats(ownname=>'SYSADM', indname=>''||iname||'', estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE);' from test_missing_index
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected


The desired out put should be :

exec dbms_stats.gather_index_stats(ownname=>'SYSADM', indname=>'test_index', estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE);

Any help will be highly appreciated
This post has been answered by Frank Kulash on Oct 27 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 20 2012
Added on Oct 27 2011
5 comments
13,328 views