数据库系统为oracle 10g,小弟初学,遇到点问题,请教各位前辈:
有一张表,名称为t1,分别有字段id1,value1
id1 value1   
1 LENOVO
2 CD
3 DVD   
另外一张表,名称为t2,分别有字段id2 value2
id2 value2   
1 LENOVO
2 FD
3 DVD   求一update语句:
当t1与t2表的id1的值与id2相同时,则t1表的对应value值也等于t2表中的value值,满足这样的sql语句不知如何写,请教各位?

解决方案 »

  1.   

    update t1 set value1=(select value2 from t2 where t1.id1=t2.id2)
      

  2.   


    update t1 set value1=(select value2 from t2 where t1.id1=t2.id2 and rownum=1)
    where exists(select 1 from t2  where where t1.id1=t2.id2 )
      

  3.   

    顶一楼  接个分  楼主是在触发器还是全表更新啊  上面的sql重复执行的话最好再加点控制
      

  4.   

    update t1 set value1 = t2.value2 from t1 where exists (select 1 from t2 where t2.id2 = t1.id1)
      

  5.   

    update t1 set value1 = (select value2 from t2 where t2.id2 = t1.id1) where exists (select 1 from t2 where t2.id2 = t1.id1)
      

  6.   

    update t1 a set value1=(select value2 from t2  b where a.id1=b.id2)
    where exists(select 1 from t2 c where a.id1=c.id2)
      

  7.   


    update t1 set value1=(select value2 from t2 where t1.id1=t2.id2 and rownum<2)
    where exists(select 1 from t2  where where t1.id1=t2.id2 and t1.value1<>t2.value2)
      

  8.   


    update t1 set value1=nvl((select value2 from t2 where t1.id1=t2.id2 and rownum=1), value1);
      

  9.   

    update t1 a set value1=(select value2 from t2  b where a.id1=b.id2)  之类的方式效率方面很低下的。改为 update t1 ,t2 set t1.value1=t2.value2 where t1.id1=t2.id2;效率要好很多。
    我用一张7W数据表去更新4K的表中的一字段,前种方式要10多秒后者只要1秒
      

  10.   

       楼上是MySQL的语法吧,在Oracle中不能同时更新两张表!