我尝试使用Oracle SQL使用REGEXP_SUBSTR从clob中提取多个字符串。
clob_field示例:
xxx xxx"xxxxxxxYY=1234xxxxx.xxxx.xxxx"xx xxxxxxxxxxxxxx
xxxxx"xxxxxxxYY=2345xxxxx.xxxxx.xxxxxxxxxxxx"xxxx xxxxxxxxxx
xxx xxxxx"xxxxxxxxxxxxxxYY=34567xxxxx.xxx.xxxxx"xxxxxxxxxxxx
xxxx"xxxxxYY=4567xx.xxxxxx"xxxxxxxxxx xxxxxxxxxxx xxxxxxxx
我试过了:
select a.id, regexp_substr(b.clob_field,'YY=',",[^"]+"') "clob_result"
from table1 a, table2 b
where a.id = b.id
加入查询示例的所需结果是:
id clob_result
1 xxxxxxxYY=1234xxxxx.xxxx.xxxx
1 xxxxxxxYY=2345xxxxx.xxxxx.xxxxxxxxxxxx
1 xxxxxxxxxxxxxxYY=34567xxxxx.xxx.xxxxx
1 xxxxxYY=4567xx.xxxxxx
不清楚如何搜索包含' YY ='的字符串,并返回用"引用的整个字符串;在开始和结束。
非常感谢任何帮助!
答案 0 :(得分:0)
select
regexp_substr(string,'"([^"]*YY=[^"]*)"', 1, 1, '', 1) as clob_result
from your_table
select
id, occ,
regexp_substr(string,'"([^"]*YY=[^"]*)"', 1, occ, '', 1) as clob_result
from your_table,
(select level occ from dual connect by level < 99)
where occ <= regexp_count(string,'"([^"]*YY=[^"]*)"')
order by id, occ
答案 1 :(得分:0)
您可以使用REGEXP_REPLACE获取多个出现以及周围的双引号。然后,您可以使用TRIM / REPLACE删除它们。
with x(y) as (
select 'xxxx"xxxxxxxYY=1234xxxxx.xxxx.xxxx"xx xxxxx' from dual union all
select 'xx"xxxxxxxYY=2345xxxxx.xxxxx.xxxxxxxxxxxx"xxx xxx' from dual union all
select 'xxx"xxxxxxxxxxxxYY=34567xxxxx.xxx.xxxxx"xxxxxxxxx' from dual union all
select 'x"xxxxxYY=4567xx.xxxxxx"xx"xxxxxYY=8787xx.xxxx"xx' from dual
)
select y, replace(trim('"' from regexp_replace(y,
'("[^"]*YY=[^"]*")|(.)',
'\1'
) -- this will remove anything that is not matched by the regex
),
'""',
','
) as clob_result
from x
<强> Results 强>:
| Y | CLOB_RESULT |
|---------------------------------------------------|-------------------------------------------|
| xxxx"xxxxxxxYY=1234xxxxx.xxxx.xxxx"xx xxxxx | xxxxxxxYY=1234xxxxx.xxxx.xxxx |
| xx"xxxxxxxYY=2345xxxxx.xxxxx.xxxxxxxxxxxx"xxx xxx | xxxxxxxYY=2345xxxxx.xxxxx.xxxxxxxxxxxx |
| xxx"xxxxxxxxxxxxYY=34567xxxxx.xxx.xxxxx"xxxxxxxxx | xxxxxxxxxxxxYY=34567xxxxx.xxx.xxxxx |
| x"xxxxxYY=4567xx.xxxxxx"xx"xxxxxYY=8787xx.xxxx"xx | xxxxxYY=4567xx.xxxxxx,xxxxxYY=8787xx.xxxx |