The Like operators in Oracle use '_' and '%' As wildcards, just Like this:
SELECT name FROM test_like WHERE name like'_ A %';
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:
- REGEXP_LIKE (x, pattern [, match_option])
- If the source string x matches the regular expression patternTrue. You can use match_option to modify the default matching option. This parameter can be set:
- -'C', Indicating that the matching time zone is case sensitive (default option)
- -'I', Indicating that the matching is case insensitive.
- -'N'Allows the use of operators that can match any character (usually'.')
- -'M', Uses x as a string that contains multiple rows
For example:
SELECT*FROMTest_regWHEREREGEXP_LIKE (Name,'(A) \ 1','I');
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:
- SELECT*FROMTest_regWHEREREGEXP_LIKE (Name,'A \ 1','I')
- ORA-12727: the backward reference in the regular expression is invalid
Finally, do not confuse the wildcards of the like operator with the regular expression syntax. That is to say, 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.
- SQL>SELECT*FROMTest_regWHEREREGEXP_LIKE (Name,'^ _ (A) \ 1','I');
- NAME
- ----------
Actually use:
- SQL>SELECT*FROMTest_regWHEREREGEXP_LIKE (Name,'^. (A) \ 1','I');
- NAME
- ----------
- SaAs
For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12