为什么 FETCH FIRST N ROWS 不能与WITH 语句结合使用?
我有以下 SQL 语句,但它无法在我的 DB2 数据库上运行:
WITH a AS (
SELECT * FROM sysibm.systables
)
SELECT a.* FROM a
FETCH FIRST 10 ROWS
如果没有 FETCH 语句,它就可以工作。我收到的错误消息是:
非法使用关键字 OPTIMIZE、令牌 ERR_STMT WNG_STMT 获取 SQL 保存点 保持空闲 预计是助理。
有什么建议吗?
I have the following SQL statement which does not run on my DB2 database:
WITH a AS (
SELECT * FROM sysibm.systables
)
SELECT a.* FROM a
FETCH FIRST 10 ROWS
Without the FETCH statement it works. The error message I get is:
Illegal use of keyword OPTIMIZE, token ERR_STMT
WNG_STMT GET SQL SAVEPOINT HOLD FREE
ASSOCIATE was expected.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您缺少 FETCH 子句末尾的
ONLY
关键字。You're missing the
ONLY
keyword at the end of the FETCH clause.最后缺少唯一的关键字。示例此处。
Missing the Only Keyword at the end. Example here.
虽然您给出的示例可能很简化,但将 fetch first 子句放在第一个选择部分中怎么样?
我永远无法清楚地阅读文档,但由于 with-statement 创建了一个公共表表达式,您可能无法使用 fetch-first-clause 来从中进行选择。根据 本文档,在 with 语句的 select 中使用 fetch-first-clause 是有效的语法。
IE
While the example you give is likely simplified, how about putting the fetch first clause in the first select portion?
I can never read the documentation clearly, but as the with-statement creates a common-table-expression, you might not be able to use the fetch-first-clause on selecting from it. According to this documentation, having the fetch-first-clause in the select of the with-statement is valid syntax.
i.e.