如何将这个旧的oracle SQL语句转换为已遵循DB2 ANSI 98:
SELECT
O.OBJECT_NAME AS OBJECT_NAME,
ATT.ATTRIBUTE_NAME AS ATTRIBUTE_NAME,
(CASE WHEN R.RULE_NAME = 'LAST_UPDATE' THEN 1
WHEN R.RULE_NAME = 'SOURCE_SUPREMACY' THEN 2
ELSE 3 END)
ID_RULE,
RD.SRC_CODE,
RD.WEIGTH
FROM
XOBJRULE ORL,
XOBJECT O,
XATTRIBUTE ATT,
XRULE R,
XOBJRULEDET RD,
CDSOURCEIDENTTP S
WHERE
ORL.ID_OBJECT = O.ID_OBJECT(+) AND
ORL.ID_ATTRIBUTE = ATT.ID_ATTRIBUTE(+) AND
ORL.ID_RULE = R.ID_RULE AND
R.ID_RULE = RD.ID_RULE(+) AND
RD.SRC_CODE = S.SOURCE_IDENT_TP_CD(+) AND
ORL.PERSON_ORGANIZATION IN (1,3)
ORDER BY 1,2,5 ASC
此SQL语句是从Java调试中提取的。我该如何将其转换为DB2格式而又不显着使用更改标记,以免查看Java代码逻辑?
答案 0 :(得分:3)
查询使用Oracle自己的外部联接语法(+)
。对于DB2,您需要将所有联接转换为ANSI SQL 92显式联接语法:LEFT OUTER JOIN。
...
FROM
XOBJRULE ORL
left outer join XOBJECT O on ORL.ID_OBJECT = O.ID_OBJECT
left outer join XATTRIBUTE ATT on ORL.ID_ATTRIBUTE = ATT.ID_ATTRIBUTE
inner join XRULE R on ORL.ID_RULE = R.ID_RULE
left outer join XOBJRULEDET RD on R.ID_RULE = RD.ID_RULE
left outer join CDSOURCEIDENTTP S on RD.SRC_CODE = S.SOURCE_IDENT_TP_CD
WHERE ORL.PERSON_ORGANIZATION IN (1,3)