繁体   English   中英

PL Sql解析#字符

[英]PL Sql Parsing # Character

我在表中有一条记录,该表仅包含一列,并且它的列包含类似于字符串下的数据。

D#1001111068#112B#0010040130022013012111505444 ## 20130121110800#20130121115054#01#-## 240#用户名#用户名#20130124171831#20130130#6

在#个字符之间,每个字符串都在其他表中显示这样的一列。

D# 
1001111068#                          --Customer Number 
112B#                                --Procut Id 
0010040130022013012111505444#        --Serial Number 
#                                    --Order Number(empty record)     
20130121110800#                      --X Columns

我想解析这些项​​目并插入到其他表中。 怎么写这个。

您可以通过以下表达式提取第n个子字符串:

regexp_substr(source_string, '([^#]*)(#|$)', 1, n, '', 1)

完整查询:

create table your_table(
   source_string varchar2(4000)
);

insert into your_table
values('D#1001111068#112B#0010040130022013012111505444##20130121110800#20130121115054#01#-##240#username#username#20130124171831#20130130#6');

select 
  n,
  regexp_substr(source_string, '([^#]*)(#|$)', 1, n, '', 1) 
from your_table,
(
  select level as n from dual 
  connect by level <= (
    select max(regexp_count(source_string, '#')) + 1 
    from your_table
  )
) 
where n <= regexp_count(source_string, '#') + 1;

输出:

1   D
2   1001111068
3   112B
4   0010040130022013012111505444
5   (null)
6   20130121110800
7   20130121115054
8   01
9   -
10  (null)
11  240
12  username
13  username
14  20130124171831
15  20130130
16  6

小提琴

您要查找的函数是regexp_substr

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM