I have a records in table which contains only one column,and its column contains data like under string.
D#1001111068#112B#0010040130022013012111505444##20130121110800#20130121115054#01#-##240#username#username#20130124171831#20130130#6
Between # chracters every string show one column in other table like that.
D#
1001111068# --Customer Number
112B# --Procut Id
0010040130022013012111505444# --Serial Number
# --Order Number(empty record)
20130121110800# --X Columns
I want to parse these items and insert to other table. How to write this.
You can extract n-th substring by the following expression:
regexp_substr(source_string, '([^#]*)(#|$)', 1, n, '', 1)
Full query:
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;
Output:
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 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.