2017-06-02 85 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)