|
发表于 2011-10-31 13:00:58
|
显示全部楼层
Re:-存儲过程中的异常
SQL code CREATE OR REPLACE PROCEDURE LOAN_BOOK(B_ID IN NUMBER, U_ID IN NUMBER) IS
OR_ID NUMBER(6);
OR_NAME VARCHAR2(1000);
BK_ID NUMBER(12);
BK_NAME VARCHAR2(1000);
ST_DATE DATE;
ED_DATE DATE;
H1 NUMBER(6);
H2 NUMBER(6);
H3 NUMBER(6);
L VARCHAR2(10);
S VARCHAR2(20);
BEGIN
SELECT STATUS INTO S FROM BOOK WHERE BOOK_ID = B_ID;
IF S = '在庫' THEN
SELECT HOLD1, HOLD2, HOLD3, LIMITED --查询
INTO H1, H2, H3, L
FROM EACH_OWNER
WHERE OWNER_ID = U_ID;
IF L = 'N' THEN
ST_DATE := SYSDATE;
ED_DATE := ST_DATE + 15;
SELECT USER_ID, USER_NAME
INTO OR_ID, OR_NAME
FROM USERS
WHERE USER_ID = U_ID;
SELECT BOOK_ID, BOOK_NAME
INTO BK_ID, BK_NAME
FROM BOOK
WHERE BOOK_ID = B_ID;
INSERT INTO LOAN --插入
VALUES
(SQ_LOAN_ID.NEXTVAL,
OR_ID,
OR_NAME,
BK_ID,
BK_NAME,
ST_DATE,
ED_DATE);
UPDATE BOOK SET STATUS = '借出' WHERE BOOK_ID = B_ID;
COMMIT;
DBMS_OUTPUT.PUT_LINE('YOU HAVE BORROWED THE BOOK SUCCESSFULLY!');
IF H1 = 0 THEN
UPDATE EACH_OWNER SET HOLD1 = B_ID WHERE OWNER_ID = U_ID;
DBMS_OUTPUT.PUT_LINE('11111111');
ELSIF H2=0 THEN
UPDATE EACH_OWNER SET HOLD2 = B_ID WHERE OWNER_ID = U_ID;--更新
DBMS_OUTPUT.PUT_LINE('22222222');
ELSIF H3=0 THEN
UPDATE EACH_OWNER
SET HOLD3 = B_ID
WHERE OWNER_ID = U_ID;
DBMS_OUTPUT.PUT_LINE('33333');
END IF;
SELECT HOLD1,HOLD2,HOLD3
INTO H1,H2,H3 FROM EACH_OWNER
WHERE OWNER_ID=U_ID;
IF H1<>0 AND H2<>0 AND H3<>0 THEN
UPDATE EACH_OWNER
SET LIMITED='Y'
WHERE OWNER_ID=U_ID;
END IF;
COMMIT;
ELSE
DBMS_OUTPUT.PUT_LINE('YOU HAVE ALREADY OWNED 3 BOOKS!CANNOT OWN ANY MORE!');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('THE BOOK IS ALREADY OWNED BY SOMEONE.PLEASE MAKE SURE THE DETIAL!');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('YOU MAY HAVE ENTERED A WRONG USERID OR BOOKID!');
END LOAN_BOOK; |
|