Is there a similar clause similar to LIMIT in PL / SQL

0

I'm using PL / SQL and would like to know if you have any clause or sql script that is similar to the sql LIMIT clause, I've been searching here and found rownum < = X, but does not meet what I want to do. I'll try to explain

SELECT

select 
  codfil, coditprod, qtde 
from 
  mov_lotevencto
order by 
  qtde desc;

Result

  CODFIL         CODITPROD      QTDE
1 106            65303          6098,4
2 106            65303          5450,4
3 106            65303          3648,6
4 106            50635          3050,8
5 106            58973          2947,8

If I use rownum

asked by anonymous 23.02.2018 / 16:04

2 answers

4

The ROWNUM column, Oracle returns the row number within the search result.

The number is assigned according to the order in which the rows are drawn from the table / sql.

This order is set before the ORDER BY , as this is done after the "resultSet" is created.

For your SQL to work correctly you have to do:

select * from (
  select 
    codfil, coditprod, qtde 
  from 
    mov_lotevencto
  order by 
    qtde desc
) where rownum <= 1;

Practical Example

I made a practical example

link

    
23.02.2018 / 16:14
1

In mysql:

SELECT * FROM tabelaxpto LIMIT 1

In sql:

SELECT TOP 1* FROM tabelaxpto 

In sql pl:

SELECT * FROM tabelaxpto WHERE rownum = 1
    
23.02.2018 / 17:07