table1  字段 a1,a2,a3,a4  主键 a1
  table2  字段 a1,b2,b3,b4  主键 a1
 现在想更新table1中满足table1.a1=table2.a1记录中字段a2的值 , table1.a2=table1.a2-table2.b2
 我写的
    update table1 a set table1.a2=table1.a2 - (select b.b2 from table2 b
where a.a1=b.a1  and a.a4='000001')
where  a.a4='000001'
我感觉没问题 可是总执行不了 提示 ORA-00936: 缺少表达式
使用oracle8.0.5

解决方案 »

  1.   

    update table1 set ColA = '' from table1 a, (Select ColA from tableB) b
    where a.ColA = b.ColA
      

  2.   

    请问楼上的 这个SQL语句在ORACLE能执行吗?
      

  3.   

    update table1 
    set table1.a2=table1.a2-table2.b2
    from table2
    where table1.a1=table2.a1
      

  4.   

    首先谢谢apartst,但是你写的 我实验了一下无法执行!错误!
     也谢谢  ncwuhh 关注,但我就是执行不了使用的是oracle8.0.5 
      不会和oracle版本有关系吧!呵呵!
      

  5.   

    update table1 a set a2=a2-(select b2 
                               from table2 b
                               where a.a1=b.a1 and a.a4='000001')
    where a.a1=(select a1 from table2 c where a.a1=c.a1) and a.a4='000001';
      

  6.   

    update table1 a 
      set a.a2 = a.a2 - (select b.b2 from table2 b where b.a1 = a.a1)
      where a.a4='000001'
      

  7.   

    谢谢各位了。可是我还是无法执行,楼上的2位我看了一下。好象也没有问题,可是问题依然。
    和 我写的好象也差不多。但为什么?????谁能给我解释一下。难道和ORACLE有关系???
    请各位实验一下再次谢谢大家的关注!!!!!!!!!!!!
      

  8.   

    >>   update table1 a set table1.a2=table1.a2 - (select b.b2 from table2 b
    >>where a.a1=b.a1  and a.a4='000001')
    >>where  a.a4='000001'改为: update table1 set a.a2=a.a2 -b.b2 from table1 a, table2 b 
    where a.a1=b.a1 and a.a4='000001'