0

我在表中有一个记录,它只包含一列,它的列包含字符串下的数据。

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

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

4

2 回答 2

1

您可以通过以下表达式提取第 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 天
2 1001111068
3 112B
4 0010040130022013012111505444
5(空)
6 20130121110800
7 20130121115054
8 01
9 -
10(空)
11 240
12 用户名
13 用户名
14 20130124171831
15 20130130
16 6

小提琴

于 2013-03-09T14:09:03.023 回答
0

您正在寻找的功能是regexp_substr

于 2013-03-09T13:57:30.437 回答