2017-06-02 150 views
0

使用select我试图在同一时间使用选择多行插入表如下INSERT INTO在Oracle

insert into myTable values(myTable_Seq.nextval,100,select column1 from anotherTable where column1 not in(10,20)); 

这里我最后的值从另一个表WHERE条件选择的值。

我在这里失败了。它给了缺少的表达式错误。

我们可以这样做,还是必须做一个forloop。

在此先感谢。

+0

还有的例子就如何做到这一点的计算器没有短缺(见由Ryan答案在这里,https://stackoverflow.com/questions/7323407/insert-select-statement-in-oracle-11g )。 –

回答

3

如果你从一个SELECT插入您不必VALUES子句。

INSERT INTO mytable 
    SELECT mytable_seq.nextval, 
     100, 
     column1 
    FROM anothertable 
    WHERE column1 NOT IN (10, 
         20); 
1

您需要从anotherTable删除values,并使用序列值,并在查询中的固定值:

insert into myTable 
select myTable_Seq.nextval, 
     100, 
     column1 
from anotherTable 
where column1 not in(10,20)