ESCAPE clause in SQL DB2

ESCAPE in DB2 Mainframes:

In SQL the percent sign(%) and the under score(_) has special meaning.

%’ – represents any set of characters

_ – under score represents any single character.

Ex: select * from emp
where email like 'reddy_%';

This will display all the email ids starting with reddy like reddy123,reddy_34 etc. But here the requirement is to display the email ids starting with ‘reddy_’.

As in db2 underscore represents a single character it displays all the mail ids starting with reddy.

In such scenarios ESACPE clause is used to get the original meaning of _ or %.

By using the ESACPE the SQL looks like below:

select * from emp

where email like ‘reddy+_%’; ESCAPE ‘+’;

Now the above SQL displays only the mail ids starting with ‘reddy_’ like reddy_123, reddy_345 etc.

Get the full details  @

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/DSNSQ0F4/3.15.6.3

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *