Stored Routine Syntax - Oracle 5.0 Reference Manual

Table of Contents

Advertisement

Stored routines can be particularly useful in certain situations:
• When multiple client applications are written in different languages or work on different platforms, but
need to perform the same database operations.
• When security is paramount. Banks, for example, use stored procedures and functions for all
common operations. This provides a consistent and secure environment, and routines can ensure
that each operation is properly logged. In such a setup, applications and users would have no access
to the database tables directly, but can only execute specific stored routines.
Stored routines can provide improved performance because less information needs to be sent between
the server and the client. The tradeoff is that this does increase the load on the database server
because more of the work is done on the server side and less is done on the client (application)
side. Consider this if many client machines (such as Web servers) are serviced by only one or a few
database servers.
Stored routines also enable you to have libraries of functions in the database server. This is a feature
shared by modern application languages that enable such design internally (for example, by using
classes). Using these client application language features is beneficial for the programmer even
outside the scope of database use.
MySQL follows the SQL:2003 syntax for stored routines, which is also used by IBM's DB2. All syntax
described here is supported and any limitations and extensions are documented where appropriate.
Additional Resources
• You may find the
functions.
• For answers to some commonly asked questions regarding stored routines in MySQL, see
Section B.4, "MySQL 5.0 FAQ: Stored Procedures and
• There are some restrictions on the use of stored routines. See
Programs".
• Binary logging for stored routines takes place as described in
Stored
Programs".

18.2.1. Stored Routine Syntax

A stored routine is either a procedure or a function. Stored routines are created with the
PROCEDURE
CREATE FUNCTION
"CALL
Syntax"), 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. The body of a stored routine can use compound statements (see
Compound-Statement
Stored routines can be dropped with the
Section 13.1.16,
PROCEDURE
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
terminates).
• 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
associated with the
Stored Procedures User Forum
and
CREATE FUNCTION
Syntax"). A procedure is invoked using a
Syntax").
"DROP PROCEDURE
and
ALTER FUNCTION
statements within stored routines are not permitted.
USE
database, you can say
test
Additional Resources
of use when working with stored procedures and
Functions".
statements (see
Section 13.1.9,
DROP PROCEDURE
and
DROP FUNCTION
statements (see
Section 13.1.3,
USE db_name
CALL test.p()
1695
Section E.1, "Restrictions on Stored
Section 18.6, "Binary Logging of
"CREATE PROCEDURE
statement (see
CALL
and
DROP FUNCTION
Syntax"), and altered with the
"ALTER PROCEDURE
is performed (and undone when the routine
or function
p
or test.f().
CREATE
and
Section 13.2.1,
Section 13.6, "MySQL
statements (see
ALTER
Syntax").
that is
f

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the 5.0 and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Mysql 5.0

Table of Contents