-1

Tried this several time, just wanted to know if there is a workaround

shasha0607
  • 123
  • 1
  • 9
  • 2
    Does [this](https://stackoverflow.com/questions/11296361/how-to-create-id-with-auto-increment-on-oracle) answer your question ? – Barbaros Özhan Mar 28 '20 at 08:30
  • 1
    It's not clear from you question if you are adding a new column that you need to populate, or if you have an existing column with existing data, and you want to start using auto increment for all future data. The correct solution will depend on that. – EdStevens Mar 28 '20 at 11:59

1 Answers1

3

You can take advantage of the identity column in this case as follows:

alter table test 
add col1 number generated always as  identity (start with 1 increment by 1)

Db<>fiddle demo

It will automatically assign the sequence number to the already existing rows and will give number in sequence to new inserts also.

Popeye
  • 35,427
  • 4
  • 10
  • 31
  • Can you suggest something for 11g as well? Would the solution be to create a squence? Will it assign a number to the existing rows? – shasha0607 Mar 28 '20 at 18:06