(mysql.info.gz) Stored Procedure Syntax
Info Catalog
(mysql.info.gz) Stored Procedures
(mysql.info.gz) Stored Procedures
19.1 Stored Procedure Syntax
============================
Stored procedures and functions are routines that are created with
`CREATE PROCEDURE' and `CREATE FUNCTION' statements. A routine is
either a procedure or a function. A procedure is invoked using a
`CALL' statement, and can only pass back values using output variables.
A function can be called from inside a statement just like any other
function (that is, by invoking the function's name), and can return a
scalar value. Stored routines may call other stored routines.
As of MySQL 5.0.1, a stored procedure or function is associated with a
particular database. This has several implications:
* When the routine is invoked, an implicit `USE DB_NAME' is
performed (and undone when the routine terminates). `USE'
statements within stored routines are disallowed.
* You can qualify routine names with the database name. This can be
used to refer to a routine that is not in the current database.
For example, to invoke a stored procedure `p' or function `f' that
is associated with the `test' database, you can say `CALL
test.p()' or `test.f()'.
* When a database is dropped, all stored routines associated with it
are dropped as well.
(In MySQL 5.0.0, stored routines are global and not associated with a
database. They inherit the default database from the caller. If a `USE
DB_NAME' is executed within the routine, the original default database
is restored upon routine exit.)
MySQL supports the very useful extension that allows the use of regular
`SELECT' statements (that is, without using cursors or local variables)
inside a stored procedure. The result set of such a query is simply sent
directly to the client. Multiple `SELECT' statements generate multiple
result sets, so the client must use a MySQL client library that
supports multiple result sets. This means the client must use a client
library from a version of MySQL at least as recent as 4.1.
This following section describes the syntax used to create, alter,
drop, and query stored procedures and functions.
Menu
* Maintaining Stored Procedures Maintaining Stored Procedures
* SHOW PROCEDURE STATUS `SHOW PROCEDURE STATUS' and `SHOW FUNCTION STATUS'
* CALL `CALL' Statement
* BEGIN END `BEGIN ... END' Compound Statement
* DECLARE `DECLARE' Statement
* Variables in Stored Procedures Variables in Stored Procedures
* Conditions and Handlers Conditions and Handlers
* Cursors Cursors
* Flow Control Constructs Flow Control Constructs
Info Catalog
(mysql.info.gz) Stored Procedures
(mysql.info.gz) Stored Procedures
automatically generated byinfo2html