ITPub博客

首页 > Linux操作系统 > Linux操作系统 > How to escape special characters in Oracle ? [akadia]

How to escape special characters in Oracle ? [akadia]

原创 Linux操作系统 作者:jlandzpa 时间:2019-07-19 08:36:01 0 删除 编辑

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 '';


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/936/viewspace-60612/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2001-10-12

  • 博文量
    268
  • 访问量
    172264