DECLARE Examples - Teradata VantageCloud Lake

Lake - Working with SQL

Deployment
VantageCloud
Edition
Lake
Product
Teradata VantageCloud Lake
Release Number
Published
February 2025
ft:locale
en-US
ft:lastEdition
2025-11-21
dita:mapPath
jbe1714339405530.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
jbe1714339405530

Example: Specifying Declaration

The declaration is completely specified:

DECLARE hErrorMsg CHARACTER(30) DEFAULT 'NO ERROR';

Example: Specifying Multiple Local Variables of the Same Data Type

Multiple local variables of the same data type can be specified in one declaration statement.

The following declaration declares both hAccountNo and tempAccountNo to be INTEGER. No default is specified for either variable; therefore NULL is assigned as the default for both.

DECLARE hAccountNo, tempAccountNo INTEGER;

The following statement declares the data types of hLastName and hFirstNameto be CHARACTER(30).

DECLARE hFirstName, hLastName CHARACTER(30);

Example: Assigning a Default Value for Each Local Variable

A default value can be assigned for each local variable specified in a declaration.

In the following example, a default value of 'NO ERROR' is explicitly assigned to hNoErrorMsg and hErrorMsg:

DECLARE hNoErrorMsg, hErrorMsg CHARACTER(30) DEFAULT 'NO ERROR';

Example: Declaring hBirthdate as DATE Data Type

The following statement declares hBirthdate to be of DATE data type with a default value of '1998-01-06'.

DECLARE hBirthdate DATE DEFAULT '1998-01-06';