從oracle9i開始引入了insert all關鍵字支持將某張表的數據同時插入多張表單。語法如下:
Insert all Insert_into_clause [value_clause] subquery;
Insert conditional_insert_clause subquery;
如上所示,insert_into_clause用于指定insert子句;value clause用于指定值子句;subquery用于指定提供數據的子查詢;condition_insert_clause用于指定insert條件子句。
當使用all操作符執行多表插入時,在每個條件子句上都要執行into子句后的子查詢,并且條件中使用的列必須在插入和子查詢的結果集中:
--使用all關鍵字執行多表插入操作
insertall
when birthday > '01-1月-08'theninto tdate1
when birthday < '01-1月-08'theninto tdate2
whenname = 'zhangsan'theninto tdate1
whenname = 'lisi'theninto tdate2
select * from tdate;
在上述操作語句中,如果原表tdate中存在既滿足birthday > '01-1月-08'又滿足name = 'zhangsan'的數據,那么將執行兩次插入。而使用first關鍵字就可以避免這個問題。使用first關鍵字時,如果有記錄已經滿足先前條件,并且已經被插入到某個表單中(未必非要是同一個表),那么該行數據在后續插入中將不會被再次使用。也就是說使用first關鍵字,原表每行數據按照執行順序只會被插入一次。
insertfirst
when birthday > '01-1月-08'theninto tdate1
when birthday < '01-1月-08'theninto tdate2
whenname = 'zhangsan'theninto tdate1
whenname = 'lisi'theninto tdate2
select * from tdate;
posted on 2009-09-12 09:24
Ke 閱讀(906)
評論(0) 編輯 收藏 所屬分類:
oracle