======原題======甲骨文外連接和常量值
我有多個外的常數加入如下的SQL:
select .. from CLAS MDP, CLAS ORG_CNTRY, CLAS BEN_CNTRY
AND ORG_CNTRY.LAS_ID(+) = 'COUNTRY_LOOKUP'
AND ORG_CNTRY.CB_DT = MDP.CB_DT
AND BEN_CNTRY.LAS_ID(+) = 'COUNTRY_LOOKUP'
AND BEN_CNTRY.CB_DT = MDP.CB_DT
上述查詢是否與下面的查詢相同?請指教。
select ... from
CLAS MDP left join CLAS ORG_CNTRY on ORG_CNTRY.LAS_ID = 'COUNTRY_LOOKUP' left
join CLAS BEN_CNTRY on BEN_CNTRY.LAS_ID = 'COUNTRY_LOOKUP' where ORG_CNTRY.CB_DT
= MDP.CB_DT and BEN_CNTRY.CB_DT = MDP.CB_DT
======後續問題=======
@Used_By_Already,@Gordon Linoff感謝您的答覆。
但是,我的實際查詢比我最初發布的要多一點。它如下所示:
MDP.CLAS_ID = 'DIS_PARAMETERS'
AND MDP.CB_DT = <<BusinessDate>>
AND ACCT.ACCT_NO = TXN.ACCT_NO
AND MDP.CTRY_CD = TXN.REC_CTRY_CD
AND TXN.CB_DT BETWEEN ACCT.START_DT and ACCT.END_DT
AND ORG_CNTRY.CLAS_ID(+) = 'COUNTRY_LOOKUP'
AND ORG_CNTRY.CB_DT = MDP.CB_DT
AND BEN_CNTRY.CLAS_ID(+) = 'COUNTRY_LOOKUP'
AND BEN_CNTRY.CB_DT = MDP.CB_DT
AND TXN.SEND_CTRY_CD = ORG_CNTRY.CLAS_SCHM_CD(+)
AND TXN.RCIP_CTRY_CD = BEN_CNTRY.CLAS_SCHM_CD(+)
這可以重寫成如下嗎?請指教。
select ...
from
CLAS MDP left join CLAS ORG_CNTRY on ORG_CNTRY.CB_DT = MDP.CB_DT
AND ORG_CNTRY.LAS_ID = 'COUNTRY_LOOKUP'
right join ACCT_TRAN TXN on ORG_CNTRY.CLAS_SCHM_CD = TXN.SEND_CTRY_CD
left join CLAS BEN_CNTRY on BEN_CNTRY.CB_DT = MDP.CB_DT
AND BEN_CNTRY.LAS_ID = 'COUNTRY_LOOKUP'
right join ACCT_TRAN TXN on BEN_CNTRY.CLAS_SCHM_CD = TXN.RCIP_CTRY_CD
號聯接和過濾謂詞可以在'join'條款都去了,即使分離過濾謂詞出與內部連接是更符合邏輯,並把它們在'where'條款。這意味着內部和外部連接不可互換是我不喜歡的語法之一。 –
存在一個非常非正式的,基本上不成文的規則,即:*「不要使用正確的外連接」*這裏肯定沒有理由這麼做。但是,您要求確定的答案,而無需訪問數據。它只能是最好的猜測,它需要進行測試。注意你**不能聲明表格別名TXN兩次**,這將永遠不會工作。 –