oracle中的文本提取
text extraction in oracle
我有一个字符串作为
My Id no is ++ 789456123456 <<.This is my 2nd no 987658974569
new page
我要提取789456123456
,987658974569
作为逗号分隔的数据。它们的长度为 12 位数字
select
regexp_replace ('My Id no is ++ 789456123456 <<.This is my 2nd no 987658974569 new page' ,
`'.*([[:digit:]]{12}) .*([[:digit:]]{12}).*' , ' ')
from dual
解释:
regexp_replace
--> 函数可以处理替换的正则表达式。
'.*([[:digit:]]{12}) .*([[:digit:]]{12}).*'
--> 这个表达式查找 digit(0-0)
并且 {12}
是在这种情况下前一个字符应该重复的次数 12.
()
<-- 用于记忆以后可以用到的模式
<-- 第一组和第二组
如果两个数字之间没有空格,此解决方案将不起作用
编辑:更新代码以处理换行符
select regexp_replace ( translate (col1 , chr(10)||chr(11)||chr(13), ' '), '.*([[:digit:]]{12}) .*([[:digit:]]{12}).*' , ',')
from
(
select 'We have received a consent for account no 540400005897 ,
detail of which are given below: 895647895623
Detail: Please do not share this with anyone. Thank You.' as col1
from dual
)
我有一个字符串作为
My Id no is ++ 789456123456 <<.This is my 2nd no 987658974569
new page
我要提取789456123456
,987658974569
作为逗号分隔的数据。它们的长度为 12 位数字
select
regexp_replace ('My Id no is ++ 789456123456 <<.This is my 2nd no 987658974569 new page' ,
`'.*([[:digit:]]{12}) .*([[:digit:]]{12}).*' , ' ')
from dual
解释:
regexp_replace
--> 函数可以处理替换的正则表达式。
'.*([[:digit:]]{12}) .*([[:digit:]]{12}).*'
--> 这个表达式查找 digit(0-0)
并且 {12}
是在这种情况下前一个字符应该重复的次数 12.
()
<-- 用于记忆以后可以用到的模式
<-- 第一组和第二组
如果两个数字之间没有空格,此解决方案将不起作用
编辑:更新代码以处理换行符
select regexp_replace ( translate (col1 , chr(10)||chr(11)||chr(13), ' '), '.*([[:digit:]]{12}) .*([[:digit:]]{12}).*' , ',')
from
(
select 'We have received a consent for account no 540400005897 ,
detail of which are given below: 895647895623
Detail: Please do not share this with anyone. Thank You.' as col1
from dual
)