oracle10g new feature--regular expression--go

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.