oracle autoincrement with sequence and trigger is not working correctly

前端 未结 2 614
盖世英雄少女心
盖世英雄少女心 2020-12-07 03:53

here is my problemI have this code to make an autoincrement variable in oracle database:

CREATE TABLE Korisnici
    (
        id_korisnika number PRIMARY KEY         


        
相关标签:
2条回答
  • 2020-12-07 04:14

    It's not a problem. You have probably specified cache 10 in your sequence creation script. If you change this to nocache it will help with the gaps, at the cost of a hit to performance, but they'll never go away completely as any rollbacks done, and killed inserts etc will use up values. Please see this Ask Tom post.

    At the end of the day it shouldn't matter in the slightest. If you're relying on an unbroken sequence as the key of your table then you probably have a problem with your data rather than sequences.

    0 讨论(0)
  • 2020-12-07 04:27

    Specifying the SEQUENCE with NOCACHE will stop a session caching 20 numbers at a time and help.

    create sequence test_seq
    start with 1 
    increment by 1
    NOCACHE;
    

    However, if you're hoping for a completely contiguous sequence this is very difficult to achieve - numbers taken from the sequence are "lost" if (for example) an insert is rolled back.


    Based on your comment, I wonder if you're forgetting to COMMIT?

    0 讨论(0)
提交回复
热议问题