Reference Guide > TDV SQL Script > SQL Language Concepts > Data Types
 
Data Types
TDV supports several data types in SQL Script:
All of the character strings, numeric, date, time, and TIMESTAMP data types that SQL supports, plus BLOB, CLOB, ROW, and XML. For details, see Supported Data Types.
Custom data types. SQL Script lets you declare custom data types for convenience and clarity. You can declare them locally or make them PUBLIC. For details, see DECLARE TYPE.
The following guidelines apply to TDV data type support:
References to PUBLIC types must be fully qualified. Such references are valid anywhere the target data type is valid.
You can use a modifier named PIPE in procedure parameter declarations to pipeline (stream) the output. For details, see PIPE Modifier.
After you have declared a custom data type, you can use its name anywhere in the script that you can use a built-in type.
A PUBLIC type in another procedure can be accessed by specifying the fully qualified path to that procedure, followed by a period, followed by the name of the type.
Supported Data Types
The following table lists all the data types supported in SQL Scripts. All types with optional sizes have default values, as noted.
Data Type
Range or List of Values
Integer Numeric Types
BIT
0 or 1
TINYINT
-128 to 127
SMALLINT
-32768 to 32767
INTEGER
-231 to +231 - 1
INT
An alias for INTEGER
BIGINT
-263 to +263 - 1
Non-integer Numeric Types
FLOAT
Approximately 7-digit-precision floating point
REAL
An alias for FLOAT
DOUBLE
Approximately 17-digit-precision floating point
DECIMAL[(p,s)]
Fixed precision number with up to p (precision) digits total and up to s (scale) digits to the right of the decimal point. Default: DECIMAL(32,2).
NUMERIC[(p,s)]
Same as DECIMAL, except default is NUMERIC(32,0)
Date and Time Types
DATE
 
TIME
 
TIMESTAMP
 
String and Binary Types
CHAR[(n)]
Character string of exactly n characters, padded with spaces. Default for n: 255.
VARCHAR[(n)]
Also, CLOB
Unpadded character string of up to n characters. Default for n: 255.
BINARY[(n)]
Binary string of exactly n bytes, right-padded as necessary with bytes of zeroes. Default for n: 255.
VARBINARY(n)
Also, BLOB
Unpadded binary string of up to n bytes. Default for n: 255.
Other Types
BOOLEAN
A value of TRUE or FALSE. (‘BOOLEAN’ is not a valid value.)
CURSOR
An untyped cursor (because no list of fields is provided)
CURSOR(...)
A cursor defined as a set of fields (‘columns’)
CURSOR(rowType)
A CURSOR declared by referencing a ROW type (instead of specifying fields directly)
ROW(...)
A set of fields (also called ‘columns’)
XML [ (
{ DOCUMENT | CONTENT | SEQUENCE }
[ ( ANY | UNTYPED |
XMLSCHEMA schema-details ) ]
) ]
schema-details:
URI target-namespace-uri
[ LOCATION schema-location ]
[ { ELEMENT element-name
| NAMESPACE namespace-uri
[ ELEMENT element-name ] } ]
| NO NAMESPACE
[ LOCATION schema-location ]
[ { ELEMENT element-name
| NAMESPACE namespace-uri
[ ELEMENT element-name ] } ]
An XMLvalue. Default: ‘No Schema.’
target-namespace-uri: a string literal that represents a valid URI
schema-location: a string literal that represents a valid URI
namespace-uri: a string literal that represents a valid URI
element-name: any valid identifier
Example (Declaring a Custom Data Type)
You can declare a custom data type in SQL Script for later referencing:
DECLARE TYPE SocialSecurityType VARCHAR(12);
DECLARE ssn SocialSecurityType;
DECLARE data ROW (name VARCHAR(40), ssn SocialSecurityType);
Example (Referencing a Custom Data Type)
If you have declared a custom data type in SQL Script named SocialSecurityType in a procedure named TypeSample in the folder /shared/examples, you can reference the type as follows:
DECLARE ssn /shared/examples/TypeSample.SocialSecurityType;
Example (XML Data Type)
You can declare an XML data type in SQL Script as follows:
cast ('<item> </item>' as XML (SEQUENCE))
cast('<bar></bar>' as XML(SEQUENCE(ANY)))
PROCEDURE item()
BEGIN
DECLARE item
XML (SEQUENCE (XMLSCHEMA URI LOCATION 'http://www.w3.org/2001/
XMLSchema-instance' [^] ELEMENT xsi));
END