Search code examples
sqloracle-databasejdbcauto-increment

Auto increment a field without sequence in ORACLE


I am trying to increment a field without sequence . Is there any possiblities?? can i do something like this

INSERT INTO Test 
VALUES ((
         SELECT COUNT(ID) 
         FROM Test)+1)

Please suggest me a way to do this


Solution

  • If your sequence field is called seq_fld for example you could use

    insert into Test values ( (select max(seq_fld) from Test) + 1)
    

    It is advisable to have unique constraint on seq_fld