17.10 - Examples - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - Data Types and Literals

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1143-171K
Language
English (United States)

The following examples illustrate how to perform data type conversions using CAST.

Example: Performing Data Type Conversions

Using ANSI CAST syntax:

SELECT ID_Col, Name_Col
FROM T1
WHERE Int_Col = CAST(SUBSTRING(Char_Col FROM 3 FOR 3) AS INTEGER);

Example: Performing Data Type Conversions Using ANSI CAST Syntax

Using ANSI CAST syntax:

SELECT CAST(SUBSTRING(Char_Col FROM 1 FOR 2) AS INTEGER),
   CAST(SUBSTRING (Char_Col FROM 3 FOR 3) AS INTEGER) 
FROM T1;

Example: Performing Data Type Conversions Using Teradata Extensions to the ANSI CAST Syntax

Using Teradata extensions to the ANSI CAST syntax:

CREATE TABLE t2 (f1 TIME(0) FORMAT 'HHhMIm');
   
INSERT t2 (CAST('15h33m' AS TIME(0) FORMAT 'HHhMIm'));
   
SELECT f1 FROM t2;

The result from the SELECT statement is:

    f1
------
15h33m