INSERT INTO table (f1 ,f2 ,f3) SELECT 1 ,'a',3 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM table2 where a = b)
DUAL 為臨時表 ,也可以查詢真實表欄位插入。
需要插入多條資料時,可使用 UNION :
INSERT INTO table (f1 ,f2 ,f3) SELECT 1 ,'a',3 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM table2 where a = b) UNION SELECT 10 ,'ab',30 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM table2 where a = b)