Skip to content

PROC

DELIMITER //
CREATE PROCEDURE GetTotalOrders(IN customerID INT)
BEGIN
SELECT COUNT(*)
FROM orders
WHERE customer_id = customerID;
END//
DELIMITER ;
Query OK, 0 rows affected (0.00 sec)

The example provided shows a Stored Procedure in MySQL. The procedure GetTotalOrders takes in a customerID as an input parameter. It counts the total number of orders for the particular customer with the input customerID from the orders table.

The DELIMITER command is used to change the standard delimiter which is semicolon (;) to another symbol (// in this case). This is important because the stored procedure contains semicolons - without changing the delimiter, MySQL would interpret these as statement ending. The delimiter is changed back to semicolon at the end.