Welcome 微信登录

首页 / 数据库 / MySQL / Oracle update关联表的思路总结

1、其中最普通的是update t1 set b=(select b from t2 where t1.a=t2.a);但是,要注意空值的影响,如果怕空值的影响,要写成update t1 set tname= (select sname from t2 where t1.id=t2.id)where exists(select 1 from t2 where t1.id=t2.id);2、对视图的UPDATE语句update (select /*+use_hash(t1,t2)*/ t1.tname b1,t2.sname b2from t1,t2 where t1.id=t2.id)set b1=b2;这种方法效率高,但是要注意两个关联字段都要有唯一性索引!避免ORA-01427: 单行子查询返回多个行3、存储过程declarecursor c is select t1.*,t1.rowid from t1;beginfor c1 in cloopupdate t1 set tname=(select sname from t2 where id=c1.id)where rowid=c1.rowid and exists (select 1 from t2 where c1.id=t2.id);end loop;end;但是还是要注意要有exists的语句,否则一样解决不了空值问题4、merge也可以进行update:思路4:merge update更新 http://www.linuxidc.com/Linux/2012-08/67443.htmOracle 11gR2 RAC安装 报【INS-20802】(PRVF-5436) 错误Oracle ORA-28002: the password will expire within 10 days相关资讯      Oracle基础知识 
  • 查看Oracle 32位还是64位(x86 or   (10/05/2014 19:10:00)
  • Oracle中表的建立与修改-五种约束  (02/07/2013 09:49:18)
  • Oracle select 语句字段连接  (12/17/2012 14:51:53)
  • Oracle online redo log 基础知识  (02/09/2013 09:43:04)
  • 如何查看Oracle数据库的session阻  (01/01/2013 09:11:15)
  • Oracle Redo Log 及Logmnr配置使用  (12/14/2012 19:36:51)
本文评论 查看全部评论 (0)
表情: 姓名: 字数