[英]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.