为什么 FETCH FIRST N ROWS 不能与WITH 语句结合使用?

发布于 2024-12-07 08:52:17 字数 326 浏览 0 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寒冷纷飞旳雪 2024-12-14 08:52:17

您缺少 FETCH 子句末尾的 ONLY 关键字。

WITH a AS (
    SELECT * FROM sysibm.systables
)
SELECT a.* FROM a
FETCH FIRST 10 ROWS ONLY;

You're missing the ONLY keyword at the end of the FETCH clause.

WITH a AS (
    SELECT * FROM sysibm.systables
)
SELECT a.* FROM a
FETCH FIRST 10 ROWS ONLY;
埋葬我深情 2024-12-14 08:52:17

最后缺少唯一的关键字。示例此处

Missing the Only Keyword at the end. Example here.

苄①跕圉湢 2024-12-14 08:52:17

虽然您给出的示例可能很简化,但将 fetch first 子句放在第一个选择部分中怎么样?

我永远无法清楚地阅读文档,但由于 with-statement 创建了一个公共表表达式,您可能无法使用 fetch-first-clause 来从中进行选择。根据 本文档,在 with 语句的 select 中使用 fetch-first-clause 是有效的语法。

IE

WITH a AS (
SELECT * FROM sysibm.systables
FETCH FIRST 10 ROWS ONLY
)
SELECT a.* FROM a;

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.

WITH a AS (
SELECT * FROM sysibm.systables
FETCH FIRST 10 ROWS ONLY
)
SELECT a.* FROM a;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文