如何将多个带有序列值的行插入到oracle中? [英] How can I insert multiple rows into oracle with a sequence value?
本文介绍了如何将多个带有序列值的行插入到oracle中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
However, one of the values I am inserting is taken from a sequence, i.e.
insert into TABLE_NAME
(COL1,COL2)
select MY_SEQ.nextval,'some value' from dual
union all
select MY_SEQ.nextval,'another value' from dual
;
如果尝试运行它,则会收到ORA-02287错误.有什么办法解决这个问题,还是我应该只使用很多INSERT语句?
If I try to run it, I get an ORA-02287 error. Is there any way around this, or should I just use a lot of INSERT statements?
如果我必须为序列以外的所有其他列指定列名,那么我会失去原有的简洁性,因此这是不值得的.在那种情况下,我将只使用多个INSERT语句.
If I have to specify column names for all other columns other than the sequence, I lose the original brevity, so it's just not worth it. In that case I'll just use multiple INSERT statements.
推荐答案
这有效:
insert into TABLE_NAME (COL1,COL2)
select my_seq.nextval, a
from
(SELECT 'SOME VALUE' as a FROM DUAL
UNION ALL
SELECT 'ANOTHER VALUE' FROM DUAL)
这篇关于如何将多个带有序列值的行插入到oracle中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文