Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learn SQL using MySQL in One Day and Learn It Well

You're reading from  Learn SQL using MySQL in One Day and Learn It Well

Product type Book
Published in Apr 2024
Publisher Packt
ISBN-13 9781836205678
Pages 121 pages
Edition 1st Edition
Languages
Author (1):
Jamie Chan Jamie Chan
Profile icon Jamie Chan

Stored Function

 

The final thing that we need to code is the check_cancellation function.

 

This function checks the number of consecutive cancellations made by the member who's trying to cancel a booking. It has one parameter p_booking_id whose data type matches that of the id column in the bookings table. In addition, it returns an integer and is deterministic.

 

Try declaring this function yourself. You can refer to Chapter 10 for reference on declaring a function.

 

Within the function (between the BEGIN and END $$ markers), we need to use a cursor to loop through the bookings table vertically. To begin, let’s first declare three local variables called v_done, v_cancellation and v_current_payment_status.

 

Both v_done and v_cancellation are of INT type.

 

v_current_payment_status, on the other hand, has a data type that matches the data type of the payment_status column in the bookings table.

 

Next, we need to use...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}