0

I have a query in the form

SELECT REPLACE(text, 'a','b') 
FROM DUAL;

if the string text = a','b','c

How do I place the string in the replacd function so that it runs correctly?

user126885
  • 157
  • 1
  • 2
  • 10

2 Answers2

2

Like this using the alternative quote operator: test := q'[a','b','c]';

Or:

SELECT REPLACE(q'[a','b','c]', 'a','b') 
FROM DUAL;

More info here.

Here's another way to prove it in Sqlplus:

SQL> declare
     test varchar2(15) := q'[a','b','c]';
   begin
   dbms_output.put_line(REPLACE(test, 'a', 'b'));

   end;
   /

b','b','c

PL/SQL procedure successfully completed.

SQL>
Gary_W
  • 9,933
  • 1
  • 22
  • 40
0

Escape each single quote with a second single quote:

SELECT REPLACE( 'a'',''b'',''c','a','b') FROM DUAL
MT0
  • 143,790
  • 11
  • 59
  • 117