本来要写个update语句
update table_a A
       set A.flag=1
       where A.id in (select B.id from table_b B)
结果误写成
update table_a A
       set A.flag=1
       where A.id in (select A.id from table_b B) 
为啥错误的写法,oralce编译不报错呢?
而且  只要B表中有数据,A就全表更新了
      B表没数据,A表就update了0条记录,
谁能解释下?是oracle的bug么?

解决方案 »

  1.   

    (select A.id from table_b B)这句是可以执行的
    你说的错误的写法只是和你的本意不一致,语法上没错
      

  2.   

    select A.id from table_b B单独的语句运行:
    提示:ora-00904的错误!
      

  3.   


    select * from test a
    where name in(
    select a.name from test b)这个就不提示,直接显示
    select * from test a
      

  4.   

    表A和B做交叉,只要B中有数据,就更新A的所有数据;(也可以把B换成dual一样)
    B中没有数据,就更新0行;
      

  5.   

    update table_a A 
          set A.flag=1 
          where A.id in (select A.id from table_b B) 
    可以这样理解吧:。
    如果B有数据,那么子查询返回A的所有id,A表全部更新;
    如果B没有数据,子查询返回空集合,A表0行更新。
      

  6.   


    你这个不是语法错误,是逻辑错误,oracle编译的时候,检查语法而已,他不知道你需要的逻辑。
      

  7.   


    恩,没有错,老大说的对,是逻辑错误,oracle编译的时候只检查语法不检查逻辑的。
      

  8.   

    对, where A.id in (select A.id from table_b B) 和
     where A.id in (select '' from table_b B)效果是一样的!
      

  9.   

    没有错误
    若b表有记录,第二句会将a表的每条记录都作修改
    那个条件没有意义
    若b表没有记录,则a表修改的记录数为0
      

  10.   

    没有错误啊如果b表有记录时,所有的条件都满足,所以全表更新了如果b表没有记录时,不满足where条件,所以没有更新
      

  11.   

    语法上没有错误,不会报错.你可以在后面的查询中用一个别的表做查询,但是筛选字段用a,你a.一下就能出来a的字段的信息了.这个是你自己的写法的问题,不是bug
      

  12.   

    SQL> select * from test1;        ID NAME
    ---------- --------------------
             1 wh
             2 wp
             3 wrSQL> select * from test3;        ID NAME
    ---------- --------------------
             3 www
             1 rrrr
             6 hhh
    SQL> update test1 a
      2  set a.name='xxx'
      3  where a.id in (select a.id from test3 b)
      4  ;3 rows updated.
    SQL> update test1 a
      2  set a.name='xxx'
      3  where a.id in (select a.id from dual)
      4  ;3 rows updated.SQL> rollback;Rollback complete.SQL> update test1 a
      2  set a.name='xxx'
      3  where a.id in (select null from dual)
      4  ;0 rows updated.
    你的说法好像不完全正确哦。
    select a.id from dual和select null from dual有什么区别吗
    为什么执行结果会相反?BTW: 这算是一个BUG吗??
      

  13.   

    update table_a A
       set A.flag=1
       where A.id in (select A.id from table_b B) 语法上没有错。并且结果应该是更新你A表中所有记录。
      

  14.   


    select a.id from dual和select null from dual当然有区别。
    子查询是a.id IN (.....), 你select null 肯定最终结果是False
      

  15.   

    SQL> update test1 a
      2  set a.name='xxx'
      3  where a.id in (select a.id from dual)
      4  ;3 rows updated.SQL> rollback;Rollback complete.SQL> update test1 a
      2  set a.name='xxx'
      3  where a.id in (select null from dual)
      4  ;0 rows updated.
    不太明白,为什么select a.id from dual成功而select null from dual却不成功
    dual中明明也没有a.id这个字段呀,按说IN操作符后面不是应该是个值列表吗
    只有a.id符合值列表中的某个值的时候where条件才会为真,才会进行修改
      

  16.   

    select a.id from dual
    取的是子查询外面的test1.id。。
      

  17.   

    因为你没表a 
    本来要写个update语句 
    update table_a A 
          set A.flag=1 
          where A.id in (select B.id from table_b B) 
    你这个写法有表a 
      

  18.   


    select a.id from dual可以查询出来A表的ID列的值,where条件成立,所以它会更新.而select null from dual查不到A表中ID列的值,所以where条件不成立,当然不会更新.