Introduction
A stored procedure is a subroutine available to applications that access a relational database system. A stored procedure (sometimes called a proc, sproc, StoPro, StoredProc, sp or SP) is actually stored in the database data dictionary.
Typical use for stored procedures include data validation (integrated into the database) or access control mechanisms. Furthermore, stored procedures can consolidate and centralize logic that was originally implemented in applications. Extensive or complex processing that requires execution of several SQL statements is moved into stored procedures, and all applications call the procedures. One can use nested stored procedures by executing one stored procedure from within another.
Stored procedures are similar to user-defined functions (UDFs). The major difference is that UDFs can be used like any other expression within SQL statements, whereas stored procedures must be invoked using the
A stored procedure is a subroutine available to applications that access a relational database system. A stored procedure (sometimes called a proc, sproc, StoPro, StoredProc, sp or SP) is actually stored in the database data dictionary.
Typical use for stored procedures include data validation (integrated into the database) or access control mechanisms. Furthermore, stored procedures can consolidate and centralize logic that was originally implemented in applications. Extensive or complex processing that requires execution of several SQL statements is moved into stored procedures, and all applications call the procedures. One can use nested stored procedures by executing one stored procedure from within another.
Stored procedures are similar to user-defined functions (UDFs). The major difference is that UDFs can be used like any other expression within SQL statements, whereas stored procedures must be invoked using the
CALL
statement.SQL Dialects Reference/Procedural language/Stored procedures
Database
|
Create syntax
|
Calling
|
DB2
|
CREATE PROCEDURE
procedure_name(...) BEGIN /* SQL code */ END
|
CALL
procedure_name(...)
|
SQLite
|
N/A
|
N/A
|
MySQL
|
DELIMITER
$$CREATE PROCEDURE nameprocedure (input_parameter_name datatype,
... )BEGIN /* SQL code */END$$DELIMITER ;
|
CALL
nameprocedure(...)
|
PostgreSQL
|
CREATE FUNCTION
function_name (input_parameter_name datatype, ...)RETURNS
return_typeAS $$DECLARE variable_name datatype;BEGIN /* SQL code
*/END;$$ LANGUAGE plpgsql;
|
SELECT
function_name(...)
|
Firebird
|
SET TERM $$
;CREATE PROCEDURE nameprocedure (input_parameter_name datatype,
... ) RETURNS (output_parameter_name datatype, ... )AS DECLARE
VARIABLE variable_name datatype;BEGIN /* SQL code */END$$SET TERM
; $$
|
SELECT ... FROM
function_name(...)
EXECUTE
function_name(...)
|
SQL
Server
|
CREATE PROCEDURE
nameprocedure (input_parameter_name datatype, ... )AS /* SQL
code */GO
|
EXEC
nameprocedure(...)
|
Linter
|
CREATE [OR
REPLACE] PROCEDURE procedure_name([IN/OUT/INOUT] parameter_name
datatype, ...) [RESULT datatype] [FOR DEBUG] DECLARE /*
variables declaration */ CODE /* stored procedure code
(including SQL code)*/ EXCEPTIONS /* exceptions declarations
*/ END
|
CALL
procedure_name(...)EXECUTE procedure_name(...)EXECUTE
procedure_name(...) AS OWNERSELECT procedure_name(...)FROM
...WHEREprocedure_name(...) = ...
|
Comments
Post a Comment
Important - Make sure to click the Notify Me check-box below the comment to be notified of follow up comments and replies.