将Oracle转换为MySQL:看到不同的输出

时间:2017-11-29 20:09:44

标签: mysql oracle

我有来自Oracle的SQL查询,我试图将其转换为MySQL。

以下是两者的查询的一部分。数据库结构不同,因此您会发现表和列的名称不同。

运行时,我在MYSQL部分没有得到任何结果,需要帮助才能找到原因?

Oracle SQL查询:

    (SELECT  all_ips.child_itm_num,
             pres.child_itm_num AS present,
             prev.child_itm_num AS potential_prev_version
     FROM
            (SELECT DISTINCT child_itm_num
             FROM    EDW.dpdm_bom bom
             WHERE   root_itm_num IN ('a','b')) all_ips,
            (SELECT DISTINCT child_itm_num
             FROM    EDW.dpdm_bom bom
             WHERE   root_itm_num = 'b') pres,
   (SELECT DISTINCT child_itm_num
    FROM    EDW.dpdm_bom bom
    WHERE   root_itm_num = 'a') prev 
     WHERE  SUBSTR(all_ips.child_itm_num,0,LENGTH(all_ips.child_itm_num) - 3) = SUBSTR(pres.child_itm_num, 0,LENGTH(pres.child_itm_num) - 3)
     AND    SUBSTR(prev.child_itm_num,0,LENGTH(prev.child_itm_num) - 3)       = SUBSTR(pres.child_itm_num, 0,LENGTH(pres.child_itm_num) - 3)
     AND    prev.child_itm_num NOT IN (SELECT child_itm_num 
                                       FROM    EDW.dpdm_bom bom
                                       WHERE   root_itm_num ='b'))

enter image description here

MySQL查询:

    (SELECT  all_ips.child_name,
             pres.child_name AS present,
             prev.child_name AS potential_prev_version
     FROM
            (SELECT DISTINCT child_name
             FROM    DPDM_BOM bom
             WHERE   child_name IN ('a','b')) all_ips,
            (SELECT DISTINCT child_name
             FROM    DPDM_BOM bom
             WHERE   revision_name = 'b') pres,
            (SELECT DISTINCT child_name
             FROM    DPDM_BOM bom
             WHERE   revision_name = 'a') prev 
  WHERE  SUBSTR(all_ips.child_name,0,LENGTH(all_ips.child_name) - 3) = SUBSTR(pres.child_name, 0,LENGTH(pres.child_name) - 3)
  AND    SUBSTR(prev.child_name,0,LENGTH(prev.child_name) - 3)       = SUBSTR(pres.child_name, 0,LENGTH(pres.child_name) - 3)
  AND    prev.child_name NOT IN (SELECT child_name 
                                       FROM    DPDM_BOM bom
                                       WHERE   revision_name = 'b'))

enter image description here

请帮助!

Anusha H.

1 个答案:

答案 0 :(得分:1)

我认为您应该将WHERE child_name IN ('a','b')替换为WHERE revision_name IN ('a','b')。另外,使用CHAR_LENGTH代替LENGTH(尽管Mysql也支持LENTGH)。

(SELECT  all_ips.child_name,
             pres.child_name AS present,
             prev.child_name AS potential_prev_version
     FROM
            (SELECT DISTINCT child_name
             FROM    DPDM_BOM bom
             WHERE   revision_name IN ('a','b')) all_ips,
            (SELECT DISTINCT child_name
             FROM    DPDM_BOM bom
             WHERE   revision_name = 'b') pres,
            (SELECT DISTINCT child_name
             FROM    DPDM_BOM bom
             WHERE   revision_name = 'a') prev 
  WHERE  SUBSTR(all_ips.child_name,0,CHAR_LENGTH(all_ips.child_name) - 3) = SUBSTR(pres.child_name, 0,CHAR_LENGTH(pres.child_name) - 3)
  AND    SUBSTR(prev.child_name,0,LENGTH(prev.child_name) - 3)       = SUBSTR(pres.child_name, 0,LENGTH(pres.child_name) - 3)
  AND    prev.child_name NOT IN (SELECT child_name 
                                       FROM    DPDM_BOM bom
                                       WHERE   revision_name = 'b'))                                   

希望它有所帮助!