case when 语法,使用的时候我看到好像只能用
case...when 
 then 'A'
else
 'B'但是我目前不想在then中简单的显示一个字符串,想显示列值,请问怎么做?下面的代码报错...“table1 A标识符无效”请大家指点,谢谢!!
case...when 
 then table1.A
else
 table1.A + 10

解决方案 »

  1.   

    SELECT 
          CASE deptno when 10
               then dept.dname
          else
               dept.loc ||deptno
          END result  --可能是你少了end
    FROM deptRESULT
    -----------------
    ACCOUNTING
    DALLAS20  
    CHICAGO30 
    BOSTON40  
      

  2.   

    case ... when 
     then table1.A
    else
     table1.A + 10
    end
      

  3.   


    select * from yyq2;
    -------------------------------------------------
    1 100
    2 200
    3 300select 
    (case id when 1 then money
    when 2 then money + 10
    end) moneyTemp
    from yyq2
    ---------------------------------------------------
    100
    210
      

  4.   

    注意case函数的case语句的区别
    case函数,格式:case ... when .. then ... else... end,在使用普通函数的地方都可以使用。
    case语句,格式:case ... when .. then ... else... end case,只能在pl/sql过程中使用。
      

  5.   

    我写了end了,但是我发现时由于when case 写数字,else写字符串导致的....
    看来需要匹配上,多谢大家