Add a column with the row number in the select result

0

How can I add the row number of the select result to an additional column?

For example:

select e.ds_estados  
  from estados e

This select would return me the registered states

    AC
    AL
    AM
    ...
    TO

I would like next to the state to return the line number together

    1  -  AC
    2  -  AC
    3  -  AC
    ...
    27  - TO
    
asked by anonymous 24.03.2017 / 20:09

2 answers

0

Thank you Jeferson Almeida!

I've found another way to do this too, for those who are interested, follow the code:

select rownum linha, 
       a.estado estado 
from (select b.estado     
        from estados b) a
    
24.03.2017 / 20:47
0

To do this you can use the row_number() function below as an example of how to use it, in the case I did it by ordering by column e.ds_estados

select  row_number() over (order by e.ds_estados) linha, e.ds_estados  
from estados e
    
24.03.2017 / 20:23