Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Applies to:
Databricks SQL
Databricks Runtime
Represents numbers with a specified maximum precision and fixed scale.
Syntax
{ DECIMAL | DEC | NUMERIC } [ ( p [ , s ] ) ]
p: Optional maximum precision (total number of digits) of the number between 1 and 38. The default is 10.s: Optional scale of the number between 0 andp. The number of digits to the right of the decimal point. The default is 0.
Limits
The range of numbers:
-1E(p-s) + 1E-sto-1E-s- 0
+1E-sto+1E(p-s) - 1E-s
Equivalently, the maximum magnitude is (1Ep - 1) × 1E-s.
For example, a DECIMAL(5, 2) has a range of -999.99 to 999.99.
Literals
decimal_digits { [ BD ] | [ exponent BD ] }
| digit [ ... ] [ exponent ] BD
decimal_digits:
[ + | - ] { digit [ ... ] . [ digit [ ... ] ]
| . digit [ ... ] }
exponent:
E [ + | - ] digit [ ... ]
digit: Any numeral from 0 to 9.
The BD postfix and exponent E are case insensitive.
Examples
> SELECT +1BD;
1
> SELECT 5E3BD;
5000
> SELECT 5.321E2BD;
532.1
> SELECT -6.45
-6.45
> SELECT typeof(6.45);
DECIMAL(3,2)
> SELECT CAST(5.345 AS DECIMAL(3, 2));
5.35
> SELECT typeof(CAST(5.345 AS DECIMAL));
DECIMAL(10, 0)
> SELECT typeof(CAST(5.345 AS DECIMAL(2)));
DECIMAL(2, 0)