Difference between revisions of "CAST()"
Helen.george (Talk | contribs) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
====Data Type Abbreviations==== | ====Data Type Abbreviations==== | ||
− | {| class="wikitable" | + | {| class="wikitable" width="100%" |
!Abbreviations||Data Type||Width Required||Precision Required | !Abbreviations||Data Type||Width Required||Precision Required | ||
|- | |- | ||
Line 22: | Line 22: | ||
|D||DATE||No||No | |D||DATE||No||No | ||
|- | |- | ||
− | |F||FLOAT||Yes||No, defaults to 0 | + | |valign="top"|F||valign="top"|FLOAT||valign="top"|Yes||No, defaults to 0 |
|- | |- | ||
− | |G||LONG VARBINARY/GENERAL||No||No | + | |valign="top"|G||LONG VARBINARY/GENERAL||valign="top"|No||valign="top"|No |
|- | |- | ||
− | |I, Int||INTEGER||Yes||No, defaults to 0 | + | |valign="top"|I, Int||INTEGER||valign="top"|Yes||No, defaults to 0 |
|- | |- | ||
|L||LOGICAL/BIT||No||No | |L||LOGICAL/BIT||No||No | ||
|- | |- | ||
− | |M||LONG VARCHAR/MEMO||No||No | + | |valign="top"|M||LONG VARCHAR/MEMO||valign="top"|No||valign="top"|No |
|- | |- | ||
− | |N, Num||NUMERIC||Yes||No, defaults to 0 | + | |valign="top"|N, Num||valign="top"|NUMERIC||valign="top"|Yes||No, defaults to 0 |
|- | |- | ||
− | |P||PACKED DECIMAL||Yes||No, defaults to 0 | + | |valign="top"|P||valign="top"|PACKED DECIMAL||valign="top"|Yes||No, defaults to 0 |
|- | |- | ||
− | |Q||QUAD||Yes||No, defaults to 0 | + | |valign="top"|Q||valign="top"|QUAD||valign="top"|Yes||No, defaults to 0 |
|- | |- | ||
− | |R||REAL||Yes||No, defaults to 0 | + | |valign="top"|R||valign="top"|REAL||valign="top"|Yes||No, defaults to 0 |
|- | |- | ||
− | |S||SHORT||Yes||No, defaults to 0 | + | |valign="top"|S||valign="top"|SHORT||valgn="top"|Yes||No, defaults to 0 |
|- | |- | ||
|T||DATETIME||No||No | |T||DATETIME||No||No | ||
Line 48: | Line 48: | ||
|Y||CURRENCY||No||No | |Y||CURRENCY||No||No | ||
|- | |- | ||
− | |Z||ZONED||Yes||No, defaults to 0 | + | |valign="top"|Z||valign="top"|ZONED||valign="top"|Yes||No, defaults to 0 |
|- | |- | ||
|} | |} | ||
Line 68: | Line 68: | ||
[[Category:Documentation]] | [[Category:Documentation]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
− | |||
− | |||
− | |||
[[Category:Formatting Functions]] | [[Category:Formatting Functions]] | ||
+ | [[Category:SQL]] |
Latest revision as of 07:57, 4 February 2013
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