用正则表达式提取clob里的文本格式记录集

前端之家收集整理的这篇文章主要介绍了用正则表达式提取clob里的文本格式记录集前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

表结构如下

sql> desc test;
Name Type Nullable Default Comments 
---- ---- -------- ------- -------- 
C1   CLOB Y 

sql> select count(*) from test;
  COUNT(*)
----------
         1

字段中内容

SU.SYSTEM_USER_CODE||'|#|'||S.STAFF_NAME||'|#|'||SU.STATUS_CD||'|#|'||SU.CHANNEL_ID||'|#|'||SU.LAN_ID
01|#|政企|#|1000|#|13378|#|1407
02|#|政企|#|1000|#|13383|#|1407
01|#|路|#|1100|#|10093|#|1401
54|#|2354|#|1100|#|111|#|14
55|#|2355|#|1100|#|111|#|14
56|#|2356|#|1100|#|111|#|14
57|#|2357|#|1100|#|111|#|14
58|#|2358|#|1100|#|111|#|14
59|#|2359|#|1100|#|111|#|14

用正则表达式将数据先拆分为行,再将各行拆分为列。

sql> SELECT c1,2         regexp_substr(c1,'[^|#]+',1,1) AS d1,3         regexp_substr(c1,2) AS d2,4         regexp_substr(c1,3) AS d3,5         regexp_substr(c1,4) AS d4,6         regexp_substr(c1,5) AS d5
  7    FROM (SELECT to_char(regexp_substr(c1,'[^[:space:]]+',LEVEL + 1)) AS c1
  8            FROM test
  9          CONNECT BY LEVEL <= regexp_count(c1,chr(10)));
C1                                       D1    D2    D3    D4    D5
---------------------------------------- ----- ----- ----- ----- -----
01|#|政企|#|1000|#|13378|#|1407          01    政企  1000  13378 1407
02|#|政企|#|1000|#|13383|#|1407          02    政企  1000  13383 1407
01|#|路|#|1100|#|10093|#|1401            01    路    1100  10093 1401
54|#|2354|#|1100|#|111|#|14              54    2354  1100  111   14
55|#|2355|#|1100|#|111|#|14              55    2355  1100  111   14
56|#|2356|#|1100|#|111|#|14              56    2356  1100  111   14
57|#|2357|#|1100|#|111|#|14              57    2357  1100  111   14
58|#|2358|#|1100|#|111|#|14              58    2358  1100  111   14
59|#|2359|#|1100|#|111|#|14              59    2359  1100  111   14
9 rows selected
原文链接:https://www.f2er.com/regex/362347.html

猜你在找的正则表达式相关文章