0% found this document useful (0 votes)
3 views4 pages

DBMS A 4

The document outlines a PL/SQL code block that calculates fines for borrowed books based on the number of days overdue. It includes the creation of 'Borrower' and 'Fine' tables, and implements control structures and exception handling for fine calculations and status updates. The code handles user input for roll number and book name, computes the fine based on the overdue period, and updates the database accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

DBMS A 4

The document outlines a PL/SQL code block that calculates fines for borrowed books based on the number of days overdue. It includes the creation of 'Borrower' and 'Fine' tables, and implements control structures and exception handling for fine calculations and status updates. The code handles user input for roll number and book name, computes the fine based on the overdue period, and updates the database accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Group A : Assignment No.

4
Aim: Unnamed PL/SQL code block: Use of Control structure and Exception handling is ma
ndatory. Suggested Problem statement: Consider Tables: 1. Borrower(Roll_no, Name, Dateof
Issue, NameofBook, Status) 2. Fine(Roll_no,Date,Amt) • Accept Roll_no and NameofBook f
rom user. • Check the number of days (from date of issue). • If days are between 15 to 30 the
n fine amount will be Rs 5per day. • If no. of days>30, per day fine will be Rs 50 per day and
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 e
xception by named exception handler or user define exception handler.

Code:
Borrow Table :

create table Borrower(Roll_no int, Name varchar(50), Date_of_Issue date, Name_of_Book


varchar(70), Status varchar(50));

insert into Borrower values(101,'Samira', '04-12-2010' ,'DSA', 'Return');

insert into Borrower values(102,'Atharv', '07-09-2019' ,'DBMS', 'Issued');

insert into Borrower values(103,'Gauri', '04-12-2021' ,'TOC', 'Issued');

insert into Borrower values(104,'Aakash', '08-11-2021' ,'C++', 'Issued');

insert into Borrower values(105,'Palak', '04-12-2022' ,'SPM', 'Return');

insert into Borrower values(106,'Aakansha', '10-09-2022' ,'Python', 'Issued');

alter table Borrower add PRIMARY KEY(Roll_no);

select * from Borrower;

desc Borrower;

Fine Table:

create table Fine(Roll_no int,Date_of_fine date,Amount int);

alter table Fine add PRIMARY KEY(Roll_no);


declare

rollno number(20);

name varchar(50);

amt int;

doi date;

System_date date;

no_of_days number(20);

begin

rollno:=:rollno;

name:=:name;

select Sysdate into System_date from dual;

select Date_of_Issue into doi from Borrower where Roll_no=rollno and


Name_of_Book=name;

dbms_Output.put_line(doi);

no_of_days:=System_date - doi;

dbms_Output.put_line(no_of_days);

if(no_of_days>15 and no_of_days<30) then

amt:=no_of_days*5;

dbms_Output.put_line('amount'||amt);

elsif no_of_days>30 then

amt:=no_of_days*50;

dbms_Output.put_line('amount'||amt);

else

dbms_Output.put_line('No fine');

end if;
if no_of_days>15 then

insert into Fine values(rollno,Sysdate ,amt);

update Borrower set Status='Return' where Roll_no=rollno;

end if;

exception

when no_data_found then

dbms_Output.put_line(rollno || 'Not found');

end;

Output:

ROLL_NO NAME DATE_OF_ISSUE NAME_OF_BOOK STATUS

101 Samira 04/12/2010 DSA Return

102 Atharv 07/09/2019 DBMS Issued

103 Gauri 04/12/2021 TOC Issued

104 Aakash08/11/2021 C++ Issued

105 Palak 04/12/2022 SPM Return

106 Aakansha 10/09/2022 Python Issued

04/12/2010

4539

amount226950

ROLL_NO DATE_OF_FINE AMOUNT

101 09/15/2022 226950


1 row(s) updated.

You might also like