Oracle SP 未编译
我在 MS SQL 方面有经验,但是在 Oracle 上上课,我一生都无法弄清楚为什么这个存储过程的脚本不起作用。我在第一个异常变量的变量声明部分中遇到错误。这是错误消息:
PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:
in out <an identifier> <a double-quoted delimited-identifier> LONG_ double ref char
time timestamp interval date binary national character nchar
编码
CREATE or REPLACE Procedure Movie_Rental_SP
(
Mv_ID IN Number,
Mem_ID IN Number,
Pay_ID IN Number,
Mv_Chk Number,
Mem_Chk Number,
Pay_Chk Number,
Qty_Chk Number,
--> next line is where the error points
UnKnown_Mv Exception,
UnKnown_Mem Exception,
UnKnown_Pay Exception,
UnAvail_Mv Exception )
IS
BEGIN
SELECT COUNT(Movie_ID) INTO Mv_Chk FROM MM_Movie WHERE Movie_ID = Mv_ID;
SELECT COUNT(Member_ID) INTO Mem_Chk FROM MM_Member WHERE Member_ID = Mem_ID;
SELECT COUNT(Payment_Methods_ID) INTO Pay_Chk FROM MM_Pay_Type WHERE Payment_Methods_ID = Pay_ID;
SELECT Movie_Qty INTO Qty_Chk FROM MM_Movie WHERE Movie_ID = Mv_ID;
IF Mv_Chk = 0 THEN RAISE UnKnown_Mv;
ELSE IF Mem_Chk = 0 THEN RAISE UnKnown_Mem;
ELSE IF Pay_Chk = 0 THEN RAISE UnKnown_Pay;
ELSE Qty_Chk = 0 THEN RAISE UnAvail_Mv;
END IF;
DECLARE New_ID NUMBER;
BEGIN
SELECT Max(Rental_ID)+1 INTO New_ID FROM MM_Rental;
EXCEPTION WHEN NO_DATA_FOUND THEN
New_ID := 1;
DBMS_OUTPUT.PUT_LINE ('There are no exsisting Rental IDs, ID set to 1');
END;
INSERT INTO MM_Rental VALUES (New_ID,Mem_ID,Mv_ID,Sysdate,Null,Pay_ID);
UPDATE MM_Movie SET Movie_Qty = Movie_Qty - 1 WHERE Movie_ID = Mv_ID;
EXCEPTION
WHEN UnKnown_Mv THEN
RAISE_APPLICATION_ERROR(-20001,'There is no movie with Movie ID of: '||Mv_ID||' Transaction cancelled.');
WHEN UnKnown_Mem THEN
RAISE_APPLICATION_ERROR(-20002,'No member exists with member ID: '||Mem_ID||' Transaction cancelled.');
WHEN UnKnown_Pay THEN
RAISE_APPLICATION_ERROR(-20003,'No payment type for: '||Pay_ID||' Transaction cancelled.');
WHEN UnAvail_Mv THEN
RAISE_APPLICATION_ERROR(-20004,'No movies available for: '||Mv_ID||' Transaction cancelled.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Error number: '||sqlcode);
DBMS_OUTPUT.PUT_LINE ('Error message: '||sqlerrm);
DBMS_OUTPUT.PUT_LINE('Unanticipated error. Contact your system administrator.');
END;
/
任何帮助将不胜感激!