SET | Teradata Vantage - SET - Advanced SQL Engine - Teradata Database

SQL Stored Procedures and Embedded SQL

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
vqj1592443206677.ditamap
dita:ditavalPath
vqj1592443206677.ditaval
dita:id
B035-1148
lifecycle
previous
Product Category
Teradata Vantage™

Assigns a value to a local variable or parameter in a stored procedure.

ANSI Compliance

SET is ANSI/ISO SQL:2011-compliant.

Required Privileges

None.

Invocation

Executable.

Stored procedures only.

Syntax

SET assignment_target = assignment_source ;

Syntax Elements

assignment_target
The name of the variable or parameter to be assigned a value.
assignment_source
The value to be assigned to assignment_source.

Usage Notes

  • All valid expressions except those containing subqueries are permitted in a SET statement assignment source.
  • Both assignment target and assignment source must be specified.
  • Assignment target is always on the left hand side (LHS) of the SET expression.
  • Assignment source is always on the right hand side (RHS) of the SET expression.
  • The data type of the assignment source must be compatible with the data type specified for the assignment target. Vantage performs implicit conversions for DateTime data types when the source data type differs from the target data type. For more information, see Teradata Vantage™ - Data Types and Literals, B035-1143.
FOR this component of a SET assignment … Valid Constructs Are... Invalid Constructs Are...
assignment target
  • Local variable name
  • OUT or INOUT parameter name
  • QUERY_BAND variable name
  • Status variable
  • FOR loop column and correlation name
  • IN parameter
assignment source a literal or an expression containing one of the following:
  • Local variable
  • IN or INOUT parameter
  • FOR loop column and correlation names when the SET statement is within the scope of the FOR statement
  • Constant expression
  • Status variable
  • An expression that evaluates to a UDT
  • OUT parameter
  • FOR loop column and correlation names when the SET statement is not within the scope of the FOR statement

Example: Using the SET Statement to Assign Values

The following example illustrates a valid use of the SET statement to assign values to variables and parameters.

SET hNoAccts = hNoAccts + 1;
SET hErrorText = 'SQLSTATE: '||sqlstate|| 
', SQLCODE: '||sqlcode||', ACTIVITY_COUNT: '
 ||activity_count;