How to escape special characters in Oracle ? [akadia]

If you want to retrieve TABLE_NAMES from ALL_TABLES where the table name is like 'ADD_' using the following query, you may notice that the query is returning ADDRESS and ADD_CODES:

create table address (p1 number);
create table add_codes (p1 number);

select distinct table_name
from all_tables
where table_name like 'ADD_%';

TABLE_NAME
----------
ADDRESS
ADD_CODES

If you try to escape the '_' character with the following query, you will still get the same result.

select distinct table_name from all_tables
where table_name like 'ADD_%'

Therefore the question is: How do you use LIKE to find data that contains an underscore or percent sign ? The answer is to escape the underscore and/or percent sign in the LIKE template. You have to designate what character you would like to use via the ESCAPE keyword. A slash is commonly used, but any character would actually work:

select distinct table_name
from all_tables
where table_name like 'ADD_%' ESCAPE '';


请使用浏览器的分享功能分享到微信等