cast-specification |--CAST--(--+-expression-------+--AS--data-type-----------------> +-NULL-------------+ '-parameter-marker-' (1) >----+------------------------------+---)-----------------------| '-SCOPE--+-typed-table-name-+--' '-typed-view-name--'
Notes:
|
The CAST specification returns the cast operand (the first operand) cast to the type specified by the data type.
The supported casts are shown in Table 4 where the first column represents the data type of the cast operand (source data type) and the data types across the top represent the target data type of the CAST specification. If the cast is not supported an error will occur (SQLSTATE 42846).
When casting character strings (other than CLOBs) to a character string with a different length, a warning (SQLSTATE 01004) is returned if truncation of other than trailing blanks occurs. When casting graphic character strings (other than DBCLOBs) to a graphic character string with a different length, a warning (SQLSTATE 01004) is returned if truncation of other than trailing blanks occurs. For BLOB, CLOB and DBCLOB cast operands, the warning is issued if any characters are truncated.
When numeric data is cast to character the result data type is a fixed-length character string (see CHAR). When character data is cast to numeric, the result data type depends on the type of number specified. For example, if cast to integer, it would become a large integer (see INTEGER).
SELECT EMPNO, CAST(SALARY AS INTEGER) FROM EMPLOYEE
UPDATE PERSONNEL SET RETIRE_YEAR =? WHERE AGE = CAST( ? AS T_AGE)
The first parameter is an untyped parameter marker that would have a data type of R_YEAR, although the application will use an integer for this parameter marker. This does not require the explicit CAST specification because it is an assignment.
The second parameter marker is a typed parameter marker that is cast as a distinct type T_AGE. This satisfies the requirment that the comparison must be performed with compatible data types. The application will use the source data type (which is SMALLINT) for processing this parameter marker.
Successful processing of this statement assumes that the function path includes the schema name of the schema (or schemas) where the two distinct types are defined.