MYSQL:
SELECT * FROM book ORDER BY $sidx $sord LIMIT $start , $limit;
How do I turn this into Oracle?
MYSQL:
SELECT * FROM book ORDER BY $sidx $sord LIMIT $start , $limit;
How do I turn this into Oracle?
You have to use rownum
property, BUT you have to apply it to the result set already ordered AND you need to pass it from the inner query (credit to Bob Jarvis and Daniel Hilgarth: check their explanations and links given in comments as well). It should be something like this:
SELECT * FROM
(SELECT b.*, rownum as row_num FROM book b ORDER by $sidx $sord)
WHERE row_num BETWEEN $start AND $start + $limit;
I am not familiar with the oracle syntax, but you can use the ROW_NUMBER()
function to rank the rows then select those with 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 Onwards
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