DB2中出现意外的标记"LIMIT"

Mar*_*tuc 1 sql db2 ruby-on-rails db2-luw

我的Rails应用程序连接到远程DB2数据库,在迁移时我遇到了这个错误:

==  DropLegacyProject: migrating ========================================
rake aborted!
An error has occurred, this and all later migrations canceled:

RuntimeError: Failed to execute statement due to: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N  An unexpected token "LIMIT" was found following "".  Expected tokens may include:  "FETCH FIRST <n> ROWS ONLY".  SQLSTATE=42601 SQLCODE=-104: SELECT  projects.* FROM projects WHERE projects.id < 17 LIMIT 1
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

bha*_*mby 5

DB2 does not support the LIMIT x keyword.

As the error message says, the proper way to do this would to use FETCH FIRST x ROWS ONLY instead.


Mar*_*tuc 5

正如bhamby所建议的,DB2默认情况下不支持LIMIT x关键字...。

但从 DB2 v9.7.2 开始,可以通过DB2_COMPATIBILITY_VECTOR 注册表变量启用支持LIMIT x

db2set DB2_COMPATIBILITY_VECTOR=MYS
db2stop
db2start
Run Code Online (Sandbox Code Playgroud)

...它有效!