我用PL/SQL查询中遇到这么一个问题,其中A表的列1,列2跟B表的列3,列4相对应,如果B表列3,列4有值存在,则把相应的值赋值给A表的列1,列2.请问应该怎么写语句?

解决方案 »

  1.   

    update  A 
    set A.c1=(select B.c3 from B where B.c3 is not null and B.c4 is not null),
    set A.c2=(select B.c4 from B where B.c3 is not null and B.c4 is not null)
      

  2.   

    我看应该这样吧,
    假设A表和B表通过id关联查询
    select case when b.c3 is not null then b.c3 else a.c1 end c1,
    case when b.c4 is not null then b.c4 else a.c2 end c2
    from a
    left join b on a.id=b.id