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...