As Yahia points out, you should always use bind variables and not dynamically collect SQL queries dynamically. This is the right way to protect yourself from SQL injection attacks. Failure provides a much lower level of protection.
However, assuming you are using Oracle 10.1 or later, you can use q quoting syntax. Sort of
1 select q'[This is a string with an embedded ']' str 2* from dual SQL> / STR ----------------------------------- This is a string with an embedded '
You can replace characters [and] with the number of other characters, depending on what characters can be displayed in the string
1 select q'<This is a string with an embedded '>' str 2* from dual SQL> / STR ----------------------------------- This is a string with an embedded ' SQL> ed Wrote file afiedt.buf 1 select q'{This is a string with an embedded '}' str 2* from dual SQL> / STR ----------------------------------- This is a string with an embedded '
source share