-2

I need to find a below record

O'GRAD

I wanted to use LIKE

LIKE 'O'GRAD'

But i come across a problem with apostrophe. What would be the best way around it?

Doniu
  • 85
  • 1
  • 10

2 Answers2

0

Double up the apostrophe

LIKE 'O''GRAD'

or use the Q syntax

LIKE q'{O'GRAD}'
Connor McDonald
  • 10,418
  • 1
  • 11
  • 16
0

if your Oracle DB version is 10g or upper you may use :

select * 
  from mytable t
 where t.col1 like '%'||q'$O'GRAD$'||'%';
/

or classically add an extra quote to existing quote

select * 
  from mytable t
 where like '%'||'O''GRAD'||'%';
/

to overcome the single quotation mark problem.

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55