Can I execute an autonumber sequence in SELECT for Oracle?

I need to do a task in Oracle, I do not know how I can do it.

Ok, I need to do SELECT when I define an autonumber sequence on the fly.

For instance:

Select autonumber(1, 9000) as auto from some_table

And the result will be

auto
------
1
2
3
4
5
6
7
8
9
10
...
9000

Could this be done? Is there any oracle function in a function that will help me do this?

+3
source share
3 answers
select 
  rownum
from 
  dba_objects, 
  dba_objects
where
  rownum <= 9000;
-2
source

If you need a sequence of numbers that does not depend on the rows in the actual table, and not the numbering of the rows returned (in this case, look rownumor row_number()), you can do:

select level as auto
from dual
connect by level <= 9000;
+17
source

Oracle, rownum

select rownum as auto, other1, other2 from some_table

ANSI ROW_NUMBER() Oracle

+1

Source: https://habr.com/ru/post/1787654/


All Articles