How To Escape Special Characters in SQL statements?

Answer

There are a number of special characters that needs to be escaped (protected), if you want to include them in a character string. Here are some basic character escaping rules:

► The escape character () needs to be escaped as (\).
► The single quote (') needs to be escaped as (') or ('') in single-quote quoted strings.
► The double quote (") needs to be escaped as (") or ("") in double-quote quoted strings.
► The wild card character for a single character (_) needs to be escaped as (_).
► The wild card character for multiple characters (%) needs to be escaped as (%).
► The tab character needs to be escaped as (t).
► The new line character needs to be escaped as (n).
► The carriage return character needs to be escaped as (r).

Here are some examples of how to include special characters:

SELECT 'It''s Sunday!' FROM DUAL;
It's Sunday!

SELECT 'Allo, C'est moi.' FROM DUAL; Allo, C'est moi.

SELECT 'MontTuetWedtThutFri' FROM DUAL;
Mon Tue Wed Thu Fri

All sql dba Questions

Ask your interview questions on sql-dba

Write Your comment or Questions if you want the answers on sql-dba from sql-dba Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---