首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Oracle MERGE INTO的应用

2012-10-17 
Oracle MERGE INTO的使用在时常操作数据库,我们会有一个批量的增量更新的动作。一般来说,我们使用游标。crea

Oracle MERGE INTO的使用

在时常操作数据库,我们会有一个批量的增量更新的动作。

一般来说,我们使用游标。

create cursor ....

然后读取每一条记录,看看表里面有没有记录,没有记录就插入,有记录就更新。

可是游标操作的效率让人凌乱。

?

于是乎,DB2和Oracle都支持的MERGE INTO语句发挥了用处。

?

先看一段代码。

merge into fares t  using (select DEPART, ARRIVE, price from my_table) tmp  on (t.depart = tmp.depart      and t.arrive = tmp.arrive)  when matched then    update set t.price = tmp.price  when not matched then    insert values (tmp.depart, tmp.arrive, tmp.price)  ;

?

?

热点排行