如何在Oracle中多行插入序列?

时间:2017-07-18 06:58:45

标签: sql oracle

我希望在Oracle中的表中插入多行。但它让我很困惑: 我不能用

insert into pager (PAG_ID,PAG_PARENT,PAG_NAME,PAG_ACTIVE)
          (select seq_paper.nextval,'Multi 8000',1 from dual
 union all select seq_paper.nextval,'Multi 8001',1 from dual)

因为table1需要是新的。我需要在存在的table1中插入一些行。

我也不能用

Restrictions on Sequence Values You cannot use CURRVAL and NEXTVAL in the  
following constructs:  
■ A SELECT statement that is combined with another SELECT statement with the  
UNION, INTERSECT, or MINUS set operator ;
...and other constructs

因为oracle告诉我:

{{1}}

2 个答案:

答案 0 :(得分:2)

您可以对select进行修改,以便nextval不在union

结果如下:

insert into pager (PAG_ID,PAG_PARENT,PAG_NAME,PAG_ACTIVE) 
    select seq_paper.nextval, NULL, a, b from 
        (select 'Multi 8000' a, 1 b from dual 
         union all 
         select seq_paper.nextval,'Multi 8001',1 from dual)

答案 1 :(得分:1)

使用nextval一次并在子查询中创建数据:

800px