加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 02:03:53 所属栏目:百科 来源:网络整理
导读:表结构如下 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||'|#|

表结构如下

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读