- Categories:
AS_DECIMAL , AS_NUMBER¶
Casts aVARIANT value to a fixed-pointNUMBER value, with optional precision and scale.This function doesn’t cast floating-point values.
AS_DECIMAL is a synonym for AS_NUMBER.
TheDECIMAL data type is synonymous with the NUMBER data type.
- See also:
Syntax¶
AS_DECIMAL(<variant_expr>[,<precision>[,<scale>]])AS_NUMBER(<variant_expr>[,<precision>[,<scale>]])
Arguments¶
variant_exprAn expression that evaluates to a value of type VARIANT.
precisionThe number of significant digits of the decimal number to store.
The default is
38.scaleThe number of significant digits after the decimal point.
The default is
0.
Returns¶
The function returns a value of type NUMBER or NULL:
If the type of the value in the
variant_exprargument is DECIMAL or NUMBER, the function returns a value of type NUMBER.
If the type of the value in the
variant_exprargument doesn’t match the type of the outputvalue, the function returns NULL.If the
variant_exprargument is NULL, the function returns NULL.
Usage notes¶
When reducing scale, this function rounds the result, which can cause out-of-range errors.
Examples¶
Create a table and load data into it:
CREATEORREPLACETABLEas_number_example(number1VARIANT);INSERTINTOas_number_example(number1)SELECTTO_VARIANT(TO_NUMBER(2.34,6,3));
Use the AS_NUMBER function in a query to cast a VARIANT value to a NUMBER value:
SELECTAS_NUMBER(number1,6,3)number_valueFROMas_number_example;
+--------------+| NUMBER_VALUE ||--------------|| 2.340 |+--------------+