Come posso effettuare il paging in Sybase senza creare una tabella temporanea? (problema di Oracle Rownum)

StackOverflow https://stackoverflow.com/questions/1225889

  •  22-07-2019
  •  | 
  •  

Domanda

In Oracle, di solito esegui una query in questo modo per il paging.

SELECT * FROM (SELECT *, rownum rid  FROM TABLEA WHERE rownum <= #pageend#)
WHERE rid > #pagestart#

Tuttavia, non esiste " rownum " funzione in Sybase DBMS.

Come posso fare esattamente quella stessa query in Sybase?

Ho trovato alcuni modi.

  1. usa " rowcount "

    imposta il conteggio delle righe 10

    seleziona * da TABLEA

  2. usa identità (crea tabella temporanea)

    SELEZIONA *, ROWNUM = IDENTITÀ (8) IN #TEMP DA TABLEA

    SELEZIONA * DA #TEMP DOVE ROWNUM < # pageend # AND ROWNUM > = # pagestart #

    DROP TABLE #TEMP

questi non sono ciò che voglio.

il conteggio delle righe è impostato a livello di sessione e non voglio creare una tabella temporanea.

È stato utile?

Soluzione

Se hai una colonna ID univoca sulla tua tabella, puoi utilizzare SELECT TOP n

SELECT TOP 10 *
FROM tableA
WHERE id BETWEEN @start AND @end

Altri suggerimenti

Questo ti darà tutti gli ID in modo da poterli usare in una selezione come " select * where id_column in (ids from query below) "

select top 10 id_column from trade
where @whereClause
and id_column > 0  //keep replacing this with the max id from the result set
order by id_column
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top