gpt4 book ai didi

oracle10g - 在插入语句中使用两个 .nextval

转载 作者:行者123 更新时间:2023-12-02 05:41:07 25 4
gpt4 key购买 nike

我正在使用 oracle 数据库并面临一个问题,其中两个 id_poduct.nextval 创建为错误:ORA-00001:违反唯一约束 (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;

最佳答案

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
);

这不使用 insert all 语法,但如果您只插入同一个表,它的工作方式相同。

关于oracle10g - 在插入语句中使用两个 .nextval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10947743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com