Good news or bad news?
God knows!!!
……
Oracle 10g SQL/PLSQL引入了正则表达式语法。有以下几个内置函数:
REGEXP_LIKE
REGEXP_SUBSTR
REGEXP_INSTR
REGEXP_REPLACE
到了11g,oracle引入了一个新的函数:
REGEXP_COUNT
正则表达式的强大功能就不说了,在Oracle10g之前,很多复杂的字符串操作编程需要在客户端应用中实现。
下面简要介绍这几个函数:
SQL Element Category Description
------------- ---------- -------------------------------------------------------------------------------------------------
REGEXP_LIKE Condition Searches a character column for a pattern.
Use this function in the WHERE clause of a query to return rows matching a regular expression.
The condition is also valid in a constraint or as a PL/SQL function returning a boolean.
The following WHERE clause filters employees with a first name of Steven or Stephen:
WHERE REGEXP_LIKE(first_name, '^Ste(v|ph)en$')
REGEXP_REPLACE Function Searches for a pattern in a character column and replaces each occurrence of that pattern with the specified string.
The following function call puts a space after each character in the country_name column:
REGEXP_REPLACE(country_name, '(.)', '\1 ')
REGEXP_INSTR Function Searches a string or substring for a given occurrence of a regular expression pattern (a substring)
and returns an integer indicating the position in the string or substring where the match is found.
You specify which occurrence you want to find and the start position.
The following function call performs a boolean test for a valid email address in the email column:
REGEXP_INSTR(email, '\w+@\w+(\.\w+)+') > 0
REGEXP_SUBSTR Function Searches a string or substring for a given occurrence of a regular expression pattern (a substring)
and returns the substring itself.You specify which occurrence you want to find and the start position.
The following function call uses the x flag to match the first string by ignoring spaces in the regular expression:
REGEXP_SUBSTR('oracle', 'o r a c l e', 1, 1, 'x')
REGEXP_COUNT Function Returns the number of times a pattern appears in a string. You specify the string and the pattern.
You can also specify the start position and matching options (for example, c for case sensitivity).
The following function call returns the number of times that e (but not E) appears in the string 'Albert Einstein',
starting at character position 7 (that is, one):
REGEXP_COUNT('Albert Einstein', 'e', 7, 'c') |
正则表达式功能强大,内容繁多,要想学好正则表达式需要花一定的力气,这是一个开始,有机会做个系列学习。
Refer to:
———
Oracle? Database Advanced Application Developer’s Guide 11g Release 1 (11.1)
Oracle? Database SQL Language Reference 11g Release 1 (11.1)
http://www.opengroup.org/onlinepubs/007908799/xbd/re.html
Oracle Regular Expressions Pocket Reference by Jonathan Gennick, O’Reilly & Associates
Mastering Regular Expressions by Jeffrey E. F. Friedl, O’Reilly & Associates
http://www.adp-gmbh.ch/blog/2005/december/22.html

Recent Comments