ITPub博客

首页 > 数据库 > Oracle > SQL查询的转义方法(一)

SQL查询的转义方法(一)

原创 Oracle 作者:nathanzhn 时间:2014-08-21 11:52:39 0 删除 编辑
drop table test1;
create table test1(a int, b varchar2(50));
insert into test1 values(1,'nihao %25 haha');
insert into test1 values(1,'nihao ''25'' haha');
commit;

1、查询b列含有%的行

If you want to find strings containing the % character, you will need to escape the % character within your pattern so that it isn't treated as a wildcard. To do so, you will need to use the ESCAPE clause to let Oracle know which character you have chosen as the escape character:


select * from test1
where b like '%\%%' escape '\';

2、查询b列含有单引号'的行
select * from test1
where b like '%''%' escape '\';

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

下一篇: LIKE / NOT LIKE 改写
请登录后发表评论 登录
全部评论

注册时间:2014-01-23

  • 博文量
    49
  • 访问量
    286475