SQL 方言参考/函数和表达式/数学函数/数值函数
外观
< SQL 方言参考
SQL 版本 | 功能 | 标准 SQL:2011 |
DB2 | Firebird | Ingres | Linter | MSSQL | MySQL 版本 5.x |
MonetDB | Oracle 版本 11.x |
PostgreSQL | SQLite | Virtuoso |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
? | 绝对值 of x | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) |
? | 数字 x 的符号 | N/A | SIGN(x) | SIGN(x) | SING(x) | SIGN(x) | SIGN(x) | SIGN(x) | SIGN(x) | SIGN(x) | SIGN(x) | N/A | SIGN(x) |
? | 模数 (余数) of | MOD(x, y) | MOD(x, y) | MOD(x, y) | MOD(x, y) | MOD(x, y) | x % y | x % y MOD(x, y) |
x % y MOD(x, y) |
MOD(x, y) | x % y MOD(x, y) |
x % y | MOD(x, y) |
? | 最小的整数 >= x | CEILING(x) CEIL(x) |
CEILING(x) CEIL(x) |
CEILING(x) CEIL(x) |
CEIL(x) CEILING(x) |
CEIL(x) | CEILING(x) | CEILING(x) CEIL(x) |
CEILING(x) CEIL(x) |
CEIL(x) | CEILING(x) CEIL(x) |
N/A | CEILING(x) |
? | 最大的整数 <= x | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) | N/A | FLOOR(x) |
? | 舍入 x(到 d 位精度) | N/A | ROUND(x, d) | ROUND(x, d) | ROUND(x, d) | ROUND(x[, d]) | ROUND(x[, d]) | ROUND(x[, d]) | ROUND(x, d) | ROUND(x[, d]) | ROUND(x[, d]) | ROUND(x[, d]) | ROUND(x) |
? | 将 x 截断到 n 位小数 | N/A | TRUNCATE(x, n) TRUNC(x, n) |
TRUNC(x[, n]) | TRUNCATE(x, n) TRUNC(x, n) |
TRUNC(x[, d]) | ROUND(x[, d], 1) | TRUNCATE(x[, dn) | sys.ms_trunc(x, n) | TRUNC | TRUNC(x[, y]) | N/A | N/A |
? | x 的平方根 () | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) | N/A | SQRT(x) |
? | 指数 of x () | EXP(x) | EXP(x) | EXP(x) | EXP(x) | EXP(x) | EXP(x) | EXP(x) | EXP(x) | EXP(x) | EXP(x) | N/A | EXP(x) |
? | 幂 () | POWER(x, y) | POWER(x, y) | POWER(x, y) | POWER(x, y) x ** y |
POWER(x, y) | POWER(x, y) | POW(x, y) POWER(x, y) |
POWER(x, y) | POWER(x, y) | POWER(x, y) | N/A | POWER(x,y) |
? | x 的自然对数 | LN(x) | LN(x) | LN(x) | LOG(x) LN(x) |
LN(x) | LOG(x) | LN(x) LOG(x) |
LN(x) LOG(x) |
LN(x) | LN(x) | N/A | LOG(x) |
? | x 的对数,底数为 b | N/A | LOG(b, x) | LOG(b, x) | N/A | LOG(b, x) | LOG(x, b) | LOG(b, x) | LOG(b, x) | LOG(b, x) | LOG(b, x) | N/A | ? |
? | 以 10 为底的对数 | N/A | LOG10(x) | LOG10(x) | N/A | N/A | LOG10(x) | LOG10(x) | LOG10(x) | LOG(x) | LOG(x) | N/A | LOG(x) |
? | 随机化,将种子设置为 x | N/A | RAND(x) | N/A | SET RANDOM_SEED x | RAND(x) | RAND(x) | RAND(x) | RAND(x) | random()[1] | SETSEED(x) | N/A | RANDOMIZE([x]) |
? | 生成 0 到 1 之间的浮点随机数 | N/A | RAND() | RAND() | RANDOMF() | RAND() | RAND() | RAND() | CAST(RAND() as float) / 2147483648 | dbms_random.value (返回数字 >= 0 且 < 1)dbms_random.value(37, 89) (返回一个 >= 37 且 < 89 的随机数) |
RANDOM() | RANDOM() (在 −263 和 263 之间) | RND() |
? | 列表 中的最高数字 | N/A | N/A | MAXVALUE(list) | ? | GREATEST(list) | N/A | GREATEST(list) | GREATEST(a, b) | GREATEST(list) | GREATEST(list) | MAX(list) | MAX(list) |
? | 列表 中的最低数字 | N/A | N/A | MINVALUE(list) | ? | LEAST(list) | N/A | LEAST(list) | LEAST(a, b) | LEAST(list) | LEAST(list) | MIN(list) | MIN(list) |
- ↑ Oracle 中的 random() 函数可以在内置的 DBMS 包 dbms_random 中找到。