- Categories:
AS_INTEGER¶
Casts a VARIANT value to an INTEGER. The function does not cast non-integer values.
The INTEGER data type is synonymous with the NUMBER data type, except that precision and scale can’t be specified for INTEGER values.
Syntax¶
AS_INTEGER( <variant_expr> )
Arguments¶
variant_expr
An expression that evaluates to a value of type VARIANT.
Returns¶
The function returns a value of type INTEGER or NULL:
If the type of the value in the
variant_expr
argument is INTEGER, the function returns a value of type INTEGER.
If the type of the value in the
variant_expr
argument doesn’t match the type of the output value, the function returns NULL.If the
variant_expr
argument is NULL, the function returns NULL.
Examples¶
Create a table and load data into it:
CREATE OR REPLACE TABLE as_integer_example (integer1 VARIANT);
INSERT INTO as_integer_example (integer1)
SELECT TO_VARIANT(15);
Use the AS_INTEGER function in a query to cast a VARIANT value to an INTEGER value:
SELECT AS_INTEGER(integer1) AS integer_value
FROM as_integer_example;
+---------------+
| INTEGER_VALUE |
|---------------|
| 15 |
+---------------+