MYSQL:
SELECT * FROM book ORDER BY $sidx $sord LIMIT $start , $limit;
我如何把它变成甲骨文?
您必须使用rownum
属性,但您必须将其应用于已经排序的结果集,并且您需要从内部查询中传递它(感谢 Bob Jarvis 和 Daniel Hilgarth:请查看他们的解释和评论中给出的链接)。它应该是这样的:
SELECT * FROM
(SELECT b.*, rownum as row_num FROM book b ORDER by $sidx $sord)
WHERE row_num BETWEEN $start AND $start + $limit;
我不熟悉 oracle 语法,但您可以使用该ROW_NUMBER()
函数对行进行排名,然后选择具有以下内容的行rank BETWEEN @start and @limit
:
SELECT *
FROM
(
select *,
ROW_NUMBER() OVER (ORDER BY ID DESC) AS rank
FROM book
)
WHERE rank BETWEEN @start AND @end
/* OR
WHERE BETWEEN ((@PageNum - 1) * @PageSize + 1)
AND (@PageNum * @PageSize)
/*
select * from(
select rownum as row_num, id from t
)
where row_num between :start and :start+:limit
10g 起
WITH CTE AS(SELECT b.*, Row_Number() OVER(ORDER BY SIDX,SORD) AS Rn FROM BOOK b)
SELECT *
FROM CTE
WHERE Rn BETWEEN STARTLIMIT AND ENDLIMIT