3307 Dbms 4
3307 Dbms 4
mysql> delimiter ;;
mysql> create procedure return_book(in roll_no int) begin declare amount int;
declare issue_date date; declare return_date date; declare borrowed_days int;
-> declare exit handler for sqlexception select 'some error occured!!'; select
borrower.issue_date into issue_date from borrower where borrower.roll_no=roll_no;
select curdate() into return_date; select datediff(return_date, issue_date) into
borrowed_days; set amount=0; if borrowed_days>15 and borrowed_days<=30 then set
amount=borrowed_days * 5; elseif borrowed_days>30 then set amount=(borrowed_days-
30) *50 +30 * 5; end if; insert into fine
values(roll_no,issue_date,return_date,amount); updateborrower set status='returned'
where borrower.roll_no =roll_no;
-> end;;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'set
status='returned' where borrower.roll_no =roll_no;
end' at line 2
mysql> delimiter ;;
mysql> create procedure return_book(in roll_no int) begin declare amount int;
declare issue_date date; declare return_date date; declare borrowed_days int;
-> declare exit handler for sqlexception select 'some error occured!!'; select
borrower.issue_date into issue_date from borrower where borrower.roll_no=roll_no;
select curdate() into return_date; select datediff(return_date, issue_date) into
borrowed_days; set amount=0; if borrowed_days>15 and borrowed_days<=30 then set
amount=borrowed_days * 5; elseif borrowed_days>30 then set amount=(borrowed_days-
30) *50 +30 * 5; end if; insert into fine
values(roll_no,issue_date,return_date,amount); update borrower set
status='returned' where borrower.roll_no =roll_no;
-> end;;
Query OK, 0 rows affected (0.03 sec)
mysql> delimiter ;
mysql> call retunr_book(3301);
ERROR 1305 (42000): PROCEDURE library.retunr_book does not exist
mysql> call return_book(3301);
Query OK, 1 row affected (0.02 sec)
mysql> select
fine.roll_no,borrower.name,fine.issue_date,fine.return_date,fine.amount from fine
inner join borrower on fine.roll_no=borrower.roll_no;
+---------+--------+------------+-------------+--------+
| roll_no | name | issue_date | return_date | amount |
+---------+--------+------------+-------------+--------+
| 3301 | adarsh | 2022-09-01 | 2022-09-16 | 0 |
| 3305 | aditya | 2021-06-01 | 2022-09-16 | 22250 |
+---------+--------+------------+-------------+--------+
2 rows in set (0.00 sec)
mysql> select
fine.roll_no,borrower.name,fine.issue_date,fine.return_date,fine.amount from fine
inner join borrower on fine.roll_no=borrower.roll_no;
+---------+---------------+------------+-------------+--------+
| roll_no | name | issue_date | return_date | amount |
+---------+---------------+------------+-------------+--------+
| 3301 | adarsh | 2022-09-01 | 2022-09-16 | 0 |
| 3302 | abhay | 2022-08-11 | 2022-09-16 | 450 |
| 3305 | aditya | 2021-06-01 | 2022-09-16 | 22250 |
| 3321 | harshit singh | 2022-07-01 | 2022-09-16 | 2500 |
+---------+---------------+------------+-------------+--------+
4 rows in set (0.00 sec)