首页 > 解决方案 > How to create a unique id for each insert in Oracle

问题描述

I would like to have a unique ID for each INSERT. All rows for each INSERT must have the same ID, but different to the other IDs in the table. Is any standard way to do that in ORACLE?

标签: sqloracle

解决方案


您可以在 Oracle 中使用序列:

CREATE SEQUENCE my_sq START WITH 1 INCREMENT BY 1;

然后,当您要插入时,请使用 my_seq.NEXTVAL 代替“按插入 ID”

有关序列的更多信息


推荐阅读