SlideShare a Scribd company logo
2
Most read
Practical No: 5
Problem Statement: Unnamed PL/SQL code block: Use of Control structure and
Exception handling is mandatory.
Write a PL/SQL block of code for the following requirements:-
Schema:
1. Borrower(Rollin, Name, DateofIssue, NameofBook, Status)
2. Fine(Roll_no,Date,Amt)
- 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 5per 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.
Frame the problem statement for writing PL/SQL block inline with above
statement.
Database changed
mysql> show tables;
+-----------------+
| Tables_in_prac5 |
+-----------------+
| Borrower |
| Fine |
+-----------------+
2 rows in set (0.00 sec)
mysql> desc Borrower;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| Rollin | int(12) | NO | PRI | NULL | |
| Name | varchar(25) | YES | | NULL | |
| DateOfIsssue | date | YES | | NULL | |
| Nameofbook | varchar(25) | YES | | NULL | |
| Status | varchar(3) | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> desc Fine;
+--------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------+------+-----+---------+-------+
| Rollno | int(12) | NO | PRI | NULL | |
| Date | date | YES | | NULL | |
| Amt | int(12) | YES | | NULL | |
+--------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> select * From Borrower;
+--------+--------+--------------+------------+--------+
| Rollin | Name | DateOfIsssue | Nameofbook | Status |
+--------+--------+--------------+------------+--------+
| 1 | Rahul | 2019-07-13 | dbms | I |
| 2 | Rakesh | 2019-07-28 | sql | I |
| 33 | Aadil | 2019-05-13 | toc | I |
| 85 | Akbar | 2019-06-20 | java | I |
+--------+--------+--------------+------------+--------+
4 rows in set (0.00 sec)
mysql> select * From Fine;
Empty set (0.00 sec)
dilimiter $
mysql> create procedure calfine(Rollno int(20),name varchar(50))
begin
declare ldate date;
declare fine int(20);
declare day int(20);
select DateOfIsssue into ldate from Borrower where Rollin=Rollno and
Nameofbook=name;
set day = DATEDIFF(CURDATE(),ldate);
IF(day>=15 and day<=30) then
set fine=day*5;
ELSEIF(day>30) then
set fine=day*50;
end IF;
update Borrower set Status='R' where Rollin=Rollno and Nameofbook=name;
IF(fine is not null) then
insert into Fine values(Rollno,CURDATE(),fine);
end IF;
end $
mysql> call calfine(33,'toc')$
Query OK, 1 row affected (0.03 sec)
mysql> select * from Fine$
+--------+------------+------+
| Rollno | Date | Amt |
+--------+------------+------+
| 33 | 2019-08-07 | 4300 |
+--------+------------+------+
1 row in set (0.00 sec)
mysql> call calfine(2,'sql')$
Query OK, 1 row affected (0.36 sec)
mysql> call calfine(1,'dbms')$
Query OK, 1 row affected (0.34 sec)
mysql> select * from Borrower$
+--------+--------+--------------+------------+--------+
| Rollin | Name | DateOfIsssue | Nameofbook | Status |
+--------+--------+--------------+------------+--------+
| 1 | Rahul | 2019-07-13 | dbms | R |
| 2 | Rakesh | 2019-07-28 | sql | R |
| 33 | Aadil | 2019-05-13 | toc | R |
| 85 | Akbar | 2019-06-20 | java | I |
+--------+--------+--------------+------------+--------+
4 rows in set (0.00 sec)
mysql> select * from Fine$
+--------+------------+------+
| Rollno | Date | Amt |
+--------+------------+------+
| 1 | 2019-08-07 | 125 |
| 33 | 2019-08-07 | 4300 |
+--------+------------+------+
2 rows in set (0.00 sec)
Ad

Recommended

Detection of phishing websites
Detection of phishing websites
m srikanth
 
PPT Discoloration of Taj Mahal
PPT Discoloration of Taj Mahal
MalaikaNoorani
 
Urban Heat Island Effect
Urban Heat Island Effect
GAURAV. H .TANDON
 
Environmental Pollution
Environmental Pollution
Uday Kumar Shil
 
Urban heat island
Urban heat island
Khalid Mehmood
 
Taj Mahal - The corroding beauty
Taj Mahal - The corroding beauty
Noel Tom
 
Diabetes Mellitus
Diabetes Mellitus
MD Abdul Haleem
 
Power Point Presentation on Artificial Intelligence
Power Point Presentation on Artificial Intelligence
Anushka Ghosh
 
database application using SQL DML statements: all types of Join, Sub-Query ...
database application using SQL DML statements: all types of Join, Sub-Query ...
bhavesh lande
 
Character generation techniques
Character generation techniques
Mani Kanth
 
object oriented methodologies
object oriented methodologies
Amith Tiwari
 
Web servers for the Internet of Things
Web servers for the Internet of Things
Alexandru Radovici
 
evaluation techniques in HCI
evaluation techniques in HCI
sawsan slii
 
Database security
Database security
Software Engineering
 
Cs8493 unit 5
Cs8493 unit 5
Kathirvel Ayyaswamy
 
Requirements elicitation
Requirements elicitation
Syed Zaid Irshad
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
DHIVYADEVAKI
 
Unit 4 designing classes
Unit 4 designing classes
gopal10scs185
 
Library Management System in c++
Library Management System in c++
vikram mahendra
 
Requirement modeling
Requirement modeling
Abdul Basit
 
Chapter 5 IoT Design methodologies
Chapter 5 IoT Design methodologies
pavan penugonda
 
Dda algorithm
Dda algorithm
Mani Kanth
 
Unit 5 testing -software quality assurance
Unit 5 testing -software quality assurance
gopal10scs185
 
Library Management System
Library Management System
ĞĔŃÚĨŃĔ ĞĔŃĨÚŚ
 
Cocomo model
Cocomo model
Baskarkncet
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
Omprakash Chauhan
 
UNIT-IV
UNIT-IV
VarthiniRamesh
 
Raster scan system
Raster scan system
Mohd Arif
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
Richard Crowley
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
MYXPLAIN
 

More Related Content

What's hot (20)

database application using SQL DML statements: all types of Join, Sub-Query ...
database application using SQL DML statements: all types of Join, Sub-Query ...
bhavesh lande
 
Character generation techniques
Character generation techniques
Mani Kanth
 
object oriented methodologies
object oriented methodologies
Amith Tiwari
 
Web servers for the Internet of Things
Web servers for the Internet of Things
Alexandru Radovici
 
evaluation techniques in HCI
evaluation techniques in HCI
sawsan slii
 
Database security
Database security
Software Engineering
 
Cs8493 unit 5
Cs8493 unit 5
Kathirvel Ayyaswamy
 
Requirements elicitation
Requirements elicitation
Syed Zaid Irshad
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
DHIVYADEVAKI
 
Unit 4 designing classes
Unit 4 designing classes
gopal10scs185
 
Library Management System in c++
Library Management System in c++
vikram mahendra
 
Requirement modeling
Requirement modeling
Abdul Basit
 
Chapter 5 IoT Design methodologies
Chapter 5 IoT Design methodologies
pavan penugonda
 
Dda algorithm
Dda algorithm
Mani Kanth
 
Unit 5 testing -software quality assurance
Unit 5 testing -software quality assurance
gopal10scs185
 
Library Management System
Library Management System
ĞĔŃÚĨŃĔ ĞĔŃĨÚŚ
 
Cocomo model
Cocomo model
Baskarkncet
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
Omprakash Chauhan
 
UNIT-IV
UNIT-IV
VarthiniRamesh
 
Raster scan system
Raster scan system
Mohd Arif
 
database application using SQL DML statements: all types of Join, Sub-Query ...
database application using SQL DML statements: all types of Join, Sub-Query ...
bhavesh lande
 
Character generation techniques
Character generation techniques
Mani Kanth
 
object oriented methodologies
object oriented methodologies
Amith Tiwari
 
Web servers for the Internet of Things
Web servers for the Internet of Things
Alexandru Radovici
 
evaluation techniques in HCI
evaluation techniques in HCI
sawsan slii
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
DHIVYADEVAKI
 
Unit 4 designing classes
Unit 4 designing classes
gopal10scs185
 
Library Management System in c++
Library Management System in c++
vikram mahendra
 
Requirement modeling
Requirement modeling
Abdul Basit
 
Chapter 5 IoT Design methodologies
Chapter 5 IoT Design methodologies
pavan penugonda
 
Unit 5 testing -software quality assurance
Unit 5 testing -software quality assurance
gopal10scs185
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
Omprakash Chauhan
 
Raster scan system
Raster scan system
Mohd Arif
 

Similar to Unnamed PL/SQL code block: Use of Control structure and Exception handling is mandatory. Write a PL/SQL block of code for the following requirements (20)

Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
Richard Crowley
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
MYXPLAIN
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
MYXPLAIN
 
Common schema my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Common schema my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Advance MySQL Training by Pratyush Majumdar
Advance MySQL Training by Pratyush Majumdar
Pratyush Majumdar
 
Building advanced data-driven applications
Building advanced data-driven applications
MariaDB plc
 
Window functions in MySQL 8.0
Window functions in MySQL 8.0
Mydbops
 
Writing efficient sql
Writing efficient sql
j9soto
 
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
teachersduniya.com
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
Explain
Explain
Ligaya Turmelle
 
Introduction To Lamp P2
Introduction To Lamp P2
Amzad Hossain
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
NeoClova
 
Date data type and Globalization in Oracle
Date data type and Globalization in Oracle
Masoud Haji Hassan Pour
 
Percona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuning
Sergey Petrunya
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt
KISHOYIANKISH
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQL
Mydbops
 
MySQL SQL Tutorial
MySQL SQL Tutorial
Chien Chung Shen
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
Valeriy Kravchuk
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
Richard Crowley
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
MYXPLAIN
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
MYXPLAIN
 
Common schema my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Common schema my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Advance MySQL Training by Pratyush Majumdar
Advance MySQL Training by Pratyush Majumdar
Pratyush Majumdar
 
Building advanced data-driven applications
Building advanced data-driven applications
MariaDB plc
 
Window functions in MySQL 8.0
Window functions in MySQL 8.0
Mydbops
 
Writing efficient sql
Writing efficient sql
j9soto
 
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
teachersduniya.com
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
Introduction To Lamp P2
Introduction To Lamp P2
Amzad Hossain
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
NeoClova
 
Date data type and Globalization in Oracle
Date data type and Globalization in Oracle
Masoud Haji Hassan Pour
 
Percona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuning
Sergey Petrunya
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt
KISHOYIANKISH
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQL
Mydbops
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
Valeriy Kravchuk
 
Ad

More from bhavesh lande (20)

The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019
bhavesh lande
 
information control and Security system
information control and Security system
bhavesh lande
 
information technology and infrastructures choices
information technology and infrastructures choices
bhavesh lande
 
ethical issues,social issues
ethical issues,social issues
bhavesh lande
 
managing inforamation system
managing inforamation system
bhavesh lande
 
• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance
bhavesh lande
 
IT and innovations
IT and innovations
bhavesh lande
 
organisations and information systems
organisations and information systems
bhavesh lande
 
IT stratergy and digital goods
IT stratergy and digital goods
bhavesh lande
 
Implement Mapreduce with suitable example using MongoDB.
Implement Mapreduce with suitable example using MongoDB.
bhavesh lande
 
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.
bhavesh lande
 
database application using SQL DML statements: Insert, Select, Update, Delet...
database application using SQL DML statements: Insert, Select, Update, Delet...
bhavesh lande
 
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
bhavesh lande
 
working with python
working with python
bhavesh lande
 
applications and advantages of python
applications and advantages of python
bhavesh lande
 
introduction of python in data science
introduction of python in data science
bhavesh lande
 
tools
tools
bhavesh lande
 
data scientists and their role
data scientists and their role
bhavesh lande
 
applications
applications
bhavesh lande
 
statistics techniques to deal with data
statistics techniques to deal with data
bhavesh lande
 
The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019
bhavesh lande
 
information control and Security system
information control and Security system
bhavesh lande
 
information technology and infrastructures choices
information technology and infrastructures choices
bhavesh lande
 
ethical issues,social issues
ethical issues,social issues
bhavesh lande
 
managing inforamation system
managing inforamation system
bhavesh lande
 
• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance
bhavesh lande
 
organisations and information systems
organisations and information systems
bhavesh lande
 
IT stratergy and digital goods
IT stratergy and digital goods
bhavesh lande
 
Implement Mapreduce with suitable example using MongoDB.
Implement Mapreduce with suitable example using MongoDB.
bhavesh lande
 
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.
bhavesh lande
 
database application using SQL DML statements: Insert, Select, Update, Delet...
database application using SQL DML statements: Insert, Select, Update, Delet...
bhavesh lande
 
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
bhavesh lande
 
applications and advantages of python
applications and advantages of python
bhavesh lande
 
introduction of python in data science
introduction of python in data science
bhavesh lande
 
data scientists and their role
data scientists and their role
bhavesh lande
 
statistics techniques to deal with data
statistics techniques to deal with data
bhavesh lande
 
Ad

Recently uploaded (20)

Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
 
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Mark Billinghurst
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
Cadastral Maps
Cadastral Maps
Google
 
Solar thermal – Flat plate and concentrating collectors .pptx
Solar thermal – Flat plate and concentrating collectors .pptx
jdaniabraham1
 
How to Un-Obsolete Your Legacy Keypad Design
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
Complete guidance book of Asp.Net Web API
Complete guidance book of Asp.Net Web API
Shabista Imam
 
Unit III_One Dimensional Consolidation theory
Unit III_One Dimensional Consolidation theory
saravananr808639
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Introduction to sensing and Week-1.pptx
Introduction to sensing and Week-1.pptx
KNaveenKumarECE
 
20CE404-Soil Mechanics - Slide Share PPT
20CE404-Soil Mechanics - Slide Share PPT
saravananr808639
 
Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
 
Microwatt: Open Tiny Core, Big Possibilities
Microwatt: Open Tiny Core, Big Possibilities
IBM
 
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
resming1
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
 
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Mark Billinghurst
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
Cadastral Maps
Cadastral Maps
Google
 
Solar thermal – Flat plate and concentrating collectors .pptx
Solar thermal – Flat plate and concentrating collectors .pptx
jdaniabraham1
 
Complete guidance book of Asp.Net Web API
Complete guidance book of Asp.Net Web API
Shabista Imam
 
Unit III_One Dimensional Consolidation theory
Unit III_One Dimensional Consolidation theory
saravananr808639
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Introduction to sensing and Week-1.pptx
Introduction to sensing and Week-1.pptx
KNaveenKumarECE
 
20CE404-Soil Mechanics - Slide Share PPT
20CE404-Soil Mechanics - Slide Share PPT
saravananr808639
 
Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
 
Microwatt: Open Tiny Core, Big Possibilities
Microwatt: Open Tiny Core, Big Possibilities
IBM
 
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
resming1
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 

Unnamed PL/SQL code block: Use of Control structure and Exception handling is mandatory. Write a PL/SQL block of code for the following requirements

  • 1. Practical No: 5 Problem Statement: Unnamed PL/SQL code block: Use of Control structure and Exception handling is mandatory. Write a PL/SQL block of code for the following requirements:- Schema: 1. Borrower(Rollin, Name, DateofIssue, NameofBook, Status) 2. Fine(Roll_no,Date,Amt) - 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 5per 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. Frame the problem statement for writing PL/SQL block inline with above statement. Database changed mysql> show tables; +-----------------+ | Tables_in_prac5 | +-----------------+ | Borrower | | Fine | +-----------------+ 2 rows in set (0.00 sec) mysql> desc Borrower; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | Rollin | int(12) | NO | PRI | NULL | | | Name | varchar(25) | YES | | NULL | | | DateOfIsssue | date | YES | | NULL | | | Nameofbook | varchar(25) | YES | | NULL | | | Status | varchar(3) | YES | | NULL | | +--------------+-------------+------+-----+---------+-------+ 5 rows in set (0.00 sec) mysql> desc Fine; +--------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+---------+------+-----+---------+-------+ | Rollno | int(12) | NO | PRI | NULL | | | Date | date | YES | | NULL | | | Amt | int(12) | YES | | NULL | | +--------+---------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> select * From Borrower; +--------+--------+--------------+------------+--------+ | Rollin | Name | DateOfIsssue | Nameofbook | Status | +--------+--------+--------------+------------+--------+ | 1 | Rahul | 2019-07-13 | dbms | I | | 2 | Rakesh | 2019-07-28 | sql | I | | 33 | Aadil | 2019-05-13 | toc | I | | 85 | Akbar | 2019-06-20 | java | I | +--------+--------+--------------+------------+--------+ 4 rows in set (0.00 sec) mysql> select * From Fine; Empty set (0.00 sec)
  • 2. dilimiter $ mysql> create procedure calfine(Rollno int(20),name varchar(50)) begin declare ldate date; declare fine int(20); declare day int(20); select DateOfIsssue into ldate from Borrower where Rollin=Rollno and Nameofbook=name; set day = DATEDIFF(CURDATE(),ldate); IF(day>=15 and day<=30) then set fine=day*5; ELSEIF(day>30) then set fine=day*50; end IF; update Borrower set Status='R' where Rollin=Rollno and Nameofbook=name; IF(fine is not null) then insert into Fine values(Rollno,CURDATE(),fine); end IF; end $ mysql> call calfine(33,'toc')$ Query OK, 1 row affected (0.03 sec) mysql> select * from Fine$ +--------+------------+------+ | Rollno | Date | Amt | +--------+------------+------+ | 33 | 2019-08-07 | 4300 | +--------+------------+------+ 1 row in set (0.00 sec) mysql> call calfine(2,'sql')$ Query OK, 1 row affected (0.36 sec) mysql> call calfine(1,'dbms')$ Query OK, 1 row affected (0.34 sec) mysql> select * from Borrower$ +--------+--------+--------------+------------+--------+ | Rollin | Name | DateOfIsssue | Nameofbook | Status | +--------+--------+--------------+------------+--------+ | 1 | Rahul | 2019-07-13 | dbms | R | | 2 | Rakesh | 2019-07-28 | sql | R | | 33 | Aadil | 2019-05-13 | toc | R | | 85 | Akbar | 2019-06-20 | java | I | +--------+--------+--------------+------------+--------+ 4 rows in set (0.00 sec) mysql> select * from Fine$ +--------+------------+------+ | Rollno | Date | Amt | +--------+------------+------+ | 1 | 2019-08-07 | 125 | | 33 | 2019-08-07 | 4300 | +--------+------------+------+ 2 rows in set (0.00 sec)