A stored procedure is a saved program inside the database — a block of SQL with parameters, variables, and control flow that you run with a single CALL. They power repeatable data-processing routines and ETL steps.
Key Points
- Define with DELIMITER $$ CREATE PROCEDURE get_sales(IN p_year INT) BEGIN … END $$
- Run it: CALL get_sales(2026);
- Parameters: IN (input), OUT (return values), INOUT (both)
- Declare variables, use IF/CASE and WHILE loops inside
- Pros: reusable logic, fewer round-trips, controlled access
- Cons: harder to version-control — keep definitions in Git as .sql files
.png)