带有oracle过程的块中的CASE语句

时间:2014-07-14 07:47:46

标签: sql oracle stored-procedures

我正在尝试编写一个我在where子句中使用CASE的过程。不确定这里有什么不对,但下面的代码不起作用。

它只是说错误:检查编译器日志..我甚至无法检查错误消息。你能帮忙解决一下这里错了吗?

create or replace 
PACKAGE BODY PACKAGE1_PKG AS
PROCEDURE get_row(
    p_project           IN OUT VARCHAR2,
    p_version           IN OUT VARCHAR2,
    p_logical_name      IN OUT VARCHAR2,
    p_operation_name    IN OUT VARCHAR2,
    p_obsolete_flg      IN OUT CHAR,
    p_default_operation IN OUT CHAR,
    p_crt_dt            IN OUT DATE,
    p_crt_userid        IN OUT VARCHAR2) IS

BEGIN
errbuf  := NULL;
retcode := '0';

BEGIN <<lookup_row>>
  SELECT 
     project
    ,version
    ,logical_name
    ,operation_name
    ,obsolete_flg
    ,default_operation
    ,crt_dt
    ,crt_userid
  INTO 
     p_project
    ,p_version
    ,p_logical_name
    ,p_operation_name
    ,p_obsolete_flg
    ,p_default_operation
    ,p_crt_dt
    ,p_crt_userid
  FROM  TABLEA
  WHERE

    CASE 
            WHEN p_operation_name != 0 
            THEN operation_name = 'Y'
         ELSE 
            operation_name = p_operation_name
     END
  AND project = p_project
  AND   version = p_version
  AND   logical_name = p_logical_name;




END PACKAGE1_PKG;

1 个答案:

答案 0 :(得分:3)

您不能像这样使用CASE。你使用它的方式是这样的:

CASE 
WHEN expression 1 THEN column/value 1
....
ELSE column/value default
END

在您的情况下,您可以将代码更改为

AND 
(
 (p_c != 0 AND d = 'Y')
 OR 
 (c = 0) --p_c = 0 and c=p_c is the same as c = 0
)