确保该列遵循Oracle中的序列

时间:2010-10-19 17:29:58

标签: oracle constraints sequence

是否有任何方法可以限制列(比如“ID”)以跟随创建的序列(比如“ID_SEQ”)?

如果没有自动约束,手动插入可能会使整个序列失控。可以做些什么来解决这个问题?只需拨打NextVal两次?

2 个答案:

答案 0 :(得分:7)

您可以使用触发器来完成此操作。例如:

create or replace trigger product_insert before insert on product for each row begin
select id_seq.nextval
into :new.product_id
from dual;
end;

答案 1 :(得分:3)