简体   繁体   中英

cx_oracle PK autoincrementarion

can I get some advice, how to make mechanism for inserts, that will check if the values of PK is used? If it is not used in the table, it will insert row with number. If it is used, it will increment value and check next value if it's used. So on...

This is too long for a comment.

You would need a trigger in the database to correctly implement this functionality. If you try to do it in the application layer, then you will be subject to race conditions in a multi-client environment.

Within Oracle, I would recommend just using an auto-generated column for the primary key. Don't try inserting it yourself. In Oracle 12C, you can define this directly using generated always as . In earlier versions, you need to use a sequence to define the numbers and a trigger to assign them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM