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'.
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
rocket
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/paramertize-fetch-first-n-rows-only-in-db2