안녕하세요.
ORACLE > MYSQL로 변환을 하는 과정에서 START WITH CD 부분을 어떤식으로 변환해야하는지 구글링을 해서 적용해보려 해도 잘 안되네요... 선배님들의 도움을 얻고자글을 남깁니다.
변환하기 위한 Oracle의 SQL 은 다음과 같습니다..(_ _).
ASIS : ORACLE
SELECT DISTINCT CD, UPPR_CD FROM (SELECT CLSS_STRUC_DOMAIN_CD AS CD, UPPR_CLSS_STRUC_DOMAIN_CD AS UPPR_CD FROM TB_TESTA WHERE USE_YN = 'Y' UNION SELECT ACCTG_DEPT_CD AS CD, CLSS_STRUC_DOMAIN_CD AS UPPR_CD FROM TB_TESTB WHERE USE_YN = 'Y') WHERE 1 = 1 START WITH CD = 'A100' CONNECT BY PRIOR CD = UPPR_CD
감사합니다.
-- 기존 쿼리에 Distinct 는 불필요한 코드입니다. WITH RECURSIVE t2 AS ( WITH t1 AS ( SELECT clss_struc_domain_cd AS cd , uppr_clss_struc_domain_cd AS uppr_cd FROM tb_testa WHERE use_yn = 'Y' UNION SELECT acctg_dept_cd AS cd , clss_struc_domain_cd AS uppr_cd FROM tb_testb WHERE use_yn = 'Y' ) SELECT cd , uppr_cd FROM t1 WHERE cd = 'A100' UNION ALL SELECT c.cd , c.uppr_cd FROM t2 p INNER JOIN t1 c ON p.cd = c.uppr_cd ) SELECT * FROM t2 ;