简体   繁体   English

Oracle 到 MySQL 查询转换

[英]Oracle to MySQL Query Conversion

I was working on Oracle to MySQL query conversion when I encountered the following snippet that I'm completely unable to understand:当我遇到以下我完全无法理解的片段时,我正在处理 Oracle 到 MySQL 查询转换:

select *
from a, b 
where a.liab_id = b.liability_no(+) 
and NVL (a.cust_id, b.customer_no(+)) = b.customer_no(+);

Table a columns: cust_id, liab_id, details表a列:cust_id、liab_id、详细信息

Table b columns: customer_no, liability_no,range表 b 列:customer_no、liability_no、range

I'd be really grateful if someone can explain the query or convert it to the respective MySQL query.如果有人可以解释查询或将其转换为相应的 MySQL 查询,我将不胜感激。

To convert the legacy Oracle comma join to the ANSI join syntax, you want:要将旧的 Oracle 逗号连接转换为 ANSI 连接语法,您需要:

SELECT *
FROM   a
       LEFT OUTER JOIN b
       ON (   a.liab_id = b.liability_no
          AND COALESCE( a.cust_id, b.customer_no ) = b.customer_no
          )

or或者

SELECT *
FROM   a
       LEFT OUTER JOIN b
       ON (   a.liab_id = b.liability_no
          AND ( a.cust_id = b.customer_no OR a.cust_id IS NULL )
          )

Oracle 18c db<>fiddle here Oracle 18c db<> 在这里摆弄

MySQL 8 db<>fiddle here MySQL 8 db<> 在这里摆弄

In both Oracle and MySQL, you should use explicit JOIN syntax.在 Oracle 和 MySQL 中,您应该使用显式JOIN语法。 That would be:那将是:

select *
from a left join
     b 
    on a.liab_id = b.liability_no and
       a.cust_id = b.customer_no;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM