Skip to content

OUT

DELIMITER //
CREATE PROCEDURE GetTotalOrders(OUT total INT)
BEGIN
SELECT COUNT(*) INTO total FROM orders;
END //
CALL GetTotalOrders(@total);
SELECT @total;
+-------+
| @total|
+-------+
| 100 |
+-------+

The SQL procedure GetTotalOrders is created to get the total number of orders from the table orders. The OUT parameter total is used to store the result. After the procedure is called with a user-defined variable @total, it extracts the total order count and stores it in @total. A SELECT statement is then used to display the total count of the orders.