Create a new function named opt_in_out()
that takes three parameters:
p_opt_in boolean
– a flag denoting whether a customer wants to opt in (TRUE
) or opt out (FALSE
).
p_cust_id int
– the customer's ID.
p_newsl_id int
– the newsletter's ID.
The function should perform the following operations:
- Create a
p_exists boolean
variable that will store TRUE
if there exists a row in the subscription
table that matches the function's arguments.
- Create separate cases:
- If
p_opt_in AND NOT p_exists
, then insert these values into the subscription
table: p_cust_id
, p_newsl_id
, and current_timestamp
.
- If
NOT p_opt_in AND p_exists
, then delete the proper row from the subscription table.
-
If p_opt_in AND p_exists
, then log the following information:
Argument |
Value |
p_process_name |
'opt_in_out()' |
p_message_text |
'Customer with ID of {p_cust_id} has already subscribed to the newsletter with ID of {p_newsl_id}' |
p_level |
'info' |
Finish the execution here.
-
In other cases, log the following information:
Argument |
Value |
p_process_name |
'opt_in_out()' |
p_message_text |
'Invalid customer with ID of {p_cust_id} or newsletter with ID of {p_newsl_id}' |
p_level |
'error' |
Finish the execution here.
-
Finally, log the following information:
Argument |
Value |
p_process_name |
'opt_in_out()' |
p_message_text |
'Opt in/out request for the customer with ID of {p_cust_id} and newsletter with ID of {p_newsl_id} has been processed' |
p_level |
'info' |