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!

Escaping the single quote

Steve_74Oct 31 2012 — edited Oct 31 2012
Oracle version: 11.2.0.2
create table test_tab (col1 varchar2(15));

insert into test_tab values ('YELLOW');
insert into test_tab values ('GREEN');
insert into test_tab values ('RED');
insert into test_tab values ('BLUE');
commit;

SQL>  select * from test_tab;

COL1
---------------
YELLOW
GREEN
RED
BLUE
I would like the values of the above table to be printed with

a single quote surrounding them followed by a commma and a space then right paranthesis.

Expected output 1 :
Colours are ('YELLOW', )
Colours are ('GREEN', )
Colours are ('RED', )
Colours are ('BLUE', )
Related question:

From googling , I gather that , to escape a single quote, just add another one to it. But my following attempts have failed.

For the above requirement , I was doing some experiments to get at least the following printed
Expected output 2:
My car is 'white'
This is what i Tried
SQL> select 'My car is '''white from dual;

WHITE
-----------
My car is '

SQL> select 'My car is ''white'' from dual;
ERROR:
ORA-01756: quoted string not properly terminated



SQL> select 'My car is '''white'' from dual;
select 'My car is '''white'' from dual
                          *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected


SQL> select 'My car is '''white''' from dual;
ERROR:
ORA-01756: quoted string not properly terminated
This post has been answered by Frank Kulash on Oct 31 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 28 2012
Added on Oct 31 2012
6 comments
6,740 views