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)

More Related Content

PPT
Urban heat island
PPTX
Urban Heat Island Effect
PPT
Environmental Pollution
PPTX
PPT Discoloration of Taj Mahal
DOC
Dbms lab questions
PPTX
Detection of phishing websites
PPTX
Taj Mahal - The corroding beauty
PPTX
Diabetes Mellitus
Urban heat island
Urban Heat Island Effect
Environmental Pollution
PPT Discoloration of Taj Mahal
Dbms lab questions
Detection of phishing websites
Taj Mahal - The corroding beauty
Diabetes Mellitus

What's hot (20)

PDF
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
PDF
database application using SQL DML statements: all types of Join, Sub-Query ...
TXT
Getweeklyhoursbyuser
PPTX
Railway booking & management system
PPTX
Eucalyptus, Nimbus & OpenNebula
PDF
Course registration system
PDF
E learning project report (Yashraj Nigam)
PPTX
Cloud Reference Model
PDF
database application using SQL DML statements: Insert, Select, Update, Delet...
PPTX
(Project) Student grading system
PPTX
Fingerprint Authentication for ATM
PDF
Student information chatbot final report
DOCX
Synopsis on railway reservation system
PPTX
Vision of cloud computing
PPTX
Online Quiz System Project PPT
PPTX
Car rental Project Ppt
PPSX
Student Marks Analyzing System-Problem Statement, SRS, ERD, DFD, Structured C...
PDF
Railway reservation system
PPTX
Pgp pretty good privacy
PDF
Graphical Password by Image Segmentation
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
database application using SQL DML statements: all types of Join, Sub-Query ...
Getweeklyhoursbyuser
Railway booking & management system
Eucalyptus, Nimbus & OpenNebula
Course registration system
E learning project report (Yashraj Nigam)
Cloud Reference Model
database application using SQL DML statements: Insert, Select, Update, Delet...
(Project) Student grading system
Fingerprint Authentication for ATM
Student information chatbot final report
Synopsis on railway reservation system
Vision of cloud computing
Online Quiz System Project PPT
Car rental Project Ppt
Student Marks Analyzing System-Problem Statement, SRS, ERD, DFD, Structured C...
Railway reservation system
Pgp pretty good privacy
Graphical Password by Image Segmentation
Ad

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)

PPT
Applied Partitioning And Scaling Your Database System Presentation
PDF
Advanced Query Optimizer Tuning and Analysis
PDF
Need for Speed: MySQL Indexing
ODP
Common schema my sql uc 2012
ODP
Common schema my sql uc 2012
PDF
Advance MySQL Training by Pratyush Majumdar
PDF
Building advanced data-driven applications
PDF
Window functions in MySQL 8.0
PPTX
Writing efficient sql
PPTX
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
PDF
Performance Schema for MySQL Troubleshooting
ODP
PPT
Introduction To Lamp P2
PPTX
MySQL8.0_performance_schema.pptx
PPTX
Date data type and Globalization in Oracle
PDF
Percona live-2012-optimizer-tuning
PPT
4. Data Manipulation.ppt
PDF
Parallel Query in AWS Aurora MySQL
PDF
MySQL SQL Tutorial
PDF
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
Applied Partitioning And Scaling Your Database System Presentation
Advanced Query Optimizer Tuning and Analysis
Need for Speed: MySQL Indexing
Common schema my sql uc 2012
Common schema my sql uc 2012
Advance MySQL Training by Pratyush Majumdar
Building advanced data-driven applications
Window functions in MySQL 8.0
Writing efficient sql
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
Performance Schema for MySQL Troubleshooting
Introduction To Lamp P2
MySQL8.0_performance_schema.pptx
Date data type and Globalization in Oracle
Percona live-2012-optimizer-tuning
4. Data Manipulation.ppt
Parallel Query in AWS Aurora MySQL
MySQL SQL Tutorial
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
Ad

More from bhavesh lande (19)

PDF
The Annual G20 Scorecard – Research Performance 2019
PDF
information control and Security system
PDF
information technology and infrastructures choices
PDF
ethical issues,social issues
PDF
managing inforamation system
PDF
• E-commerce, e-business ,e-governance
PDF
IT and innovations
PDF
organisations and information systems
PDF
IT stratergy and digital goods
PDF
Implement Mapreduce with suitable example using MongoDB.
PDF
aggregation and indexing with suitable example using MongoDB.
PDF
working with python
PDF
applications and advantages of python
PDF
introduction of python in data science
PDF
PDF
data scientists and their role
PDF
applications
PDF
statistics techniques to deal with data
PPTX
introduction to data science
The Annual G20 Scorecard – Research Performance 2019
information control and Security system
information technology and infrastructures choices
ethical issues,social issues
managing inforamation system
• E-commerce, e-business ,e-governance
IT and innovations
organisations and information systems
IT stratergy and digital goods
Implement Mapreduce with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.
working with python
applications and advantages of python
introduction of python in data science
data scientists and their role
applications
statistics techniques to deal with data
introduction to data science

Recently uploaded (20)

PPTX
communication and presentation skills 01
PPTX
introduction to high performance computing
PPTX
Amdahl’s law is explained in the above power point presentations
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Soil Improvement Techniques Note - Rabbi
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
ChapteR012372321DFGDSFGDFGDFSGDFGDFGDFGSDFGDFGFD
PPTX
CyberSecurity Mobile and Wireless Devices
communication and presentation skills 01
introduction to high performance computing
Amdahl’s law is explained in the above power point presentations
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
"Array and Linked List in Data Structures with Types, Operations, Implementat...
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Fundamentals of Mechanical Engineering.pptx
Soil Improvement Techniques Note - Rabbi
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
ChapteR012372321DFGDSFGDFGDFSGDFGDFGDFGSDFGDFGFD
CyberSecurity Mobile and Wireless Devices

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)