Cast Expression; Considerations For Cast; Valid Conversions For Cast; Examples Of Cast - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

CAST Expression

"Considerations for CAST"

"Valid Conversions for CAST "

"Examples of CAST"

The CAST expression converts data to the data type you specify.
CAST ({expression | NULL} AS data-type)
expression | NULL
specifies the operand to convert to the data type data-type.
If the operand is an expression, then data-type depends on the data type of expression
and follows the rules outlined in
If the operand is NULL, or if the value of the expression is null, the result of CAST is
NULL, regardless of the data type you specify.
data-type
specifies a data type to associate with the operand of CAST. See
When casting data to a CHAR or VARCHAR data type, the resulting data value is left justified.
Otherwise, the resulting data value is right justified. Further, when you are casting to a CHAR
or VARCHAR data type, you must specify the length of the target value.
Considerations for CAST
Fractional portions are discarded when you use CAST of a numeric value to an INTERVAL
type.
Depending on how your file is set up, using CAST might cause poor query performance by
preventing the optimizer from choosing the most efficient plan and requiring the executor
to perform a complete table or index scan.
Valid Conversions for CAST
An exact or approximate numeric value to any other numeric data type.
An exact or approximate numeric value to any character string data type.
An exact numeric value to either a single-field year-month or day-time interval such as
INTERVAL DAY(2).
A character string to any other data type, with one restriction:
The contents of the character string to be converted must be consistent in meaning with the
data type of the result. For example, if you are converting to DATE, the contents of the
character string must be 10 characters consisting of the year, a hyphen, the month, another
hyphen, and the day.
A date value to a character string or to a TIMESTAMP (Neoview SQL fills in the time part
with 00:00:00.00).
A time value to a character string or to a TIMESTAMP (Neoview SQL fills in the date part
with the current date).
A timestamp value to a character string, a DATE, a TIME, or another TIMESTAMP with
different fractional seconds precision.
A year-month interval value to a character string, an exact numeric, or to another year-month
INTERVAL with a different start field precision.
A day-time interval value to a character string, an exact numeric, or to another day-time
INTERVAL with a different start field precision.
Examples of CAST
In this example, the fractional portion is discarded:
"Valid Conversions for CAST " (page
357).
"Data Types" (page
243).
CAST Expression
357

Advertisement

Table of Contents
loading

Table of Contents