oracle+update+阻塞,oracle update from 问题!

在 Oracle 数据库中,遇到一个更新问题,尝试更新 t_tmprpt_firstreplycosttime 表的某些字段,但错误地将所有数据都更新了。解决方法包括使用类视图更新和子查询限制更新范围。类视图更新是通过先提取匹配数据再进行更新,确保数据唯一性。子查询方法则是通过在 WHERE 子句中使用子查询来指定需要更新的记录。这两种方法都可以有效避免全表更新的问题。
摘要由CSDN通过智能技术生成

update t_tmprpt_firstreplycosttime t

set(t.firstreplytime,

t.dealstaff,

t.firstreplyfailcontent)

= (select a.suggesttime,

a.suggester,

substr(a.remark,instr(a.remark,'】',1)+2)

from t_wf_suggesthis a

where t.serialno = a.serialno

and t.serviceclassid = a.serviceclassid);update t_tmprpt_firstreplycosttime t

set (t.firstreplytime,

t.dealstaff,

t.firstreplyfailcontent)

= (select a.suggesttime,

a.suggester,

substr(a.remark,instr(a.remark,'】',1)+2)

from t_wf_suggesthis a

where t.serialno = a.serialno

and t.serviceclassid = a.serviceclassid);

想把t_tmprpt_firstreplycosttime

表中的3个字段数据更新为t_wf_suggesthis表中的

suggesttime, suggester,substr(a.remark,instr(a.remark,'】',1)+2)的值。条件是t表的

sreialno和serviceclassid都与a表中的相等。

问题:当我执行这条更新时候会把t表中的所有数据都更新了。

解决:oracle中没update from 这样的更新,可以考虑2种解决办法。

一,

update (select a.suggesttime atime,

b.firstreplytime btime,

a.suggester astaff,

b.dealstaff bstaff,

substr(a.remark,instr(a.remark,'】',1)+2) acontent,

b.firstreplyfailcontent bcontent

from t_wf_suggesthis a, t_tmprpt_firstreplycosttime b)

setbtime = atime,

btaff = astaff,

bcontent = acontent;update (select a.suggesttime atime,

b.firstreplytime btime,

a.suggester astaff,

b.dealstaff bstaff,

substr(a.remark,instr(a.remark,'】',1)+2) acontent,

b.firstreplyfailcontent bcontent

from t_wf_suggesthis a, t_tmprpt_firstreplycosttime b)

set btime = atime,

btaff = astaff,

bcontent = acontent;

这是类视图的更新方法,这也是oracle所独有的。

先把对应的数据全部抽取出来,然后更新表一样更新数据,这里需要注意的是,必须保证表的数据唯一性。

这就要求a,b两表的关联字段上都是具备唯一性的。

二,

update t_tmprpt_firstreplycosttime t

set(t.firstreplytime,

t.dealstaff,

t.firstreplyfailcontent)

= (select a.suggesttime,

a.suggester,

substr(a.remark,instr(a.remark,'】',1)+2)

from t_wf_suggesthis a

where t.serialno = a.serialno

and t.serviceclassid = a.serviceclassid)

where t.serialno in(select b.serialno

from t_wf_suggesthis b

where b.serialno = t.serialno

and b.serviceclassid = t.serviceclassid);update t_tmprpt_firstreplycosttime t

set (t.firstreplytime,

t.dealstaff,

t.firstreplyfailcontent)

= (select a.suggesttime,

a.suggester,

substr(a.remark,instr(a.remark,'】',1)+2)

from t_wf_suggesthis a

where t.serialno = a.serialno

and t.serviceclassid = a.serviceclassid)

where t.serialno in (select b.serialno

from t_wf_suggesthis b

where b.serialno = t.serialno

and b.serviceclassid = t.serviceclassid);

这种就是使用子查询来确定更新的数据。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值