今天遇到一個 MySQL 轉 Oracle Join 的問題
[由原 MySQL COPY 過來的SQL] -->> 不可執行
select xyz.xyz_abc.id AS id,
xyz.xyz_abc.version AS version,
xyz.xyz_abc.chart_no AS chart_no,
xyz.xyz_chrbas.pat_name AS chart_Name,
xyz.xyz_abc.special_code AS special_code,
xyz.xyz_abc.disabled AS disabled
from xyz.xyz_chrbas join xyz.xyz_abc where xyz.xyz_abc.chart_no = xyz.xyz_chrbas.chart_no
[修改後的SQL] 可執行
select xyz.xyz_abc.id AS id,
xyz.xyz_abc.version AS version,
xyz.xyz_abc.chart_no AS chart_no,
xyz.xyz_chrbas.pat_name AS chart_Name,
xyz.xyz_abc.special_code AS special_code,
xyz.xyz_abc.disabled AS disabled
from xyz.xyz_chrbas, xyz.xyz_abc where xyz.xyz_abc.chart_no = xyz.xyz_chrbas.chart_no
此的問題主要在Inner Join vs Cross Join的差異
MySQL join 語法本身有部份隱藏性的功能,在MySQL中,Inner Join 可等於 Cross Join,差別只在你是否有Join Condition "On" or "Using"
在而在Oracle 中,Cross Join必須明確指定
簡單的解決方法,把mysql 中的 join 改為Cross Join 或 逗號代替即可。
若本意是要用 Inner Join, 不論是MySQL 或 Oracle ,必須要以" On" or " Using "作為 Join Condition.
若改用逗號,則是由資料庫依Join Condition 自行決定,省去指定的麻煩
沒有留言:
張貼留言