|
|
CAST Specification
With the
CASTspecification it is possible to specify a data type conversion.CASTconverts the value of an expression to a specified data type.Rules
The following rules apply to
CAST:
data-typecan be any (cast compatible) SQL data type supported by Mimer SQL.The table below describes cast compatibility. (An asterisk indicates that specific limitations do also apply. For example casting an integer value to a one-field interval data type is possible, but not to a two-field interval.)
- When converting a numeric or character value to fixed-length character, the value of the source expression is padded with trailing spaces, if the length of the converted value is shorter than the length of the target data type.
- When converting a numeric or character value to variable-length character, no trailing spaces are padded.
- A character value can be converted to a character value of another character type and/or another length if the value to convert is not longer than the length of the target (for
CHARACTER) or the maximum length of the target (forVARCHAR).- A character value can be converted to a fixed-length binary value of equal length.
- A character value can be converted to a variable-length binary value of another length if the value to convert is not longer than the length of the target (for
CHARACTER) or the maximum length of the target (forVARCHAR).- A character value can be converted to a national character value.
- A national character value can be converted to a character value. If the national character value contains non-Latin1 characters, those characters are replaced with '
¿' and a warning is returned.- Character values can be converted to a numeric data type if the character string consists of a valid literal representation of the target data type.
- Character values can be converted to a
DATETIMEorINTERVALdata type providedexpressionconforms to the natural limits placed on date/time values by the Gregorian calendar.- When a
DATEis converted to aTIMESTAMP, theHOUR,MINUTEandSECONDfields of the target are set to zero. The other fields are set to the corresponding values in the source expression.- When a
TIMEis converted to aTIMESTAMP, the respective values for theYEAR,MONTHandDAYfields of the target are obtained by evaluatingCURRENT_DATE. The other fields are set to the corresponding values in the source expression.- When a
TIMESTAMPis converted to aDATEorTIME, the fields of the target are set to the corresponding values in the source expression. Any values in the source expression for which there are no corresponding fields in the target are ignored.- When converting from a single field
INTERVALto an exact numeric value, it must be possible to represent theINTERVALvalue as an exact numeric value without the loss of leading significant digits.- When converting from an exact numeric value to a single field
INTERVAL, it must be possible to represent the exact numeric as anINTERVALvalue without the loss of leading significant digits.- If
CASTis applied onNULL, or ifexpressionresults inNULL, thenCASTreturnsNULL.- Character values can be converted to a
BOOLEANdata type provided expression contains the stringTRUEorFALSEregardless of case.- When converting a boolean value to fixed-length character, the value of the source expression is padded with trailing spaces, if the length of the converted value is shorter than the length of the target data type. The boolean value
TRUEis converted to the stringTRUEandFALSEis converted to the stringFALSE.- When converting a boolean value to variable-length character, no trailing spaces are padded.
Example
SELECT CAST(floatcol AS DECIMAL(15,3)), CAST(charcol AS VARCHAR(10)), CAST(intcol AS CHAR(15)), CAST(decimcol AS FLOAT) FROM types_tab;
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|