by 희주윤 [SQL Query] CONNECTBY ORACLE MYSQL MARIADB [2021.10.05 15:31:47]
안녕하세요 오라클 mariadb로 이전하게 되면서 쿼리 수정하는 중에 풀리지 않아 질문드립니다ㅠ SELECT TRIM(REGEXP_SUBSTR('A001,A002,A003','[^,]+',1,LEVEL)) AS DATA FROM DUAL CONNECT BY INSTR('A001,A002,A003',',',1,LEVEL-1)>0
해당 쿼리 조회시
DATA
-------
A001
A002
A003
이렇게 조회 되는데 mariadb로 어떻게 작성해야 될지 모르겠습니다....도와주세요ㅜㅠㅜ
WITH RECURSIVE t AS ( SELECT v , 1 lv , SUBSTRING_INDEX(v, ',', 1) x , SUBSTR(v, INSTR(v, ',') + 1) y FROM (SELECT CONCAT('A001,A002,A003', ',') v) a UNION ALL SELECT v , lv + 1 , SUBSTRING_INDEX(y, ',', 1) x , SUBSTR(y, INSTR(y, ',') + 1) y FROM t WHERE INSTR(y, ',') > 0 ) SELECT * FROM t ;
WITH RECURSIVE t AS ( SELECT v , LENGTH(v) - LENGTH(REPLACE(v, ',', '')) + 1 cnt , 1 lv , SUBSTRING_INDEX(v, ',', 1) x FROM (SELECT 'A001,A002,A003' v) a UNION ALL SELECT v , cnt , lv + 1 , SUBSTRING_INDEX(SUBSTRING_INDEX(v, ',', lv + 1), ',', -1) x FROM t WHERE lv < cnt ) SELECT * FROM t ;
Recursive 쿼리 참조.