CAST()

From Recital Documentation Wiki
Revision as of 13:44, 9 June 2009 by Yvonnemilne (Talk | contribs)

Jump to: navigation, search

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
> set sql on
Recital/SQL> select cast(limit-balance as numeric(10,2)) from example;


Products

Recital Database Server, Recital Mirage Server, Recital Terminal Developer