为什么这个简单的查询在 oracle 中可以正常工作,但在 DB2 中却不行:
select *
from
sysibm.dual d1
left join sysibm.dual d2 on 1=1 and exists (select 1 from sysibm.dual)
将涉及子查询的条件移动到 where 子句可能会有所帮助,但这会将外部联接限制为内部联接。
当我尝试运行您的查询时,我收到一个-338
错误,根据信息中心(请参阅链接),该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
这适用于 DB2 V10.1!没有安装补丁包。