首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >拆分管道分隔字符串 - Oracle SQL

拆分管道分隔字符串 - Oracle SQL
EN

Stack Overflow用户
提问于 2019-05-23 06:28:28
回答 1查看 0关注 0票数 0

我有一个具有以下结构的表:

表格1

代码语言:javascript
复制
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并放置字符串的适当位置。

输出表是:

代码语言:javascript
复制
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查询以块的形式处理并将其插入输出表中?

EN

Stack Overflow用户

发布于 2019-05-23 15:34:58

您可以regexp_substr()结合使用窗口分析功能connect by level <= regexp_count(f_content,'\|')

代码语言:javascript
复制
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

Demo

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100006794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档