请问DECODE能不能在from 语句中使用?

解决方案 »

  1.   

    decode其实是一个IF的判断!
    如:decode(值,if1,then1,if2,then2,......,else then)
      

  2.   

    from子句中可以,不能对表明用from
      

  3.   

    请问DECODE能不能在from 语句中使用?
    什么意思?举个例子!
      

  4.   

    比如有两个表table1,table2,和变量flag
    我用select....from decode(flag,1,tabel1,2,table2) where ....
    是不是说这不可以用的?如果不可以用,那请问我有什么办法可以实现相同的功能?
      

  5.   

    直接在sql语句里是没发实现的!
    过程里就可以了!
      

  6.   

    select....from decode(flag,1,tabel1,2,table2) where ....
    flag是那里来的!如果是程序里,那就程序中就写好,再传进去啊!
      

  7.   

    flag 是游标里传进去的,我现在在写的是存储过程里碰到的问题,游标无法通过编译.
      

  8.   

    既然这样就方便了,哈哈!
    过程里多一步,
    tablname 
    if flag then 
     tablname := tabel1;
    else 
     tablname := tabel2;
    end if;
    execute immediate 'select....from '''||tablname||'''where ....';
      

  9.   

    但这是游标,请问我该怎么写?我是要通过外部传进来的FLAG,从几张极其相似的表中,挑选出一张,游标的select语句只有表名是不同的,如果我不写成一句,大概就要写十几个只有表名不同的游表了.
      

  10.   

    decode.
    如同if--elseif-elseif-这种条件语句.
      

  11.   

    究竟能不能用在from 语句中啊?高手快来,帮帮忙啊
      

  12.   

    可以啊 为什么不能?
    select decode(值,if1,then1,if2,then2,...,else) from table_name;
      

  13.   

    不能这样用select....from decode(flag,1,tabel1,2,table2) where ....
    替代的方法:
    select * from tabel1 where flag=1
    union 
    select * from table2 where flag=2
      

  14.   

    decode只能用于col, 不能用于table