将代码从Oracle 8i转换为MySQL

问题描述 投票:0回答:2

如何将以下代码从Oracle 8i转换为MySQL-

select count(*) 

from   patient_visit,
        organization_master
where patient_visit.organization_id=organization_master.organization_id(+);   

在where语句中,“organization_master.organization_id(+)”在MySQL中不起作用。

请建议。

mysql oracle
2个回答
1
投票

(+)是外部联接的特定于Oracle的表示法。我想你应该写这样的东西

select count(*)     
FROM patient_visit
LEFT OUTER JOIN organization_master
ON patient_visit.organization_id=organization_master.organization_id

我没有测试它,因为我没有数据来测试它,但它应该工作。

希望能帮助到你


0
投票

您需要使用所有现代SQL数据库(也是Oracle)支持的标准JOIN语法:

select    count(*)
from      patient_visit
left join organization_master
       on patient_visit.organization_id = organization_master.organization_id

如果你有没有(+)的其他连接,那么只需用inner join替换它们:在from子句中完全避免使用逗号。其他非连接条件只停留在where条款中。

例如:

select     count(*)
from       patient_visit
inner join patient_registration 
        on patient_registration.pprn_regd_id = patient_visit.pprn_regd_id
left join  organization_master 
        on patient_visit.com_organization_id = organization_master.com_organization_id
where      patient_visit.ghm_hosp_id = i_hosp_id
© www.soinside.com 2019 - 2024. All rights reserved.