Difference between revisions of "CAST()"
Barrymavin (Talk | contribs) (→Example) |
Barrymavin (Talk | contribs) (→Example) |
||
Line 71: | Line 71: | ||
> ? cast("12/12/2005" as (m_var)) | > ? cast("12/12/2005" as (m_var)) | ||
12/12/2005 | 12/12/2005 | ||
− | |||
> open database southwind | > open database southwind | ||
− | + | > select cast(limit-balance as numeric(10,2)) from example | |
− | + | ||
</code> | </code> | ||
Revision as of 08:30, 13 July 2009
Contents
Class
Expressions and Type Conversion
Purpose
Function to convert the data type of an expression
Syntax
CAST(<exp> AS <expC>[(<expN1>[, <expN2>])] [NULL | NOT NULL])
See Also
DTOC(), DTOS(), ETOS(), LTOS(), MTOS(), STR()
Description
The CAST() function converts the expression in <exp> to the data type specified in <expC> and returns the result. The <expC> can be the full data type name, e.g. Character or supported abbreviation, e.g. C or Char. For data types requiring width and precision information, these are specified in <expN1> and <expN2> respectively.
Data Type Abbreviations
Abbreviations | Data Type | Width Required | Precision Required |
---|---|---|---|
B | TINYINT/DOUBLE | No | No |
C, Char | CHARACTER | Yes | No |
D | DATE | No | No |
F | FLOAT | Yes | No, defaults to 0 |
G | LONG VARBINARY/GENERAL | No | No |
I, Int | INTEGER | Yes | No, defaults to 0 |
L | LOGICAL/BIT | No | No |
M | LONG VARCHAR/MEMO | No | No |
N, Num | NUMERIC | Yes | No, defaults to 0 |
P | PACKED DECIMAL | Yes | No, defaults to 0 |
Q | QUAD | Yes | No, defaults to 0 |
R | REAL | Yes | No, defaults to 0 |
S | SHORT | Yes | No, defaults to 0 |
T | DATETIME | No | No |
V | VAXDATE | No | No |
Y | CURRENCY | No | No |
Z | ZONED | Yes | No, defaults to 0 |
If the specified width, <expN1> is less than that of <exp>, the result will be truncated. If greater, the result will be padded. Precision may be lost if the precision specified in <expN2> is less than that of <exp>.
The optional NULL | NOT NULL determines whether null values are permitted or not.
Example
> m_var = "date" > ? cast("12/12/2005" as (m_var)) 12/12/2005 > open database southwind > select cast(limit-balance as numeric(10,2)) from example
Products
Recital Database Server, Recital Mirage Server, Recital Terminal Developer