Stored Procedures
Named procedural code blocks stored in the database that can be invoked by name, with support for control flow, variables, and transaction management.
stored procedure sproc procedure CREATE PROCEDURE
procedural stored procedure server-side logic ddl
| Database | Status | Syntax Family | Min Version |
|---|---|---|---|
| PostgreSQL | full | plpgsql | 11 |
| MySQL | full | sql-psm | 5.0 |
| MariaDB | full | sql-psm | - |
| Oracle | full | plsql | - |
| SQL Server | full | tsql | - |
| SQLite | none | - | - |
| Redshift | full | plpgsql | 2018 |
| DB2 | full | sql-pl | - |
| Snowflake | full | - | - |
| BigQuery | full | - | - |
Compare Databases
Database Details
PostgreSQL
full
CREATE PROCEDURE transfer_funds(sender INT, receiver INT, amount NUMERIC)
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE accounts SET balance = balance - amount WHERE id = sender;
UPDATE accounts SET balance = balance + amount WHERE id = receiver;
COMMIT;
END;
$$;
CALL transfer_funds(1, 2, 100.00);- CREATE PROCEDURE was added in PostgreSQL 11; prior versions only had CREATE FUNCTION.
- Procedures can manage transactions (COMMIT/ROLLBACK) within their body, unlike functions.
- Invoked with CALL statement.
Docs: CREATE PROCEDURE
MySQL
full
DELIMITER //
CREATE PROCEDURE transfer_funds(IN sender INT, IN receiver INT, IN amount DECIMAL(10,2))
BEGIN
UPDATE accounts SET balance = balance - amount WHERE id = sender;
UPDATE accounts SET balance = balance + amount WHERE id = receiver;
END //
DELIMITER ;
CALL transfer_funds(1, 2, 100.00);- Supports IN, OUT, and INOUT parameters.
- Uses BEGIN...END blocks with control flow (IF, CASE, LOOP, WHILE, REPEAT).
- Requires DELIMITER change in CLI clients to define multi-statement bodies.
Docs: CREATE PROCEDURE
MariaDB
full
DELIMITER //
CREATE PROCEDURE transfer_funds(IN sender INT, IN receiver INT, IN amount DECIMAL(10,2))
BEGIN
UPDATE accounts SET balance = balance - amount WHERE id = sender;
UPDATE accounts SET balance = balance + amount WHERE id = receiver;
END //
DELIMITER ;
CALL transfer_funds(1, 2, 100.00);- Syntax compatible with MySQL stored procedures.
- Supports IN, OUT, and INOUT parameters.
- Supports cursors, conditional logic (IF/CASE), loops (WHILE/REPEAT/LOOP), exception handling (DECLARE ... HANDLER).
Docs: Stored Procedures
Oracle
full
CREATE OR REPLACE PROCEDURE transfer_funds(
p_sender IN NUMBER,
p_receiver IN NUMBER,
p_amount IN NUMBER
) AS
BEGIN
UPDATE accounts SET balance = balance - p_amount WHERE id = p_sender;
UPDATE accounts SET balance = balance + p_amount WHERE id = p_receiver;
COMMIT;
END;
/
EXEC transfer_funds(1, 2, 100);- Uses PL/SQL procedural language.
- Supports IN, OUT, and IN OUT parameter modes.
- Can be organized into packages for modular grouping.
Docs: CREATE PROCEDURE
SQL Server
full
CREATE PROCEDURE transfer_funds
@sender INT,
@receiver INT,
@amount DECIMAL(10,2)
AS
BEGIN
UPDATE accounts SET balance = balance - @amount WHERE id = @sender;
UPDATE accounts SET balance = balance + @amount WHERE id = @receiver;
END;
GO
EXEC transfer_funds @sender = 1, @receiver = 2, @amount = 100.00;- Uses T-SQL procedural language.
- Supports OUTPUT parameters and return codes.
- Can include TRY...CATCH error handling and explicit transaction management.
Docs: CREATE PROCEDURE
SQLite
none
- SQLite does not support stored procedures.
- Procedural logic must be implemented in application code or via loadable extensions.
Redshift
full
CREATE OR REPLACE PROCEDURE transfer_funds(sender INT, receiver INT, amount NUMERIC)
AS $$
BEGIN
UPDATE accounts SET balance = balance - amount WHERE id = sender;
UPDATE accounts SET balance = balance + amount WHERE id = receiver;
COMMIT;
END;
$$ LANGUAGE plpgsql;
CALL transfer_funds(1, 2, 100.00);- PL/pgSQL stored procedures added in 2018.
- Supports transactions within procedures (COMMIT/ROLLBACK inside a procedure).
- Can manage temporary tables, dynamic SQL (EXECUTE), and cursors.
- Supports IN and OUT parameters.
DB2
full
CREATE OR REPLACE PROCEDURE transfer_funds(
IN sender INT,
IN receiver INT,
IN amount DECIMAL(10,2)
)
BEGIN
UPDATE accounts SET balance = balance - amount WHERE id = sender;
UPDATE accounts SET balance = balance + amount WHERE id = receiver;
COMMIT;
END;
CALL transfer_funds(1, 2, 100.00);- SQL PL (procedural language) with full control flow, cursors, exception handling, and dynamic SQL.
- Also supports external procedures in Java, C, COBOL.
- Compound statements (BEGIN ATOMIC) for atomic procedure bodies.
- Supports IN, OUT, and INOUT parameters.
Docs: CREATE PROCEDURE (SQL)
Snowflake
full
CREATE OR REPLACE PROCEDURE transfer_funds(sender FLOAT, receiver FLOAT, amount FLOAT)
RETURNS STRING
LANGUAGE SQL
AS
$$
BEGIN
UPDATE accounts SET balance = balance - amount WHERE id = sender;
UPDATE accounts SET balance = balance + amount WHERE id = receiver;
RETURN 'OK';
END;
$$;
CALL transfer_funds(1, 2, 100.00);- Supports multiple languages: JAVASCRIPT, PYTHON, JAVA, SQL (Snowflake Scripting).
- JavaScript was the original procedure language; Snowflake Scripting (SQL) added later.
- Supports EXECUTE IMMEDIATE for dynamic SQL.
- Caller's rights vs owner's rights security model.
Docs: CREATE PROCEDURE
BigQuery
full
CREATE OR REPLACE PROCEDURE myproject.mydataset.transfer_funds(
sender INT64, receiver INT64, amount FLOAT64
)
BEGIN
UPDATE accounts SET balance = balance - amount WHERE id = sender;
UPDATE accounts SET balance = balance + amount WHERE id = receiver;
END;- BigQuery supports CREATE PROCEDURE and CALL for SQL stored procedures.
- Procedures can contain multi-statement scripting with BEGIN...END, DECLARE, SET, IF, LOOP, and WHILE.
- Authorized routines and system procedures are also supported.
- This is SQL scripting rather than a traditional server-resident procedural runtime like PL/pgSQL or PL/SQL, but it is still genuine stored procedure support.
Docs: Procedures