存储过程中不可以用case语句吗?

解决方案 »

  1.   

    Compilation errors for PROCEDURE TESTLDJ3Error: PLS-00103: 出现符号 "CASE"在需要下列之一时:
           (-+modnull<an identifier>
              <a double-quoted delimited-identifier><a bind variable>table
              avgcountcurrentmaxminpriorsqlstddevsumvarianceexecutethe
              foralltimetimestampintervaldate
              <a string literal with character set specification>
              <a number><a single-quoted SQL string>
    Line: 7
    Text: case when stage = '检验' then sum(qty) end  xpjy,
    我试过,不可以的。
      

  2.   

    应该这样用
    sum(case when stage = '检验' then qty else 0 end) xpjy,
      

  3.   

    我的写法
    case when stage = '检验' then sum(qty) end  xpjy,
    和你的写法
    sum(case when stage = '检验' then qty else 0 end) xpjy,
    单独作为sql语句执行都是可以的。
    但是放在存储过程里面就不可以了。
      

  4.   

    你说不行我也没有办法,select sum(case when stage = '检验' then qty else 0 end) xpjy from yourtable group by ....看看你的存储过程写的是什么 贴出来看看
      

  5.   

    换成decode就可以了。
    case不行。
      

  6.   

    你可以用最简单的case测试一下,确实不行。
      

  7.   

    create or replace procedure aaa
    is
    aa varchar2(100);
    begin
      select case when 1=2 then '1' else '2' end into aa from dual;
      dbms_output.put_line( aa );
    end;
    /
    declare
     i integer;
    begin
     aaa;
    end;
      

  8.   

    Compilation errors for PROCEDURE WIPTRACKER.AAAError: PLS-00103: 出现符号 "CASE"在需要下列之一时:
           (*-+allmodnull
              <an identifier><a double-quoted delimited-identifier>
              <a bind variable>tableavgcountcurrentdistinctmaxminpriorsql
              stddevsumuniquevarianceexecutetheforalltimetimestampinterval
              date<a string literal with character set specification>
              <a number><a single-quoted SQL string>
    Line: 5
    Text: select case when 1=2 then '1' else '2' end into aa from dual;
      

  9.   

    我的是oracle 8i ,会不会到了9i,就支持在存储过程中写case语句了?8i下,改用decode写是可以的。
      

  10.   

    8i啊!!!8i 中已经支持case,只不过8i 提供的PL/SQL编译器不支持,要想在8i 的存储过程中使用,将上面的组织成动态SQL就可以了,那就不如使用decode了