那时就会很羡慕java程序员可以使用一个正则表达式轻松搞定。10g中,再也不需要这么复杂了, oracle也提供了几个正则表达式函数,大大方便了开发人员:REGEXP_LIKE、REGEXP_REPLACE、REGEXP_INSTR、REGEXP_SUBSTR,分别用于模糊匹配、代替、插入、截取字符串。关于正则表达式的规则这就不详细描述了, 可以查相关资料得到。简单举例。以上面例子为例,我们的查询语句可以写成:Select username from t_userinfo where (phonenumber like ‘135%8888’ or phonenumber like ‘136%8888’ or phonenumber like ‘137%8888’ or phonenumber like ‘138%8888’) and length(phonenumber) = 13;
来源: www.HelloDBA.comSQL> create table t_userinfo (username varchar2(10), phonenumber varchar2(13)); Table created SQL> insert into t_userinfo values ('zhansan', '13012323434'); 1 row inserted SQL> insert into t_userinfo values ('lisi', '13512348888'); 1 row inserted SQL> insert into t_userinfo values ('wangwu', '13912328888'); 1 row inserted SQL> insert into t_userinfo values ('zhaoliu', '13743218888'); 1 row inserted SQL> insert into t_userinfo values ('sunqi', '1361234888'); 1 row inserted SQL> commit; Commit complete SQL> Select username, phonenumber from t_userinfo 2 where REGEXP_LIKE(phonenumber, '13[5-8][0-9][0-9][0-9][0-9]8{4}'); USERNAME PHONENUMBER ---------- ------------- lisi 13512348888 zhaoliu 13743218888