0% found this document useful (0 votes)
5 views1 page

Assignment 12 SQL

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Assignment 12 SQL

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Name- Abhishek Bharat Dadhel PRN-124M1H006

DECLARE
v_roll_no NUMBER := &roll_no;
v_date_of_issue DATE;
v_date_of_return DATE;
v_days NUMBER;
v_fine_amount NUMBER := 0;
BEGIN
UPDATE Borrower
SET DateofReturn = SYSDATE,
Status = 'Returned'
WHERE Roll_no = v_roll_no
AND DateofReturn IS NULL;

COMMIT;

DBMS_OUTPUT.PUT_LINE('Book returned successfully and status updated.');

SELECT DateofIssue, DateofReturn INTO v_date_of_issue, v_date_of_return


FROM Borrower
WHERE Roll_no = v_roll_no;
IF v_date_of_return IS NOT NULL THEN
v_days := (v_date_of_return - v_date_of_issue);

IF v_days BETWEEN 5 AND 10 THEN


v_fine_amount := v_days * 5;
ELSIF v_days > 10 THEN
v_fine_amount := v_days * 20;
ELSE
v_fine_amount := 0;
END IF;

INSERT INTO Fine (Roll_no, Date, Amt)


VALUES (v_roll_no, SYSDATE, v_fine_amount);

COMMIT;

DBMS_OUTPUT.PUT_LINE('Total Fine for Roll No ' || v_roll_no || ' is: Rs '


|| v_fine_amount);
ELSE
DBMS_OUTPUT.PUT_LINE('No return date found for this book.');
END IF;

EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No record found for the given Roll Number.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);
END;
/

You might also like