Oracle like 模糊查詢

來源:互聯網
上載者:User

LIKE 模糊查詢

字元匹配操作可以使用萬用字元 “%” 和 “_”:

%:表示任意個字元,包括零個;

_:表示一個任一字元;

  1. Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0    
  2. Connected as scott   
  3.   
  4. SQL> select * from dept;   
  5.     
  6. DEPTNO DNAME          LOC   
  7. ------ -------------- -------------   
  8.     10 ACCOUNTING     NEW YORK   
  9.     20 RESEARCH       DALLAS   
  10.     30 SALES          CHICAGO   
  11.     40 OPERATIONS     BOSTON  

"%" 和 "_"示範:

  1. SQL> select * from dept where DNAME like '_A%';   
  2.     
  3. DEPTNO DNAME          LOC   
  4. ------ -------------- -------------   
  5.     30 SALES          CHICAGO  

ESCAPE 示範:

  1. SQL> insert into dept values(50,'BEIJING','JIANG%XI');   
  2.     
  3. 1 row inserted   
  4.     
  5. SQL> select * from dept;   
  6.     
  7. DEPTNO DNAME          LOC   
  8. ------ -------------- -------------   
  9.     10 ACCOUNTING     NEW YORK   
  10.     20 RESEARCH       DALLAS   
  11.     30 SALES          CHICAGO   
  12.     40 OPERATIONS     BOSTON   
  13.     50 BEIJING        JIANG%XI   
  14.   
  15.  SQL> select * from dept where loc like '%\%%' escape '\';   
  16.     
  17. DEPTNO DNAME          LOC   
  18. ------ -------------- -------------   
  19.     50 BEIJING        JIANG%XI   
  20.   
  21.  SQL> select * from dept where loc like '%e%%' escape 'e';   
  22.     
  23. DEPTNO DNAME          LOC   
  24. ------ -------------- -------------   
  25.     50 BEIJING        JIANG%XI   

更多Oracle相關資訊見Oracle 專題頁面 http://www.bkjia.com/topicnews.aspx?tid=12

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.