Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
/*
DBMS Exp No.4 :- Unnamed PL/SQLcode block
Borrow(Roll_no, Name, DateofIssue, NameofBook, Status) Fine(Roll_no,Date,Amt) Problem Statement :- Accept roll_no & name of book from user. Check the number of days (from date of issue), if days are between 15 to 30 then fine amount will be Rs 5 per day. If no. of days>30, per day fine will be Rs 50 per day & for days less than 30, Rs. 5 per day. After submitting the book, status will change from I to R. If condition of fine is true, then details will be stored into fine table. Also handles the exception by named exception handler or user define exception. */
-> begin -> declare i_date date; -> declare diff int; -> declare fine_amt int; -> DECLARE EXIT HANDLER FOR SQL EXCEPTION SELECT "Table not found"; -> select Date_of_issue into i_date from Borrower where roll_no=roll and Name=nm; -> select DATEDIFF(CURDATE(),i_date)into diff; -> if(diff>=15 and diff<=30) -> then -> set fine_amt=diff*5; -> insert into Fine values(roll,CURDATE(),fine_amt); -> elseif(diff>30) -> then -> set fine_amt=diff*50; -> insert into Fine values(roll,CURDATE(),fine_amt); -> end if; -> update Borrower set Status="Return" where roll_no=roll and Name=nm; -> end $$