안녕하세요 제가 프로그램을 함에있어서 다소 난해한 부분이 있어 이렇게 여쭈어봅니다.
SELECT * FROM EAPP_APPROVAL_LINE_TLV EALT INNER JOIN EAPP_APPROVAL_STEP_TLV EAST ON EALT.APPROVAL_LINE_ID = EAST.APPROVAL_LINE_ID INNER JOIN ( SELECT APPROVAL_LINE_ID , APPROVAL_STEP_ID , APPROVER_ID FROM EAPP_APPROVAL_PERSON WHERE APPROVAL_PERSON_ID IN ( SELECT MIN(APPROVAL_PERSON_ID) FROM EAPP_APPROVAL_LINE_TLV EALT , EAPP_APPROVAL_STEP_TLV EAST , EAPP_APPROVAL_PERSON EAP WHERE EALT.APPROVAL_LINE_ID = EAST.APPROVAL_LINE_ID AND EALT.APPROVAL_LINE_ID = EAP.APPROVAL_LINE_ID AND EAST.APPROVAL_STEP_ID = EAP.APPROVAL_STEP_ID AND EALT.APPROVAL_LINE_ID = W_APPROVAL_LINE_ID GROUP BY EAST.APPROVAL_STEP_ID ) ) EAP ON EALT.APPROVAL_LINE_ID = EAP.APPROVAL_LINE_ID AND EAST.APPROVAL_STEP_ID = EAP.APPROVAL_STEP_ID INNER JOIN HRM_PERSON_MASTER HPM ON EAP.APPROVER_ID = HPM.PERSON_ID LEFT JOIN ( SELECT IPRA.APPROVAL_LINE_ID , IPRA.APPROVAL_SEQ , IPRA.APPROVAL_STEP_DESC , HPM.DISPLAY_NAME , IPRA.APPROVAL_RESULT , IPRA.APPROVAL_DATE , ERET.REASON_DESCRIPTION FROM INV_PO_REQ_APPROVAL IPRA , HRM_PERSON_MASTER HPM , EAPP_REASON_ENTRY_TLV ERET WHERE IPRA.APPROVER_ID = HPM.PERSON_ID AND IPRA.REJECT_REASON_ID = ERET.REASON_ENTRY_ID (+) AND IPRA.REQUEST_HEADER_ID = W_REQUEST_HEADER_ID ) IPRA ON EALT.APPROVAL_LINE_ID = IPRA.APPROVAL_LINE_ID AND EAST.APPROVAL_SEQ = IPRA.APPROVAL_SEQ WHERE EALT.APPROVAL_LINE_ID = W_APPROVAL_LINE_ID
이 형식을 ..
SELECT * FROM EAPP_APPROVAL_LINE_TLV EALT , EAPP_APPROVAL_STEP_TLV EAST ,(SELECT APPROVAL_LINE_ID , APPROVAL_STEP_ID , APPROVER_ID FROM EAPP_APPROVAL_PERSON WHERE APPROVAL_PERSON_ID IN ( SELECT MIN(APPROVAL_PERSON_ID) FROM EAPP_APPROVAL_LINE_TLV EALT , EAPP_APPROVAL_STEP_TLV EAST , EAPP_APPROVAL_PERSON EAP WHERE EALT.APPROVAL_LINE_ID = EAST.APPROVAL_LINE_ID AND EALT.APPROVAL_LINE_ID = EAP.APPROVAL_LINE_ID AND EAST.APPROVAL_STEP_ID = EAP.APPROVAL_STEP_ID AND EALT.APPROVAL_LINE_ID = &W_APPROVAL_LINE_ID GROUP BY EAST.APPROVAL_STEP_ID )) EAP , HRM_PERSON_MASTER HPM ,(SELECT IPRA.APPROVAL_LINE_ID , IPRA.APPROVAL_SEQ , IPRA.APPROVAL_STEP_DESC , HPM.DISPLAY_NAME , ERET.REASON_DESCRIPTION FROM INV_PO_REQ_APPROVAL IPRA , HRM_PERSON_MASTER HPM , EAPP_REASON_ENTRY_TLV ERET WHERE IPRA.APPROVER_ID = HPM.PERSON_ID AND IPRA.REJECT_REASON_ID = ERET.REASON_ENTRY_ID(+) AND IPRA.REQUEST_HEADER_ID = &W_REQUEST_HEADER_ID) IPRA WHERE EALT.APPROVAL_LINE_ID = &W_APPROVAL_LINE_ID AND EALT.APPROVAL_LINE_ID = EAST.APPROVAL_LINE_ID AND EALT.APPROVAL_LINE_ID = EAP.APPROVAL_LINE_ID AND EAST.APPROVAL_STEP_ID = EAP.APPROVAL_STEP_ID AND EAP.APPROVER_ID = HPM.PERSON_ID AND EALT.APPROVAL_LINE_ID = IPRA.APPROVAL_LINE_ID AND EAST.APPROVAL_SEQ = IPRA.APPROVAL_SEQ
이렇게 변형 하였는데 과연 옳은 변형인지 여쭈어봅니다 ^^
-- 1번은 ANSI Join 구문으로 Inner Join 과 Left Outer Join 이 공존하는데... -- 2번은 Oracle Join 구문으로 Inner Join 만 있네요? Outer Join 이 있어야 합니다. -- 오라클에서 아우터 조인은 (+) 기호로 표시하는데... AND EALT.APPROVAL_LINE_ID = IPRA.APPROVAL_LINE_ID(+) AND EAST.APPROVAL_SEQ = IPRA.APPROVAL_SEQ(+) -- 이 경우 아우터 조인을 두개의 집합(EALT, EAST)과 할 수는 없습니다. -- 해결법은 -- 1. ANSI 사용 -- 2. 2개 집합을 우선 조인하여 하나(인라인뷰)로 만든 뒤 아우터 조인 -- 3. 논리적인 접근방법으로 해결(a=b 이고 b=c 이면 a=c 이다.) -- 당황하지 않고 EALT.APPROVAL_LINE_ID 대신 EAST.APPROVAL_LINE_ID 로 변경 하면 끝. -- AND EALT.APPROVAL_LINE_ID = IPRA.APPROVAL_LINE_ID(+) AND EAST.APPROVAL_LINE_ID = IPRA.APPROVAL_LINE_ID(+) AND EAST.APPROVAL_SEQ = IPRA.APPROVAL_SEQ(+)