When querying, it is sometimes necessary to follow certain special rules to find a string, for example, you may need to query the third 5-8, the last four bits of ' 8888 ' all phones. Before 9i, you may need to write a very complex condition:
Select username from t_userinfowhere (phonenumber like ' 135%8888 ' or phonenumber like ' 136%8888 ' or phonenumber like ' 137%88 "or phonenumber like ' 138%8888 ') and length (phonenumber) = 13;
Then you'll be envious. Java programmers can easily use a regular expression. 10g, no longer need to be so complicated, Oracle also provides several regular expression functions, greatly facilitated by developers: Regexp_like, Regexp_replace, Regexp_instr, REGEXP_SUBSTR, respectively, for fuzzy matching, Replaces, inserts, and intercepts strings. Rules on regular expressions This is not described in detail, you can check the relevant information obtained. A simple example. In the example above, our query statements can be written as:
Sql> CREATE TABLE T_userinfo (username varchar2 (Ten), PhoneNumber VARCHAR2 (13)); Table createdsql> INSERT INTO t_userinfo values (' Zhansan ', ' 13012323434 '); 1 row insertedsql> insert INTO T_userinfo VALUES (' Lisi ', ' 13512348888 '); 1 row insertedsql> insert into t_userinfo values (' Wangwu ', ' 13912328888 '); 1 row insert edsql> INSERT into t_userinfo values (' Zhaoliu ', ' 13743218888 '); 1 row insertedsql> insert into t_userinfo values (' s Unqi ', ' 1361234888 '); 1 row insertedsql> commit; Commit completesql> Select username, phonenumber from T_userinfo2 where Regexp_like (PhoneNumber, ' 13[5-8][0-9][0-9][ 0-9][0-9]8{4} '); USERNAME phonenumber-----------------------Lisi 13512348888zhaoliu 13743218888
oracle10g new feature--regular expression--go