SQL查询的转义方法(一)

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 '\';
请使用浏览器的分享功能分享到微信等