SQL ESCAPE: Usage & Examples

In SQL, ESCAPE is a keyword used to specify an escape character for escaping special characters. Typically, ESCAPE is used with the LIKE statement to specify the escape character, ensuring that any wildcards or escape characters in the search string are treated as regular characters.

For example, if you want to search for a string in a LIKE statement that contains the % character, you can use the ESCAPE keyword to specify an escape character, as shown below:

SELECT * FROM table_name WHERE column_name LIKE '%\%%' ESCAPE '\';

In the examples above, we use the backslash \ as an escape character to ensure that the % character is treated as a regular character, rather than a wildcard.

bannerAds