Thursday, November 03, 2011

Apostrophe / Single Quote

Tested on an Oracle 11 database. If you want to include an apostrophe in your data, you need to precede it with another apostrophe:

SQL> create table with_apostrophes
  2  (name varchar2(10))
  3  /
 
Table created.
 
SQL>

This does not work:

SQL> insert into with_apostrophes
  2  values ('O'Connor')
  3  /
ERROR:
ORA-01756: quoted string not properly terminated
 
SQL>

But this does:

SQL> insert into with_apostrophes
  2  values ('O''Donnell')
  3  /
 
1 row created.
 
SQL> select * from with_apostrophes
  2  /
 
NAME
----------
O'Donnell
 
SQL>

No comments:

Post a Comment