SQL查詢的轉義方法(一)

nathanzhn發表於2014-08-21
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部落格 ” ,連結:http://blog.itpub.net/26521853/viewspace-1255197/,如需轉載,請註明出處,否則將追究法律責任。

相關文章