表中的第一行:
1A:CAD22021828,17:1B:RECEIVE GENERAL IND11 BEGUM ST:1C: C/O PNBB MAIN BRANCH 11 BEGUM ST 3-15A2:
表中的第二行:
:1A:/002429389016 CITY OF NAGAL AP IN 392H 329 :1E://NAGOLE STREET NAGAL AP :2A:/154510002 OFD DEPOSITORY LTD :
现在我希望将此数据加载到另一个表中,如下所示:
第一行:
1A CAD22021828,17
1B RECEIVE GENERAL IND 11 BEGUM ST /000061071257
1C C/O PNBB MAIN BRANCH 11 BEGUM ST 3-15A2
第二行:
1A /002429389016 CITY OF NAGAL AP IN 392H 329
1E //NAGOLE STREET NAGAL AO
2A /154510002 OFD DEPOSITORY LTD
我已经尝试过REGEXP_SUBSTR
SELECT
REGEXP_SUBSTR(mc_clob,':1A:([[:alnum:]]+\S+)') AS code1A,
REGEXP_SUBSTR(mc_clob,':1B:([[:alnum:]]+\s+)') AS code1B,
REGEXP_SUBSTR(mc_clob,':1C:([[:alnum:]]+\s+)') AS code1c
FROM tableA;
第一行:
1A CAD22021828,17
1B RECEIVE GENERAL IND 11 BEGUM ST /000061071257
1C C/O PNBB MAIN BRANCH 11 BEGUM ST 3-15A2
第二行:
1A /002429389016 CITY OF NAGAL AP IN 392H 329
1E //NAGOLE STREET NAGAL AO
2A /154510002 OFD DEPOSITORY LTD
这是一般问题how do i split delimited values的特例
尝试一下。我假设您在tableA
中有一些键-在这里我称之为“ id”。如果此表中没有唯一键,请告诉我,我将其重写为使用rowid
。
-- sample data
with tablea as (select 1 as id, ':1A:CAD22021828,17:1B:RECEIVE GENERAL IND11 BEGUM ST:1C: C/O PNBB MAIN BRANCH 11 BEGUM ST 3-15A2:' as mc_clob from dual
union select 2 as id, ':1A:/002429389016 CITY OF NAGAL AP IN 392H 329 :1E://NAGOLE STREET NAGAL AP :2A:/154510002 OFD DEPOSITORY LTD :' from dual)
-- query
SELECT id,
regexp_substr(mc_clob, '[^:]+', 1, level*2-1) as code,
trim(regexp_substr(mc_clob, '[^:]+', 1, level*2)) as val
FROM tableA
connect by regexp_substr(mc_clob, '[^:]+', 1, level*2) is not null
and PRIOR id = id
and PRIOR SYS_GUID() is not null;
输出:
ID CODE VALUE
1 1A CAD22021828,17
1 1B RECEIVE GENERAL IND11 BEGUM ST
1 1C C/O PNBB MAIN BRANCH 11 BEGUM ST 3-15A2
2 1A /002429389016 CITY OF NAGAL AP IN 392H 329
2 1E //NAGOLE STREET NAGAL AP
2 2A /154510002 OFD DEPOSITORY LTD
如果您的字段中有空白数据,此查询将无法很好地处理它。但也许会有所帮助。