博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
分割字符串
阅读量:6627 次
发布时间:2019-06-25

本文共 1416 字,大约阅读时间需要 4 分钟。

SQL> WITH SPLIT_TEST AS

2 (SELECT 'ORACLE,MYSQL,HADOOP,PLANNING,DATASTAGE,10,11' AS SPLIT_STR FROM DUAL
3 UNION
4 SELECT 'SCOTT,HR,OE,2014,2015' AS SPLIT_STR FROM DUAL
5 )
6 SELECT REPLACE(SPLIT_STR,',',CHR(10)) S_WORD FROM SPLIT_TEST
7 ;
S_WORD
--------------------------------------------
ORACLE
MYSQL
HADOOP
PLANNING
DATASTAGE
10
11
SCOTT
HR
OE
2014
2015

 

 

WITH SPLIT_TEST AS

(SELECT 'ORACLE,MYSQL,HADOOP,PLANNING,DATASTAGE,10,11' AS SPLIT_STR FROM DUAL)
SELECT REGEXP_SUBSTR(SPLIT_STR, '\w+', 1, LEVEL) AS BI1,
REGEXP_SUBSTR(SPLIT_STR, '[^,]+', 1, LEVEL) AS BI2,
LEVEL
FROM (SELECT SPLIT_STR,
LENGTH(SPLIT_STR) L1,
LENGTH(REPLACE(SPLIT_STR, ',', '')) L2
FROM SPLIT_TEST) A
CONNECT BY LEVEL <= L1 - L2 + 1

 

BI1                BI2                 LEVEL

----------      --------------- -------
ORACLE         ORACLE          1
MYSQL           MYSQL            2
HADOOP        HADOOP          3
PLANNING      PLANNING        4
DATASTAGE  DATASTAGE     5
10                10                   6
11                11                   7

 

WITH T_STR_ROW AS

(SELECT 1 AS ID, 'v11|$|v12|$|v13|$|' AS STR FROM DUAL)
SELECT C.LV,
RTRIM(REGEXP_SUBSTR(T.STR, '.*?\|\$\|', 1, C.LV), '\|\$\|') AS CV
FROM (SELECT STR,
LENGTH(REGEXP_REPLACE(STR,
'[^' || CHR(124) || CHR(36) || CHR(124) || ']',
NULL)) / 3 AS CNT
FROM T_STR_ROW
WHERE ID = '1') T
INNER JOIN (SELECT LEVEL LV
FROM DUAL
CONNECT BY LEVEL <=
(SELECT LENGTH(REGEXP_REPLACE(STR,
'[^' || CHR(124) ||
CHR(36) || CHR(124) || ']',
NULL)) / 3 AS CNT
FROM T_STR_ROW
WHERE ID = '1')) C
ON C.LV <= T.CNT;

转载于:https://www.cnblogs.com/wwxbi/p/4214930.html

你可能感兴趣的文章
我的友情链接
查看>>
六种微服务架构的设计模式
查看>>
路由器配置大全
查看>>
linker command failed with exit code 1 (use -v to see invocation)修改方法
查看>>
git学习记录
查看>>
centos7系统修改网卡名称
查看>>
SQL表函数的BUG
查看>>
JavaWeb中的文件上传和下载功能的实现
查看>>
linq/EF/lambda Group by/Order by 多个字段详细用法
查看>>
CSS3圆角
查看>>
TCP的状态(SYN,FIN等)
查看>>
【推导】【模拟】AtCoder Regular Contest 082 F - Sandglass
查看>>
Jetty和tomcat的比较
查看>>
HDU 6048 - Puzzle | 2017 Multi-University Training Contest 2
查看>>
Apache Kafka 0.9消费者客户端
查看>>
选择符
查看>>
【CodeForces】925 C.Big Secret 异或
查看>>
【游记】CTSC&APIO2017
查看>>
[旧博客]Python 第一天总结
查看>>
Codeforces Round #408 (Div. 2)
查看>>