With limiting the result of Select in Oracle

1

I'm doing a select from the bank and it's returning me 15 lines. I used ROWNUM to get the first 8 lines, but I want to make another select and pick up from line 9 to 15.

SELECT * FROM (SELECT DISTINCT o.STORAGE_TYPE, COUNT(o.QUANTIDADE) as 
qtd_materiais   
FROM mopsao.vw_monitoramento_do@MOPSAO m INNER JOIN VIEW_ORDENS_A_COLETAR o 
ON 
m.DELIVERY = o.DELIVERY AND m.cod_mat_c = o.MATERIAL WHERE 
m.status_andamento = 'Pickado' 
GROUP BY o.STORAGE_TYPE ORDER BY qtd_materiais DESC) WHERE ROWNUM <= 8

This first select as I described, take the first 8 lines.

    
asked by anonymous 01.10.2018 / 16:35

2 answers

2

Good morning friend, for such a demand, it is necessary to use FETCH passing as a parameter the amount of lines you want in the range.

Example: Offset - > Number of lines Fetch - > Offset + Line Range

DECLARE @Off AS INT
SET @Off = @OFFSET
SELECT Coluna1, Coluna2
  FROM Tabela
  OFFSET (@Off) ROWS FETCH NEXT 5 ROWS ONLY;
    
01.10.2018 / 16:53
0

This should resolve your case: SELECT lin. * FROM (SELECT DISTINCT o.STORAGE_TYPE, COUNT (the.QUANTITY))                              qtd_materiais, rownum as
line                       FROM mopsao.vw_monitoramento_do@MOPSAO m INNER JOIN V                       IEW_ORDENS_A_COLETAR o                       ON                       m.DELIVERY = o.DELIVERY AND m.cod_mat_c = o.MATERIAL WHERE                       m.status_andamento = 'Pickado'                       GROUP BY o.STORAGE_TYPE ORDER BY qtd_materials DESC) lin where

    
01.10.2018 / 17:04