将Oracle join(+)从Oracle PL / SQL转换为Microsoft T-SQL

时间:2012-05-23 08:24:56

标签: sql

我有以下查询需要从Oracle PL / SQL转换为MYSQL以适应数据源更改。

Oracle如何加入(+)转换为T-SQL?

SELECT INA01 , SMYDESC , CASE WHEN INACONF = 'Y' THEN '0' ELSE '1' END  , INB15 , AZF03  , INAORIU  , ZX02  , INADATE  , INA04  , GEM02  , INA02  , INA11  , INA07  , INB03  , INB04  , IMA02 , INB09 , INB08 , INBUD02
       FROM INA_FILE , SMY_FILE , GEM_FILE , INB_FILE , IMA_FILE , AZF_FILE , ZX_FILE
       WHERE INA00 = '1'                                 
         AND INACONF <> 'X'
         AND INA01 = INB01
         AND INB04 = IMA01(+)
         AND SUBSTRING(INA01,1,5) = SMYSLIP(+)
         AND SUBSTRING(INA01,1,5) NOT IN ('0IN99','1IN03','0IN92','1IN04','0IN98')
         AND INA04             = GEM01(+)
         AND INB15             = AZF01(+)
         AND INAORIU           = ZX01(+)
         AND INACONF           = 'Y'                     
         AND inadate = to_date('2012/05/23', 'yyyy/mm/dd')

3 个答案:

答案 0 :(得分:2)

您可能需要在JOIN子句中的列名前面添加表名:

SELECT INA01, SMYDESC, 
       CASE WHEN INACONF = 'Y' THEN '0' ELSE '1' END, 
       INB15, AZF03 , INAORIU , ZX02, INADATE, INA04, GEM02, INA02, 
       INA11, INA07, INB03, INB04, IMA02, INB09, INB08, INBUD02
FROM INA_FILE 
INNER JOIN INB_FILE ON INA01 = INB01
LEFT OUTER JOIN IMA_FILE ON INB04 = IMA01
LEFT OUTER JOIN GEM_FILE ON INA04 = GEM01
LEFT OUTER JOIN AZF_FILE ON INB15 = AZF01
LEFT OUTER JOIN SMY_FILE ON SUBSTRING(INA01,1,5) = SMYSLIP
LEFT OUTER JOIN ZX_FILE ON INAORIU = ZX01
WHERE INA00 = '1'                                 
AND INACONF <> 'X'
AND SUBSTRING(INA01,1,5) NOT IN ('0IN99','1IN03','0IN92','1IN04','0IN98')
AND INACONF = 'Y'                     
AND inadate = CONVERT(DATETIME, '05/23/2012', 101)

答案 1 :(得分:0)

这是outer join运算符的本机Oracle语法。

http://docs.oracle.com/cd/B28359_01/server.111/b28286/queries006.htm

upd :为了帮助您实际重写此查询,我需要知道表结构,因为您不在where子句中使用任何表引用 - 仅列,这似乎是独特的表格。

答案 2 :(得分:0)

我对你的架构做了一些假设......但是这样的事情

    SELECT  INA01 , SMYDESC , CASE WHEN INACONF = 'Y' THEN '0' ELSE '1' END  , INB15 , AZF03  , INAORIU  , ZX02  , INADATE  , INA04  , GEM02  , INA02  , INA11  , INA07  , INB03  , INB04  , IMA02 , INB09 , INB08 , INBUD02
    FROM    INA_FILE join inb_file on ina01 = inb01
            left join SMY_FILE on SUBSTRING(INA01,1,5) = SMYSLIP
            left join GEM_FILE on INA04 = GEM01
            join INB_FILE on INA01 = INB01
            left join IMA_FILE on INB04 = IMA01
            left join AZF_FILE on INB15 = AZF01
    WHERE   INA00 = '1'                                 
            AND INACONF <> 'X'
            AND SUBSTRING(INA01,1,5) NOT IN ('0IN99','1IN03','0IN92','1IN04','0IN98')
            AND INACONF = 'Y'                     
            AND inadate = '2012-05-23'