表一:tb1
结构:
    cardno       varchar(50)
    inserttime   date
-----------------------------
表二:tb2
结构
    keyno         varchar(50)
    trtime        date要求:用表1的inserttime更新表2的trtime(set tb2.trtime=tb1.inserttime) 
条件:where tb2.keyno=tb1.cardno以前在sql server 里面直接用以下语句就可以了,可ORACLE里面怎么不行了呢,麻烦大家给看看,或者给个语句。
update tb2 set trtime=b.inserttime from tb2 a,tb1 b where a.keyno=b.cardno

解决方案 »

  1.   

    update tb2 set trtime=(select b.inserttime from tb1 b where a.keyno=b.cardno)
    where exists(select 1 from  tb1 b where a.keyno=b.cardno)
      

  2.   

    update tb2  a set a.trtime=(select b.inserttime from tb1 b where a.keyno=b.cardno)
    where exists(select 1 from  tb1 b where a.keyno=b.cardno)
      

  3.   

    http://a.sili.blog.163.com/blog/static/5480959620099138119388/可以 参考
      

  4.   

    正确
    sql和pl/sql 语法还是有点差别的
      

  5.   

    merge tb2 a
    using tb1 b
    on a.keyno=b.cardno
    when matched then update set a.trtime=b.inserttime
      

  6.   


    --修正下语法问题
    merge into tb2 a
    using tb1 b
    on ( a.keyno=b.cardno)
    when matched then update set a.trtime=b.inserttime
      

  7.   

    数据量比较大,merge into的效率比update快很多
      

  8.   

    update tb2 set trtime=(select b.inserttime from tb1 b where a.keyno=b.cardno) 
    where exists(select 1 from  tb1 b where a.keyno=b.cardno)
      

  9.   

    update (select inserttime,trtime from tb1 A,tb2 B where B.keyno=A.cardno ) 
    set trtime=inserttime
      

  10.   

    update tb2 b set trtime=b.inserttime from tb2 a where a.keyno=b.cardno