Oracle如何批量更新按指定条件查出的结果数据
查询语句selecth.objname,s.longonname,s.isclosedfromsysusers,humreshwheres.isclosed='0'and...
查询语句
select h.objname,s.longonname,s.isclosed from sysuser s,humres h where s.isclosed='0'
and h.id=s.objid and h.hrstatus='4028804c16acfbc00116ccba13802936
更新语句
update sysuser set isclosed = '1'
希望把select查出来的数据,直接update
请高手指教 展开
select h.objname,s.longonname,s.isclosed from sysuser s,humres h where s.isclosed='0'
and h.id=s.objid and h.hrstatus='4028804c16acfbc00116ccba13802936
更新语句
update sysuser set isclosed = '1'
希望把select查出来的数据,直接update
请高手指教 展开
展开全部
update sysuser set isclosed = '1'
where longonname in(
select distinct s.longonname from sysuser s,humres h where s.isclosed='0'
and h.id=s.objid and h.hrstatus='4028804c16acfbc00116ccba13802936
)
where longonname in(
select distinct s.longonname from sysuser s,humres h where s.isclosed='0'
and h.id=s.objid and h.hrstatus='4028804c16acfbc00116ccba13802936
)
追问
还想请教下,为什么我通过以下语句无法实现按要求更新,只能更新所有的数据
update sysuser set isclosed='1' where exists (select h.objname,s.longonname,s.isclosed from sysuser s,humres h where s.isclosed='0'
and h.id=s.objid and h.hrstatus='4028804c16acfbc00116ccba13802936');
追答
exists 返回TRUE 和 FALSE。是和相关表比较的。而你上面的数据
(select h.objname,s.longonname,s.isclosed from sysuser s,humres h where s.isclosed='0'
and h.id=s.objid and h.hrstatus='4028804c16acfbc00116ccba13802936');
只是返回了查询的结果为TRUE。。并不能代表你UPDATE的数据关联,所以会更新整个sysuser 表。
能否试下:(只是测试啊。我没有具体实现过)
update sysuser a set isclosed='1' where exists (select h.objname,s.longonname,s.isclosed from sysuser s,humres h where s.isclosed='0'
and h.id=s.objid and h.hrstatus='4028804c16acfbc00116ccba13802936' and a.longonname =s.longonname );
正确的EXISTS语句:
select * from tablea a where exists (select * from tableb b where a.id = b.id);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |