從oracle9i開始引入了insert all關(guān)鍵字支持將某張表的數(shù)據(jù)同時插入多張表單。語法如下:
Insert all Insert_into_clause [value_clause] subquery;
Insert conditional_insert_clause subquery;
如上所示,insert_into_clause用于指定insert子句;value clause用于指定值子句;subquery用于指定提供數(shù)據(jù)的子查詢;condition_insert_clause用于指定insert條件子句。
當(dāng)使用all操作符執(zhí)行多表插入時,在每個條件子句上都要執(zhí)行into子句后的子查詢,并且條件中使用的列必須在插入和子查詢的結(jié)果集中:
--使用all關(guān)鍵字執(zhí)行多表插入操作
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'的數(shù)據(jù),那么將執(zhí)行兩次插入。而使用first關(guān)鍵字就可以避免這個問題。使用first關(guān)鍵字時,如果有記錄已經(jīng)滿足先前條件,并且已經(jīng)被插入到某個表單中(未必非要是同一個表),那么該行數(shù)據(jù)在后續(xù)插入中將不會被再次使用。也就是說使用first關(guān)鍵字,原表每行數(shù)據(jù)按照執(zhí)行順序只會被插入一次。
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 閱讀(904)
評論(0) 編輯 收藏 所屬分類:
oracle