ITPub博客

首页 > 数据库 > Oracle > 正则表达式之regexp_replace

正则表达式之regexp_replace

原创 Oracle 作者:swq618 时间:2015-06-24 23:51:00 0 删除 编辑
> 21. View the Exhibit and examine the details of the EMPLOYEES table.
Evaluate the following SQL statement:
SELECT phone_number,
REGEXP_REPLACE(phone_number,'([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})', '(\1) \2?\3')
"PHONE NUMBER"
FROM employees?
The query was written to format the PHONE_NUMBER for the employees. Which option would be the
correct format in the output?
A. xxx?xxx?xxxx
B. (xxx) xxxxxxx
C. (xxx) xxx?xxxx
D. xxx?(xxx)?xxxx
Answer: C


解析:

REGEXP_REPLACE( 字符串 , 对字符串进行匹配的正则表达式 , 对应输出格式的正则表达式 )

(650.507.9833, '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})','(\1) \2\3' )

( [[:digit:]] {3} ) \.

子表达式开始匹配任何数字出现 3 次子表达式结束转义字符 '.' 第一部分650 .

( [[:digit:]] {3} ) \.

子表达式开始匹配任何数字出现 3 次子表达式结束转义字符 '.' 第二部分507 .

( [[:digit:]] {4} )

子表达式开始匹配任何数字出现 4 次子表达式结束第三部分9833

( \1 ) \2 - \3

( 前面匹配的第一部分 ) [ 空格 ] 前面匹配的第一部分 - 前面匹配的第一部分

( 650 ) 507 - 9833

A. xxx-xxx-xxxx

B. (xxx) xxxxxxx

C. (xxx) xxx-xxxx(right)        '(\1) \2-\3' 这个格式很说明问题

D. xxx-(xxx)-xxxx

测试结果:




来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29674916/viewspace-1711179/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: code
下一篇: 父表与子表
请登录后发表评论 登录
全部评论

注册时间:2014-05-24

  • 博文量
    108
  • 访问量
    289823