Use the Regular Expression Function REGEXP_LIKE in Oracle to query

Source: Internet
Author: User
The Regular Expression Function REGEXP_LIKE is used in Oracle queries, and the Like operator in Oracle uses

The Regular Expression Function REGEXP_LIKE is used in Oracle queries, and the Like operator in Oracle uses

The Like operators in Oracle use '_' and '%' As wildcards, just Like this:

That is, all rows with the 2nd letters a in the name column of the test_like table are matched. However, note that Oracle matches the time zone in Case sensitivity. That is to say, the line name = 'saas 'cannot be queried during the above query.

The regular expression function provided by Oracle10g can solve this problem well. Of course, this is not the only advantage of using a regular expression function. In fact, it is much more powerful than the Like operator.

The syntax of regular expressions is unnecessary. Currently, most languages support regular expressions.

The following describes how to use the regular expression function REGEXP_LIKE in Oracle:

For example:

The preceding SQL statement matches the name column in The test_reg table with two consecutive characters 'A' (Case Insensitive), such as name = 'saas '. In addition, we also use the back reference syntax in the Regular Expression -- \ n to repeat the content of the last match n times. Here () \ 1 indicates matching two consecutive characters 'A '.

Note that the double brackets must be used for subsequent references. Otherwise, the following result is displayed:

Finally, do not confuse the wildcards of the like operator with the regular expression syntax, that is, do not use wildcards in the LIKE operator in a regular expression. If this is done, unknown results will be obtained ,, because '_' and '%' are matched by regular expressions as common characters.

For example, if the following SQL statement is used to obtain the record name = 'saas ', the actual query result is null.

Actually use:

For more information about Oracle, see the Oracle topic page? Tid = 12

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: 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.