Procedure with output parameter
SQL
Easy
2 views
Problem Description
Create sp_order_total(p_order_id, OUT p_total) that returns sum(qty*price) from OrderItems.
Input Format
SQL procedure
Output Format
Procedure created
Sample Test Case
Input:
OrderItems(order_id, qty, price)
Output:
Procedure created
Official Solution
CREATE PROCEDURE sp_order_total(IN p_order_id INT, OUT p_total DECIMAL(10,2)) BEGIN SELECT COALESCE(SUM(qty * price),0) INTO p_total FROM OrderItems WHERE order_id = p_order_id; END;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!