A stored procedure is a precompiled collection of SQL statements that can be executed as a single unit.
CREATE PROCEDURE GetEmployeesByDept(IN deptId INT)
BEGIN
SELECT name, salary
FROM employees
WHERE dept_id = deptId;
END;
CALL GetEmployeesByDept(2);
CREATE PROCEDURE GetEmployeeCountByDept(IN deptId INT, OUT empCount INT)
BEGIN
SELECT COUNT(*) INTO empCount
FROM employees
WHERE dept_id = deptId;
END;
-- Execution
CALL GetEmployeeCountByDept(2, @count);
SELECT @count;
EXECUTE permissions.