1

为什么这个简单的查询在 oracle 中可以正常工作,但在 DB2 中却不行:

select * 
from 
sysibm.dual d1 
left join sysibm.dual d2 on 1=1 and exists (select 1 from sysibm.dual)

将涉及子查询的条件移动到 where 子句可能会有所帮助,但这会将外部联接限制为内部联接。

4

2 回答 2

1

当我尝试运行您的查询时,我收到一个-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
于 2013-01-25T14:24:13.437 回答
0

这适用于 DB2 V10.1!没有安装补丁包。

于 2013-02-15T07:56:59.657 回答