DB2 Using LIMIT and OFFSET

二次信任 提交于 2019-11-28 12:21:22

DB2 for Linux Unix Windows (LUW) and DB2 for iSeries are different products. Likely, DB2 for iSeries does not support DB2_COMPATIBILITY_VECTOR. I'm not able to find mention of it in the iSeries Information Center.

Instead of LIMIT, you can use the FETCH FIRST 10 ROWS ONLY clause.

Instead of LIMIT and OFFSET, you should be able to use a subselect with the ROW_NUMBER olap function. Something like this:

 SELECT emp.EMPNO, emp.SALARY
 FROM (

     SELECT EMPNO, SALARY, 
            ROW_NUMBER() OVER(ORDER BY SALARY DESC) as row_number
     FROM EMPLOYEE

 ) emp
 WHERE emp.row_number > 10
 AND emp.row_number <= 20

As of IBM i 7.1 TR11 or IBM i 7.2 TR3, normal modern paging with LIMIT / OFFSET is now supported:

SELECT SalesOrderId,OrderDate,DueDate,ShipDate,
       Status,CustomerId,SubTotal,TaxAmt
  FROM SalesOrderHeader SOH
 WHERE CustomerId=@CustomerId
ORDER BY SalesOrderId DESC
 LIMIT @ROWS_PER_PAGE      -- Variable = 10
OFFSET @PAGE_START_ROW     -- Variable = 10 * Page Number

See this article for details...

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