Procedure with retry logic idea
SQL
Hard
2 views
Problem Description
When inserting into Payments, deadlock may happen. Write a stored procedure outline that retries 3 times (simple loop).
Input Format
SQL procedure
Output Format
Procedure created
Sample Test Case
Output:
Procedure created
Constraints
Pseudocode in SQL style
Official Solution
CREATE PROCEDURE sp_insert_payment_retry(IN p_order_id INT, IN p_amount DECIMAL(10,2)) BEGIN DECLARE i INT DEFAULT 0; retry_loop: WHILE i < 3 DO BEGIN INSERT INTO Payments(order_id, amount, paid_at) VALUES (p_order_id, p_amount, CURRENT_TIMESTAMP); SET i = 3; END; END WHILE; END;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!