嵌套IF语句的PL / SQL错误

时间:2013-08-23 18:10:50

标签: plsql oracle-apex

Apex 4.2

我在下面有以下pl / sql代码块,但无论何时我在APex中运行它,我都会收到错误:

ORA-06550:第35行,第4栏:PLS-00103:遇到符号“;”期待以下之一:if

DECLARE
   show_changes BOOLEAN;
   l_exists INTEGER;

BEGIN

Select count(*) into l_exists
From dba_role_privs
where grantee = upper(:APP_USER) and
(granted_role = 'SURVEY_JOB_SUID' or granted_role = 'SURVEY_SUID');

IF l_exists = 0 THEN            /* unauthorized */
   IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL  AND (:P32_SUBMISSION_DATE IS NULL     AND :P32_LOCK_DATE IS NULL) THEN   
           show_changes := TRUE;
   IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL AND (:P32_SUBMISSION_DATE IS NOT NULL AND :P32_LOCK_DATE IS NULL) THEN
      show_changes := TRUE;
   IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL AND (:P32_SUBMISSION_DATE IS NOT NULL     AND :P32_LOCK_DATE IS NOT NULL) THEN
          show_changes := FALSE;    
END IF;
ELSE                          /* authorized */  
   IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL  AND (:P32_SUBMISSION_DATE IS NULL AND :P32_LOCK_DATE IS NULL) THEN   
           show_changes := TRUE;
   IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL AND (:P32_SUBMISSION_DATE IS NOT NULL AND :P32_LOCK_DATE IS NULL) THEN
      show_changes := TRUE;
   IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL AND (:P32_SUBMISSION_DATE IS NOT NULL AND :P32_LOCK_DATE IS NOT NULL) THEN
      show_changes := TRUE;

END IF;
Return show_changes;
END;

我不确定问题是什么。任何帮助将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:3)

IF始终必须与END IF配对,ELSE位于END IF之前。如果您希望在外部IF的两个分支中的每个分支中都有三个单独的IF语句,则需要类似

的内容
IF l_exists = 0
THEN
  IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL  AND 
    (:P32_SUBMISSION_DATE IS NULL     AND :P32_LOCK_DATE IS NULL) 
  THEN   
           show_changes := TRUE;
  END IF;
  IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL AND 
     (:P32_SUBMISSION_DATE IS NOT NULL AND :P32_LOCK_DATE IS NULL) 
  THEN
      show_changes := TRUE;
  END IF;
  IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL AND 
     (:P32_SUBMISSION_DATE IS NOT NULL     AND :P32_LOCK_DATE IS NOT NULL) 
  THEN
          show_changes := FALSE;    
  END IF;
ELSE
  <<repeat the pattern>>
END IF;

但我的猜测是,你真的不希望在每个分支中有三个单独的IF语句。我猜你想要一个IF

ELSIF语句
IF l_exists = 0
THEN
  IF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL AND 
    (:P32_SUBMISSION_DATE IS NULL     AND :P32_LOCK_DATE IS NULL) 
  THEN   
           show_changes := TRUE;
  ELSIF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL AND 
       (:P32_SUBMISSION_DATE IS NOT NULL AND :P32_LOCK_DATE IS NULL) 
  THEN
      show_changes := TRUE;
  ELSIF :P32_SURVEY_JOB_REQUEST_ID IS NOT NULL AND 
       (:P32_SUBMISSION_DATE IS NOT NULL     AND :P32_LOCK_DATE IS NOT NULL) 
  THEN
          show_changes := FALSE;    
  END IF;
ELSE
  <<repeat the pattern>>
END IF;