Oracle : Escape character in sqlplus

Escape character in sql*plus :-

By default the escape character is set to backslash ( \ )
The escape character instructs SQL*Plus to treat the substitution character as an ordinary character rather than as a request for variable substitution. You can set it any other character which is not alphanumeric.

To use the Default Escape Character :-
e.g.
SQL>select * from TABLE_NAME
where COLUMN_NAME like '_ill';
The above query will return hill, mill, will

If you really want to search for '_ill', set an escape character as follows
SQL>select * from TABLE_NAME
where COLUMN_NAME like '\_ill';The above query will only match '_ill'


To Change or Set the Escape Character :-
set ESCAPE [character/ON/OFF]
Defines the escape character. OFF undefines. ON enables.
SQL> set ESCAPE #
The escape character cannot be alphanumeric or whitespace. If you try to do it you will get sqlplus error SP2-0272. SP2 - 0272 : escape character cannot be alphanumeric or whitespace
So the escape characters can be any one of ! @ # $ % ^ & * ( ) _.

Then use the escape character in front of the character you want escaped.

e.g.
SQL>select * from TABLE_NAME
where COLUMN_NAME like '_ill';
The above query will return hill, mill, will

If you really want to search for '_ill', set an escape character as follows
SQL> set ESCAPE #
SQL>select * from TABLE_NAME
where COLUMN_NAME like '#_ill';
The above query will only match '_ill'

Comments

Anonymous said…
By default escape char is '\' and not '/'
Anonymous said…
Isn't it / in *NIX and \ in Windows