Parameterize FETCH FIRST n ROWS ONLY in DB2

做~自己de王妃 提交于 2019-11-28 09:24:50

问题


I'm trying to do the following:

  select * 
  from table      
  fetch first @param rows only

@param is an int.

DB2 would not have it. I've heard of concatenating it with ||, but I can't seem to get that to work.

Anyone have experience with this?

(PS I saw a similar question) but didn't understand his approach using ':1'.


回答1:


You could try the following:

select t.*
from (select r.*, row_number() over() as row_num  
      from table r) as t
where row_num <= @param



回答2:


Try this, where V_NBR is your passed in parameter for the number of rows you want:

FETCH FIRST ' || DIGITS ( V_NBR ) || '  ROWS ONLY '  


来源:https://stackoverflow.com/questions/3751884/parameterize-fetch-first-n-rows-only-in-db2

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