一定要注意操作符的优先级,以REGEXP_LIKE为例:
--^ , $在非中括号中使用时,表示字符的开始与结束
SQL> select * from reg;
ID NAME
---------- --------------------
1 work hard
1 hard
1 work Hard
1 Hard
1 Hards
SQL> select * from reg where regexp_like(name,'hard$');
ID NAME
---------- --------------------
1 work hard
1 hard
SQL> select * from reg where regexp_like(name,'^hard$');
ID NAME
---------- --------------------
1 hard
SQL> select * from reg where regexp_like(name,'^H|hard$'); --这里注意操作符的优先级。
ID NAME
---------- --------------------
1 work hard
1 hard
1 Hard
1 Hards
SQL> select * from reg where regexp_like(name,'^H|hard'); --这里注意操作符的优先级。
ID NAME
---------- --------------------
1 work hard
1 hard
1 Hard
1 Hards
SQL> select * from reg where regexp_like(name,'^hard$');
ID NAME
---------- --------------------
1 hard
SQL> select * from reg where regexp_like(name,'hard$');
ID NAME
---------- --------------------
1 work hard
1 hard
SQL> select * from reg where regexp_like(name,'hard');
ID NAME
---------- --------------------
1 work hard
1 hard
SQL> select * from reg where regexp_like(name,'Hard');
ID NAME
---------- --------------------
1 work Hard
1 Hard
1 Hards
SQL> select * from reg where regexp_like(name,'Hard$');
ID NAME
---------- --------------------
1 work Hard
1 Hard
SQL> select * from reg where regexp_like(name,'^Hard$');
ID NAME
---------- --------------------
1 Hard
--^在[]中使用时表示不接受该字符集合
SQL> select * from reg;
ID NAME
---------- --------------------
1 work hard
1 hard
1 work Hard
1 Hard
1 Hards
SQL> select * from reg where regexp_like(name,'[^H|hard]');
ID NAME
---------- --------------------
1 work hard
1 work Hard
1 Hards
SQL> select * from reg where regexp_like(name,'[^hard]');
ID NAME
---------- --------------------
1 work hard
1 work Hard
1 Hard
1 Hards
SQL> select * from reg where regexp_like(name,'[^Hard]');
ID NAME
---------- --------------------
1 work hard
1 hard
1 work Hard
1 Hards
SQL> select * from reg where regexp_like(name,'w.[Hard]');
ID NAME
---------- --------------------
1 work hard
1 work Hard
SQL> select * from reg where regexp_like(name,'w*[Hard]');
ID NAME
---------- --------------------
1 work hard
1 hard
1 work Hard
1 Hard
1 Hards
SQL> select * from reg where regexp_like(name,'work [Hard]');
ID NAME
---------- --------------------
1 work Hard
SQL> select * from reg where regexp_like(name,'work [^Hard]'); --^在[]中使用时表示不接受该字符集合
ID NAME
---------- --------------------
1 work hard
整理自网络