decode(field,if,then,elseif,then...else)

解决方案 »

  1.   

    decode(col_name,1,值1,2,值2,3,值3,null)==>
    if col_name=1 then
    dbms_output.put_line(值1);
    elsif col_name=2 then
    dbms_output.put_line(值2);
    elsif col_name=3 then
    dbms_output.put_line(值3);
    else
    dbms_output.put_line(null);
    end if;
      

  2.   

    decode(col_name,1,值1,2,值2,3,值3,null)==>
    if col_name=1 then
    dbms_output.put_line(值1);
    elsif col_name=2 then
    dbms_output.put_line(值2);
    elsif col_name=3 then
    dbms_output.put_line(值3);
    else
    dbms_output.put_line(null);
    end if;
      

  3.   

    那不是和iif一样?用sql语句这么写的:
    case statement when case1 then statemwnt…………end case是这个意思吗?
      

  4.   

    类似于SQL Server中的case when功能
      

  5.   

    select case when tab_1.a = tab_1.b then 'error'
                when tab_1.c = tab_1.d then 'ok'
    from tab_1
    大虾们以上语句在Oracle中如何实现....
      

  6.   

    select case when tab_1.a = tab_1.b then 'error'
                when tab_1.c = tab_1.d then 'ok'
                else 'none'
           end case     
    from tab_1
    大虾们以上语句在Oracle中如何实现....
      

  7.   

    sql语句不行吗?
    在Sql语句中可以用if吗?
      

  8.   

    decode 跟if一样
    example :
    select decode(item_name ,'A',1,'B',2,'C',3,4) FROM TABLE_NAME;
    也就是
         if item_name = 'A' THEN 
          item_name := 1;
         elsif item_name = 'B' THEN
           item_name := 2;
         elsif item_name = 'C' THEN
           item_name := 3;
         else
           item_name := 4; 
         end if;
      

  9.   

    是和sql server 的iif一样
      

  10.   

    但是decode可以有多个分支
    而iif好像只有两个分支
      

  11.   

    其实有点不一样了
    iif(逻辑表达式A,value1,value2)
    如果逻辑表达式A值为True,那么返回value1,否则返回value2Decode(表达式A,表达式1,value1,表达式2,value2...)
    如果表达式1等于表达式A,返回value1,否则
    如果表达式2等于表达式A,返回value2,否则其实上面几位大虾们说得都是对的!