我有一个具有以下结构的表:
表格1
f_name f_content
test1.txt |0002434299|354534|535345345|05|||BCV RESULT # 174|Test 12%|
test2.txt |543566677|HTTYE|9w5w RRLL|05|||BBN RESULT # 144|Test 15#%|3
我需要使用管道(|)分隔f_content并放置字符串的适当位置。
输出表是:
f_name position value
test1.txt 1 (null)
test1.txt 2 0002434299
test1.txt 3 354534
test1.txt 4 535345345
test1.txt 5 05
test1.txt 6 (null)
test1.txt 7 (null)
test1.txt 8 BCV RESULT # 174
test1.txt 9 Test 12%
test1.txt 10 (null)
test2.txt 1 (null)
test2.txt 2 543566677
test2.txt 3 HTTYE
test2.txt 4 9w5w RRLL
test2.txt 5 05
test2.txt 6 (null)
test2.txt 7 (null)
test2.txt 8 BBN RESULT # 144
test2.txt 9 Test 15#%
test2.txt 10 3
我在table1中有超过500K的记录。每条记录有200多个管道。
有没有办法编写优化查询,以便它可以处理超过200个管道的500K记录而不填充撤消表空间?
是否可以编写SQL查询以块的形式处理并将其插入输出表中?
发布于 2019-05-23 15:34:58
您可以regexp_substr()
结合使用窗口分析功能connect by level <= regexp_count(f_content,'\|')
with t(f_name,f_content) as
(
select 'test1.txt','|0002434299|354534|535345345|05|||BCV RESULT # 174|Test 12%|'
from dual
union all
select 'test2.txt','|543566677|HTTYE|9w5w RRLL|05|||BBN RESULT # 144|Test 15#%|3'
from dual
)
select f_name,
level as position,
replace( regexp_substr(replace(f_content,'|',' |'),
'([^\|])+',
1,
level
),' ',null) as value
from t
connect by level <= regexp_count(f_content,'\|') + 1
and prior f_name = f_name and prior sys_guid() is not null
https://stackoverflow.com/questions/-100006794
复制相似问题