PL / SQL错误:PLS-00103:遇到符号" EXCEPTION"

时间:2015-05-26 19:46:52

标签: oracle plsql database-administration error-handling

我正在制作PL / SQL错误处理模板。我收到此错误:' PLS-00103:遇到符号" EXCEPTION"'我无法弄清楚错误是什么。我们正在使用Oracle数据库。

DECLARE
err_num VARCHAR(100); -- We're not gonna do math on this so I made it a string.
err_msg VARCHAR2(100);
program  VARCHAR2(100);
statement VARCHAR2(100);
BEGIN
program := 'assign the program here';
statment := 'assign the statement here';
END;


EXCEPTION


WHEN ACCESS_INTO_NULL
THEN
err_num := SQLCODE;
err_msg := SQLERRM(SQLCODE);
comment := "assign a comment here";
INSERT INTO ERRORS VALUES (err_num, err_msg, program, statement, comment, CURRENT_TIMESTAMP);

WHEN CASE_NOT_FOUND
THEN
err_num := SQLCODE;
err_msg := SQLERRM(SQLCODE);
comment := "assign a comment here";
INSERT INTO ERRORS VALUES (err_num, err_msg, program, statement, comment, CURRENT_TIMESTAMP);

...

WHEN OTHERS
THEN
err_num := -9999;
err_msg := 'undefined error occurred';
comment := "assign a comment here";
INSERT INTO ERRORS VALUES (err_num, err_msg, program, statement, comment, CURRENT_TIMESTAMP);


END;

错误表是:

CREATE TABLE ERRORS 
(
  ERR_NUM VARCHAR2(100 BYTE) NOT NULL 
, ERR_MSG VARCHAR2(100 BYTE) NOT NULL 
, PROGRAM VARCHAR2(100 BYTE) 
, STATEMENT VARCHAR2(100 BYTE) 
, USER_COMMENT VARCHAR2(100 BYTE) 
, TIMESTAMP DATE NOT NULL 
) 
LOGGING 
TABLESPACE DATAL03 
PCTFREE 10 
INITRANS 1 
STORAGE 
( 
  INITIAL 65536 
  MINEXTENTS 1 
  MAXEXTENTS UNLIMITED 
  BUFFER_POOL DEFAULT 
) 
NOCOMPRESS 
NOPARALLEL;

1 个答案:

答案 0 :(得分:0)

正如其他人在评论中所建议的那样,您需要做的就是删除第一个END,如下所示:

DECLARE
err_num VARCHAR(100); -- We're not gonna do math on this so I made it a string.
err_msg VARCHAR2(100);
program  VARCHAR2(100);
statement VARCHAR2(100);
BEGIN
program := 'assign the program here';
statment := 'assign the statement here';



EXCEPTION


WHEN ACCESS_INTO_NULL
THEN
err_num := SQLCODE;
err_msg := SQLERRM(SQLCODE);
comment := "assign a comment here";
INSERT INTO ERRORS VALUES (err_num, err_msg, program, statement, comment,  CURRENT_TIMESTAMP);

WHEN CASE_NOT_FOUND
THEN
err_num := SQLCODE;
err_msg := SQLERRM(SQLCODE);
comment := "assign a comment here";
INSERT INTO ERRORS VALUES (err_num, err_msg, program, statement, comment, CURRENT_TIMESTAMP);

...

WHEN OTHERS
THEN
err_num := -9999;
err_msg := 'undefined error occurred';
comment := "assign a comment here";
INSERT INTO ERRORS VALUES (err_num, err_msg, program, statement, comment, CURRENT_TIMESTAMP);


END;

异常部分应该是PL / SQL块的一部分,而不是单独的部分。也就是说,它应该包含在BEGIN& PL / SQL块的END语句

Reference