意外的令牌" LIMIT"在DB2中

时间:2012-11-01 18:39:07

标签: sql ruby-on-rails db2 db2-luw

My 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

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:5)

DB2不支持LIMIT x关键字。

正如错误消息所述,正确的方法是使用FETCH FIRST x ROWS ONLY代替。

答案 1 :(得分:4)

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

但是从DB2 v9.7.2开始,support for LIMIT x can be enabled通过DB2_COMPATIBILITY_VECTOR registry variable

开始
db2set DB2_COMPATIBILITY_VECTOR=MYS
db2stop
db2start

......它有效!