Chinaunix首页 | 论坛 | 博客
  • 博客访问: 67836
  • 博文数量: 21
  • 博客积分: 466
  • 博客等级: 下士
  • 技术积分: 175
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-21 19:13
文章分类
文章存档

2011年(21)

我的朋友

分类: Oracle

2011-08-03 14:55:40

   The following example examines phone_number, looking for the pattern xxx.xxx.xxxx. Oracle reformats this pattern with (xxx)xxx-xxxx.

SELECT 
       REGEXP_REPLACE(phone_number,
                                        '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})' ,              
                                         '(\1) \2-\3') "REGEXP_REPLACE" 
FROM employees; 

REGEXP_REPLACE
 -------------------------------------------------------------------------------- 
(515) 123-4567 
(515) 123-4568
 (515) 123-4569 
(590) 423-4567

这一题主要考察了正则表达式函数中元字符“\n"(n是一个正整数)的用法。
Oracle® Database Application Developer's Guide - Fundamentals 10g Release 2 (10.2)对\n的解释如下:

\n

Backreference

Matches the nth preceding subexpression, that is, whatever is grouped within parentheses, where n is an integer from 1 to 9. The parentheses cause an expression to be remembered; a backreference refers to it. A backreference counts subexpressions from left to right, starting with the opening parenthesis of each preceding subexpression. The expression is invalid if the source string contains fewer than n subexpressions preceding the \n.

Oracle supports the backreference expression in the regular expression pattern and the replacement string of the REGEXP_REPLACE function.

The expression (abc|def)xy\1 matches the stringsabcxyabc and defxydef, but does not matchabcxydef or abcxy.

A backreference enables you to search for a repeated string without knowing the actual string ahead of time. For example, the expression^(.*)\1$ matches a line consisting of two adjacent instances of the same string.


英语解释不明白的可以和我留言,我们共同探讨
阅读(1188) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~