Oracle10g 在insert语句中使用two.nextval
我在使用oracle数据库时遇到一个问题,其中两个id_poduct.nextval创建为错误:Oracle10g 在insert语句中使用two.nextval,oracle10g,Oracle10g,我在使用oracle数据库时遇到一个问题,其中两个id_poduct.nextval创建为错误:ORA-00001:unique constraint(SYSTEM.SYS_C004166)违反了 它是一个主键。使用全部是一项要求。我可以在声明中使用2.nextval吗 insert all into sale_product values (id_product.nextval, id.currval, 'hello', 123, 1) into sale_product va
ORA-00001:unique constraint(SYSTEM.SYS_C004166)违反了
它是一个主键。使用全部是一项要求。我可以在声明中使用2.nextval吗
insert all
into sale_product values (id_product.nextval, id.currval, 'hello', 123, 1)
into sale_product values (id_product.nextval, id.currval, 'hi', 123, 1)
select * from dual;
first
INSERT中的id\u product.NEXTVAL
的值与second
INSERT的值相同,因此您将获得唯一约束
冲突。如果删除约束并执行插入,将注意到重复的值
唯一的方法是按顺序执行两个批量插入,或者有两个不同范围的独立序列,后者需要大量的编码和检查
create table temp(id number ,id2 number);
insert all
into temp values (supplier_seq.nextval, supplier_seq.currval)
into temp values (supplier_seq.nextval, supplier_seq.currval)
select * from dual;
ID ID2
---------- ----------
2 2
2 2
参考
多表insert语句的子查询不能使用序列
这并没有使用insert all
语法,但如果您只是插入到同一个表中,它的工作方式是相同的
insert into sale_product
select id_product.nextval, id.currval, a, b, c
from
(
select 'hello' a, 123 b, 1 c from dual union all
select 'hi' a, 123 b, 1 c from dual
);