oracle更新数据方式

三种在oracle里更新数据的方式:

1.替换更新
case when 替换当一个字段为空时,用一个字段替换它

select case when a is null then b else a end as data From A

2.插入更新
一个表的数据插入另一个表

insert into table1 select * from table2

3.指定条件下更新指定列

3.1update简单更新

update table1 set columnA=1 where columnB=100

3.2配合merge into大量更新

merge into table1 using 
(select *from table2 x  where  x.rowid =
(select MAX(y.rowid) from  table2 y  
where  x.columnA= y.columnA 
and x.columnB=y.columnB))
table2 on(table1.columnA=table2.columnA
and table1.columnB=table2.columnB)
#【匹配前提条件后形成1对1的关系】
when matched then update set 
table1.column1=table2.column1,
table1.column2=table2.column2,
table1.column3=table2.column3,
table1.column4=table2.column4

注:在满足table1的某几列与table2某几列完全相同时,能够得到唯一的一行
table1的值,此时用table2 的内容去更新table1的指定列,一对一更新。

其中merge into最推荐使用,不易出错,且更新速度快。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值