表A:
id
表B  id_b
表C  id_icselect decode(a.id_type,
1,(select b.b_desc from B b where b.id_b=a.id_a),
2,(select c.c_desc from C c where c.id_c=a.id_a)
) discription,
a.*
from A a
这条语句还可以怎么写?不用decode,兄弟们多多发贴,多多益善

解决方案 »

  1.   

    select case when a.id_type=1 then b.b_desc when a.id_type=2 then c.c_desc else null end id_type,a.*
    from a
    left join b on b.id_b=a.id_a
    left join c on c.id_c=a.id_a
      

  2.   

    还是应该用decode
    不过,最好不要楼主的这种子查询,1楼的左连接更好
      

  3.   

    可以 写成个procedure 用if then 条件语句
      

  4.   

    用Decode有啥不好
    你可以用union连接
    select b.b_desc description,a.*
    from A a,B b
    where a.id_a=b.id_b and a.id_type=1
    union
    select c.c_desc description,a.*
    from A a,C c
    where a.id_a=c.id_c and a.id_type=2
      

  5.   

    最好能用decode()函数,是一个很强大的东东,性能最好,oracle强烈建议使用
      

  6.   


    select nvl((select b.b_desc
                 from B b
                where b.id_b = a.id_a
                  and a.id_type = 1),
               (select c.c_desc
                  from C c
                 where c.id_c = a.id_a
                   and a.id_type = 2))) discription, a.*
      from A a