0

テーブルに1つの列のみを含むレコードがあり、その列にはunderstringのようなデータが含まれています。

D#1001111068#112B#0010040130022013012111505444 ## 20130121110800#20130121115054#01#-## 240#username#username#20130124171831#20130130#6

#文字の間では、すべての文字列がそのような他のテーブルの1つの列を示します。

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 D
2 1001111068
3 112B
4 0010040130022013012111505444
5(null)
6 20130121110800
7 20130121115054
8 01
9-
10(null)
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 に答える