使用序列的多个插入语句. [英] multiple insert statements using sequence.

查看:75
本文介绍了使用序列的多个插入语句.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用序列在表中插入多行
但是存在主键冲突.plzhelp

I have to insert multiple rows in a table using sequence
but there is primary key violation.plz help

推荐答案

您很有可能会重复使用序列中的相同值.

如果要基于选择查询插入数据,请使用选择内部的顺序.就像这样:
Most likely you re-use the same value from the sequence.

If you''re inserting data based on a select query, then use the sequence inside the select. So something like:
INSERT INTO MyTable (
   PrimaryKeyCol,
   SomeCol1,
   SomeCol2,
   ...)
SELECT
   MySequence.NextVal,
   SomeColumn,
   AnotherColumn,
   ...
FROM MyTable
WHERE ....



加法:

如果顺序已订购:
-运行



Addition:

If the sequence is ordered:
- run

select max(keycolumn) from yourtable;


-运行


- run

select sequence.nextval from dual;



现在,如果表中的最高值是例如10,而sequence.nextval返回7,则执行



now if the highest value in your table is for example 10 and the sequence.nextval returned 7, then execute

select sequence.nextval from dual;


3次


这篇关于使用序列的多个插入语句.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆