Procedures
StevenSwiniarski474 total contributions
Published Dec 30, 2021
Contribute to Docs
Procedures are blocks of SQL code that are saved in a database and can be executed repeatedly on demand. Also referred to as stored procedures — they can be defined with parameters to be used within the body of the procedure, produce an output value, or both.
The syntax for creating a procedure varies depending upon the type of database management system (DBMS) being used. Below is an example procedure defined and executed with MySQL that accepts two parameters and returns an output value.
MySQL Example
# Set the default delimiter so the procedure can include semicolonsDELIMITER //# Create the procedureCREATE PROCEDURE add_int (IN x INT, IN y INT, OUT z INT)BEGINSELECT x + y INTO z;END //# Set the delimiter back to the defaultDELIMITER ;# Execute the stored procedureCALL add_int (5, 3, @z);# Return the output parameterSELECT @z AS Result;
Output:
Result |
---|
8 |
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.