LIKE 模糊查詢
字元匹配操作可以使用萬用字元 “%” 和 “_”:
%:表示任意個字元,包括零個;
_:表示一個任一字元;
- Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
- Connected as scott
-
- SQL> select * from dept;
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
- 10 ACCOUNTING NEW YORK
- 20 RESEARCH DALLAS
- 30 SALES CHICAGO
- 40 OPERATIONS BOSTON
"%" 和 "_"示範:
- SQL> select * from dept where DNAME like '_A%';
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
- 30 SALES CHICAGO
ESCAPE 示範:
- SQL> insert into dept values(50,'BEIJING','JIANG%XI');
-
- 1 row inserted
-
- SQL> select * from dept;
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
- 10 ACCOUNTING NEW YORK
- 20 RESEARCH DALLAS
- 30 SALES CHICAGO
- 40 OPERATIONS BOSTON
- 50 BEIJING JIANG%XI
-
- SQL> select * from dept where loc like '%\%%' escape '\';
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
- 50 BEIJING JIANG%XI
-
- SQL> select * from dept where loc like '%e%%' escape 'e';
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
- 50 BEIJING JIANG%XI
更多Oracle相關資訊見Oracle 專題頁面 http://www.bkjia.com/topicnews.aspx?tid=12