DB2: Won't allow parameterize: 'fetch first <X> rows only'

China☆狼群 提交于 2019-12-11 05:26:55

问题


Although in Oracle DB its is allowed to parametrize the number of rows that the query can fetch by adding to the query:

select ...
from ...
where ...
and rownum <= @MaximumRecords

I can't add similar condition to acuivalent query running in DB2: It is allowed to add:

select ... 
from ...
where ...
fetch first 500 rows only

(where there is fixed number of rows) but not:

select ... 
from ...   
where ...      
fetch first :1 rows only

(:1 == @MaximumRecords)

Is someone aware of a solution/work-around to this problem?


回答1:


I think I found the solution. I just ran this query with a tool that gave a 0 default value to @MaximnumRecords and apperently DB2 doesn't allow to perform:
"fetch first 0 rows only" in any case - that was the problem.



来源:https://stackoverflow.com/questions/2621420/db2-wont-allow-parameterize-fetch-first-x-rows-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!