仅在DB2中参数化FETCH FIRST n ROWS [英] Parameterize FETCH FIRST n ROWS ONLY in DB2

查看:608
本文介绍了仅在DB2中参数化FETCH FIRST n ROWS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下操作:

I'm trying to do the following:

  select * 
  from table      
  fetch first @param rows only

@param是一个整数.

@param is an int.

DB2将没有它.我听说过将它与||连接起来,但似乎无法使它正常工作.

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

有人对此有经验吗?

(PS,我看到了类似的问题 ),但不理解他使用':1'的方法.

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

推荐答案

您可以尝试以下操作:

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

这篇关于仅在DB2中参数化FETCH FIRST n ROWS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆