Routines
DECLARE
Synopsis
DECLARE identifier [, ...] type [ DEFAULT expression ]
Description
Use the DECLARE
statement directly after the begin keyword in
routines to define one or more variables with an identifier
as name.
Examples
A simple declaration of the variable x
with the tinyint
data type and the
implicit default value of null
:
DECLARE x tinyint;
A declaration of multiple string variables with length restricted to 25 characters:
DECLARE first_name, last_name, middle_name varchar(25);
A declaration of an exact decimal number with a default value:
DECLARE uptime_requirement decimal DEFAULT 99.999;
A declaration with a default value from an expression:
DECLARE start_time timestamp(3) with time zone DEFAULT now();
Further examples of varying complexity that cover usage of the DECLARE
statement in combination with other statements are available in the SQL
routines examples documentation.