[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Stored procedures and functions are routines that are created with
CREATE PROCEDURE
and CREATE FUNCTION
statements.
A procedure is invoked using a CALL
statement, and can only
pass back values using output variables. Functions may return a
scalar value and can be called from inside a statement just like any other
function (that is, by invoking the function's name).
Stored routines may call other stored routines. A routine is either a
procedure or a function.
At present, MySQL only preserves context for the default database. That is,
if you say USE dbname
within a procedure, the original default
database is restored upon routine exit.
A routine inherits the default database from the caller, so generally routines
should either issue a USE dbname
statement, or specify all tables
with an explicit database reference, e.g. dbname.tablename
.
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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |