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

SQL Stored Procedures and Embedded SQL

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
xqq1557098602407.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1148
lifecycle
previous
Product Category
Teradata Vantage™

Purpose

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

Invocation

Executable.

Stored procedures only.

Syntax

SET assignment_target = assignment_source ;

where:

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

ANSI Compliance

SET is ANSI/ISO SQL:2011-compliant.

Authorization

None.

Rules

  • 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. Teradata Database performs implicit conversions for DateTime data types when the source data type differs from the target data type. For more information, see “Data Type Conversions” in 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;