为什么这个简单的查询在oracle中工作正常但在DB2中不起作用:
select *
from
sysibm.dual d1
left join sysibm.dual d2 on 1=1 and exists (select 1 from sysibm.dual)
将子查询涉及条件移动到where子句可能会有所帮助,但这会将外连接限制在内部。
答案 0 :(得分:1)
当我尝试运行您的查询时,我得到-338
error,根据信息中心(请参阅链接),ON
子句有以下限制:
与JOIN运算符或MERGE语句关联的ON子句 由于以下原因之一而无效。
* The ON clause cannot include any subqueries. * Column references in an ON clause must only reference columns of tables that are in the scope of the ON clause. * Scalar fullselects are not allowed in the expressions of an ON clause. * A function referenced in an ON clause of a full outer join must be deterministic and have no external action. * A dereference operation (->) cannot be used. * A SQL function or SQL method cannot be used. * The ON clause cannot include an XMLQUERY or XMLEXISTS expression.
我不确定你的查询是否可行,但你认为也许你可以重写这样的东西:
select *
from
sysibm.dual d1
left join (
SELECT dl.*,
CASE WHEN EXISTS (SELECT 1 FROM sysibm.dual)
THEN 1
ELSE 0
END AS jn
FROM sysibm.dual dl
) D2
on 1=1 and 1=d2.jn
答案 1 :(得分:0)
这适用于DB2 V10.1! 没有安装fixpack。