Variables are used within PL/pgSQL code to store modifiable data of an explicitly stated type. All variables that you will be using within a code block must be declared under the DECLARE keyword. If a variable is not initialized to a default value when it is declared, its value will default to the SQL NULL type.
Note: As you will read later on in the Section called Controlling Program Flow
," there is a type of statement known as the
FOR loop that initializes a variable used for iteration. The
FOR loop's iteration variable does not have to be pre-declared in the
DECLARE section for the block the loop is located within; hence, the
FOR loop is the only exception to the rule that all PL/pgSQL variables must be declared
at the beginning of the block they are located within.