如何使用oracle中的正则表达式来获取一段字符串中的指定格式的值?
原始值:'ZB0010+-=-3KFJK(ZB0012S)DLKG-=-ZB0042......ZB0323...'目标值1:'ZB0010,ZB0012,ZB0042,...
原始值:'ZB0010+-=-3KFJK(ZB0012S)DLKG-=-ZB0042......ZB0323...'
目标值1:'ZB0010,ZB0012,ZB0042,ZB0323'
目标值2:id, value
---------
1, ZB0010
2, ZB0012
3, ZB0042
4, ZB0323
请问如何用oracle实现? 展开
目标值1:'ZB0010,ZB0012,ZB0042,ZB0323'
目标值2:id, value
---------
1, ZB0010
2, ZB0012
3, ZB0042
4, ZB0323
请问如何用oracle实现? 展开
1个回答
展开全部
--oracle 貌似不支持正向否定预查,还是用刚刚思路:
--目标值2:
WITH TMP AS
(SELECT 'ZB0010+-=-3KFJK(ZB0012S)DLKG-=-ZB0042......ZB0323...' AS STR
FROM DUAL)
SELECT LEVEL AS ID, REGEXP_SUBSTR(STR, 'ZB[0-9]{4}', 1, LEVEL) AS VALUE
FROM TMP
CONNECT BY LEVEL <= REGEXP_COUNT(STR, 'ZB[0-9]{4}');
--目标值1:
WITH TMP AS
(SELECT 'ZB0010+-=-3KFJK(ZB0012S)DLKG-=-ZB0042......ZB0323...' AS STR
FROM DUAL)
SELECT LISTAGG(VALUE, ',') WITHIN GROUP(ORDER BY ID)
FROM (SELECT LEVEL AS ID,
REGEXP_SUBSTR(STR, 'ZB[0-9]{4}', 1, LEVEL) AS VALUE
FROM TMP
CONNECT BY LEVEL <= REGEXP_COUNT(STR, 'ZB[0-9]{4}'))
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询