Difference between revisions of "CAST()"

From Recital Documentation Wiki
Jump to: navigation, search
 
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Class==
 
Expressions and Type Conversion
 
 
 
 
==Purpose==
 
==Purpose==
 
Function to convert the data type of an expression
 
Function to convert the data type of an expression
Line 67: Line 63:
  
 
==Example==
 
==Example==
 +
<code lang="recital">
 
> m_var = "date"
 
> m_var = "date"
 
> ? 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
> set sql on
+
> select cast(limit-balance as numeric(10,2)) from example
Recital/SQL> select cast(limit-balance as numeric(10,2)) from example;
+
 
</code>
 
</code>
 
  
 
==Products==
 
==Products==
Recital Database Server, Recital Mirage Server, Recital Terminal Developer
+
Recital Server, Recital  
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:SQL]]
 
[[Category:SQL]]
 +
[[Category:Expressions and Type Conversion]]
 +
[[Category:Expressions and Type Conversion Functions]]

Latest revision as of 16:06, 27 November 2009

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 Server, Recital