I\'m in the process of generalizing a Django DB replication app and it uses the statement:
SELECT %s FROM %s LIMIT 1
to fetch 1 row and use
It's not at all universal. Actually I am surprised it is working for you in Oracle; it didn't used to be present. Normally Oracle users go for ROWNUM
.
Every database has its own syntax for limiting results by row number. There are also two methods that are ANSI standard SQL:
FETCH FIRST
. Derived from DB/2 and only made standard in SQL:2008, so very little DBMS support. Can't use an offset.
The windowing function SELECT ..., ROW_NUMBER() OVER (ORDER BY some_ordering) AS rn WHERE rn BETWEEN n AND m ... ORDER BY some_ordering
. This is from SQL:2003 and has some (patchy, sometimes slow) support in newer DBMSs. It can use an offset or any other comparison function on the row number, but has the drawback of being appallingly ugly.
Here's a good overview of the tediousness you will have to deal with if you want cross-DBMS pagination support.