您的位置:首页 - 教程 - 数据库 - 正文
Oracle反向字符截取逗號分隔字符串
DECLARE
M VARCHAR(10);
BEGIN
FOR I IN (
WITH T AS
 (SELECT REVERSE('i,am,a,test,hahahhah') AS STR FROM DUAL)
SELECT LEVEL,
       REGEXP_SUBSTR(T.STR, '[^,]+', 1, LEVEL) STR_SINGLE
  FROM T
CONNECT BY LEVEL <= LENGTH(T.STR) - LENGTH(REPLACE(T.STR, ',', '')) + 1)
LOOP
  SELECT REVERSE(I.STR_SINGLE) INTO M FROM DUAL;
 DBMS_OUTPUT.PUT_LINE(M);
END LOOP; 
END;

使用 REVERSE()函數反轉子串。


评论: