Movatterモバイル変換


[0]ホーム

URL:


Categories:

Semi-structured and structured data functions (Cast)

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:

AS_<object_type> ,AS_DOUBLE , AS_REAL ,AS_INTEGER

Syntax

AS_DECIMAL(<variant_expr>[,<precision>[,<scale>]])AS_NUMBER(<variant_expr>[,<precision>[,<scale>]])
Copy

Arguments

variant_expr

An expression that evaluates to a value of type VARIANT.

precision

The number of significant digits of the decimal number to store.

The default is38.

scale

The number of significant digits after the decimal point.

The default is0.

Returns

The function returns a value of type NUMBER or NULL:

  • If the type of the value in thevariant_expr argument is DECIMAL or NUMBER, the function returns a value of type NUMBER.

  • If the type of the value in thevariant_expr argument doesn’t match the type of the outputvalue, the function returns NULL.

  • If thevariant_expr argument 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));
Copy

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;
Copy
+--------------+| NUMBER_VALUE ||--------------||        2.340 |+--------------+

Alternative interfaces


[8]ページ先頭

©2009-2026 Movatter.jp