How to select value contain character ' in statement

Viewed 110

How to select statement when the value contain special character " ' " in between of the value.

Select * from tablename where columnone= 'He's'

The statement give me error, because have character(') in the value:

ORA-00933: SQL command not properly ended

1 Answers

The traditional way is to "Doubling-Up" of Single Quotes,

select * 
  from tablename 
 where columnone= 'He''s';

Alternatively you can use q operator for quoting string literals containing quotes. Using this you can put the actual string within q'[actual string]'

select * 
  from tablename 
 where columnone= q'[He's]';

Other variations with examples of using q operator can be found here

Related