现在有两张完全一致的表,a 和 b,他们的唯一索引是 sqlnum
且a表的sqlnum不会跟b表的sqlnum相同
现在我想根据sqlnum来更新表中的step字段,但是不知道该sqlnum在哪张表中,
能否一个sql语句解决。。

解决方案 »

  1.   

    select * from
    (select sqlnum,'a' tabname from a
      union all
      select sqlnum,'b' from b)
    where sqlnum=?
      

  2.   

    sqlnum,A表和B表有没有重合的,如果没有,将两表union做成一张视图,然后更新视图。
      

  3.   

    直接写两个update语句,条件都是一样的!A和B表只能有一个表更新,也不会有什么异常发生的!因为A和B中的sqlnum是没有重复的!这是最简的方法!没有必要先查出来!
      

  4.   

    是要更新啊..
    那么不能用union 视图直接更新
    可以建个替代触发器,然后更新视图;或者写个过程,将要更新的sqlnum和step作为传参
      

  5.   

    create or replace trigger tgab
    instead of update on ab
    for each row
    begin
    update a set step=:new.step where sqlnum=:new.sqlnum;
    if sql%rowcount=0 then
    update b set step=:new.step where sqlnum=:new.sqlnum;
    end if;
    end;然后更新视图ab即可(ab可以是union all视图,也可以是全连接视图)