Conclusion
In this chapter we provided an overview of the building blocks of the MySQL stored program language. The MySQL stored program language—based on the ANSI SQL:2003 PSM specification—is a block-structured language that supports all the programming fundamentals that you would expect from a procedural language. The major aspects of the stored program language with which you should be familiar at this point are:
The
DECLARE
statement, which allows you to define and initialize program variables.Stored program parameters, which allow you to pass information into or—in the case of stored procedures—out of a stored program.
The
SET
statement, which allows you to change the value of a program variable.MySQL functions, operators, and data types—the MySQL stored program language utilizes most of the equivalents available in the MySQL SQL language.
Stored program type checking is very dependent on the setting of
the sql_mode
configuration
variable. If a program is created when the sql_mode
variable includes one of the strict
settings (STRICT_TRANS_TABLES
or
STRICT_ALL_TABLES
), then the
program will reject invalid variable assignments with an error. If
neither of the strict modes is in effect, then the stored program will
generate an error when invalid data assignments occur, but will
continue execution. Non-strict stored program behavior can lead to
unexpected and subtle bugs, and we recommend that you usually use the
strict mode when creating your stored programs.
Get MySQL Stored Procedure Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.