标签:意义 acl span 16px ble div lis code 字段
Oracle中,要实现判断有数据则更新,无数据则插入功能,要用到Merge into来实现(Oracle 9i引入的功能),其语法如下:
本方法适用于大数据量更新
MERGE INTO table_name alias1 USING (table|view|sub_query) alias2 ON (join condition) WHEN MATCHED THEN UPDATE table_name SET col1 = col_val1, col2 = col_val2 WHEN NOT MATCHED THEN INSERT (column_list) VALUES (column_values);
严格意义上讲,”在一个同时存在Insert和Update语法的Merge语句中,总共Insert/Update的记录数,就是Using语句中alias2的记录数”。
有一个表T,有两个字段a、b,我们想在表T中做Insert/Update,如果条件满足,则更新T中b的值,否则在T中插入一条记录。
MERGE INTO T T1 USING (SELECT ‘1001‘ AS a,2 AS b FROM dual) T2 ON ( T1.a=T2.a) WHEN MATCHED THEN UPDATE SET T1.b = T2.b WHEN NOT MATCHED THEN INSERT (a,b) VALUES(T2.a,T2.b);
标签:意义 acl span 16px ble div lis code 字段
原文地址:http://www.cnblogs.com/lisidapao/p/6879810.html