遇到以下符号之一时遇到符号 "EXCEPTION":,

Encountered the symbol "EXCEPTION" when expecting one of the following: ,

1.This 是一个包,用于从用户那里获取一些详细信息并将其存储在数据库中,但是我在创建验证时遇到了几个错误(异常部分)

create or replace PACKAGE  MOVIE_PKG
AS
PROCEDURE ADDCONSUMERDETAILS(c_con_ID consumer_info.con_id%type,c_con_name consumer_info.con_name%type,
c_con_email consumer_info.con_email%type,c_con_co consumer_info.con_co%type,c_con_ct consumer_info.con_ct%type);
END MOVIE_PKG;

create or replace PACKAGE BODY MOVIE_PKG
AS
--ADD/INSERT CONSUMER INFORMATION--take input for cust id 
PROCEDURE ADDCONSUMERDETAILS(c_con_id consumer_info.con_id%type,c_con_name consumer_info.con_name%type,
c_con_email consumer_info.con_email%type,c_con_co consumer_info.con_co%type,c_con_ct consumer_info.con_ct%type)
AS
EXC_CON_ID EXCEPTION;
EXC_CON_NAME EXCEPTION;
EXC_CON_CO EXCEPTION;
BEGIN
--CONSUMER ID VALIDATION
IF LENGTH(EXC_CON_ID)=0 THEN
RAISE EXC_CON_ID;
ELSE IF LENGTH(EXC_CON_ID)<4 THEN
RAISE EXC_CON_NAME;
ELSE IF LENGTH(EXC_CON_CO)!=10 THEN
RAISE EXC_CON_CO;
ELSE
INSERT INTO CONSUMER_INFO VALUES(C_CON_ID,C_CON_NAME,C_CON_EMAIL,C_CON_CO,C_CON_CT);
  DBMS_OUTPUT.PUT_LINE('Data Added Successfully');
END IF;

EXCEPTION
WHEN EXC_CON_ID THEN
   DBMS_OUTPUT.PUT_LINE('INVALID CONSUMER ID, CHECK CONSUMER ID:ENTER CORRECT ID');
WHEN EXC_CON_NAME THEN
   DBMS_OUTPUT.PUT_LINE('INVALID CONSUMER NAME, ENTER CORRECT CONSUMER NAME');
WHEN EXC_CON_CO THEN
   DBMS_OUTPUT.PUT_LINE('INVALID CONSUMER NUMBER');
END ADDCONSUMERDETAILS;

END MOVIE_PKG;

--消费者table

的插入警报触发器
create or replace TRIGGER consumer_insert_chk
AFTER
INSERT
ON CONSUMER_INFO
FOR EACH ROW
BEGIN
DBMS_OUTPUT.PUT_LINE('A ROW IS INSERTED TO CONSUMER TABLE');
--End of trigger
END consumer_insert_chk;

--客户端块

SET SERVEROUTPUT ON;
DECLARE
  C_CON_ID consumer_info.con_id%type:='&IDENTIFICATIONNUMBER';
  C_CON_NAME  CONSUMER_INFO.CON_NAME%TYPE:='&NAME';
  C_CON_EMAIL CONSUMER_INFO.CON_EMAIL%TYPE:='&EMAIL';
  C_CON_CO CONSUMER_INFO.CON_CO%TYPE:=&CONTACTNO;
  C_CON_CT CONSUMER_INFO.CON_CT%TYPE:='&CITY';
BEGIN
MOVIE_PKG.ADDCONSUMERDETAILS(C_CON_ID,c_con_name,c_con_email,c_con_co,c_con_ct);
END;
/
  1. 这是我遇到的错误

    LINE/COL错误


    23/1 PLS-00103:在预期以下情况之一时遇到符号“EXCEPTION”:( begin case declare end exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set SQL 对所有合并管道清除执行提交 32/5 PLS-00103:遇到以下符号之一时遇到符号“MOVIE_PKG”: 错误:检查编译器日志

您在 EXCEPTION 关键字之前缺少两个 END IF

BEGIN
   --CONSUMER ID VALIDATION
   IF LENGTH (EXC_CON_ID) = 0
   THEN
      RAISE EXC_CON_ID;
   ELSE
      IF LENGTH (EXC_CON_ID) < 4
      THEN
         RAISE EXC_CON_NAME;
      ELSE
         IF LENGTH (EXC_CON_CO) != 10
         THEN
            RAISE EXC_CON_CO;
         ELSE
            INSERT INTO CONSUMER_INFO
                 VALUES (C_CON_ID,
                         C_CON_NAME,
                         C_CON_EMAIL,
                         C_CON_CO,
                         C_CON_CT);

            DBMS_OUTPUT.PUT_LINE ('Data Added Successfully');
         END IF;
      END IF;              --> this
   END IF;                 --> this
EXCEPTION
   WHEN EXC_CON_ID
   THEN
      DBMS_OUTPUT.PUT_LINE (
         'INVALID CONSUMER ID, CHECK CONSUMER ID:ENTER CORRECT ID');
   WHEN EXC_CON_NAME
   THEN
      DBMS_OUTPUT.PUT_LINE (
         'INVALID CONSUMER NAME, ENTER CORRECT CONSUMER NAME');
   WHEN EXC_CON_CO
   THEN
      DBMS_OUTPUT.PUT_LINE ('INVALID CONSUMER NUMBER');
END ADDCONSUMERDETAILS;

信不信由你,但如果您注意格式化,实际上会有很大帮助。缩进创造奇迹,让您轻松找出罪魁祸首。未格式化的代码是一团糟所以......难怪你有问题。我建议你要么使用 GUI 的格式化程序,要么 - 如果你在 SQL*Plus - 手动格式化它。

ELSE IF 语句的正确语法是 ELSIF (link)。另外我不明白为什么你总是检查异常的长度。

create or replace PACKAGE  MOVIE_PKG
AS
PROCEDURE ADDCONSUMERDETAILS(c_con_ID consumer_info.con_id%type,
                             c_con_name consumer_info.con_name%type,
                             c_con_email consumer_info.con_email%type,
                             c_con_co consumer_info.con_co%type,
                             c_con_ct consumer_info.con_ct%type
                            );
END MOVIE_PKG;
/

create or replace PACKAGE BODY MOVIE_PKG
AS
--ADD/INSERT CONSUMER INFORMATION--take input for cust id 

PROCEDURE ADDCONSUMERDETAILS(c_con_ID consumer_info.con_id%type,
                             c_con_name consumer_info.con_name%type,
                             c_con_email consumer_info.con_email%type,
                             c_con_co consumer_info.con_co%type,
                             c_con_ct consumer_info.con_ct%type
                            );
AS
  EXC_CON_ID EXCEPTION;
  EXC_CON_NAME EXCEPTION;
  EXC_CON_CO EXCEPTION;
BEGIN
  --CONSUMER ID VALIDATION
  IF LENGTH(C_CON_ID) = 0 THEN
    RAISE EXC_CON_ID;

  ELSIF LENGTH(C_CON_NAME) < 4 THEN
    RAISE EXC_CON_NAME;

  ELSIF LENGTH(C_CON_CO) != 10 THEN
    RAISE EXC_CON_CO;

  ELSE
    INSERT INTO CONSUMER_INFO 
           VALUES(C_CON_ID,
                  C_CON_NAME,
                  C_CON_EMAIL,
                  C_CON_CO,
                  C_CON_CT);
    DBMS_OUTPUT.PUT_LINE('Data Added Successfully');
  END IF;

EXCEPTION
  WHEN EXC_CON_ID THEN
    DBMS_OUTPUT.PUT_LINE('INVALID CONSUMER ID, CHECK CONSUMER ID:ENTER CORRECT ID');
  WHEN EXC_CON_NAME THEN
    DBMS_OUTPUT.PUT_LINE('INVALID CONSUMER NAME, ENTER CORRECT CONSUMER NAME');
  WHEN EXC_CON_CO THEN
    DBMS_OUTPUT.PUT_LINE('INVALID CONSUMER NUMBER');

END ADDCONSUMERDETAILS;

END MOVIE_PKG;
/