系统提供了数学操作符对POLARDB for Oracle所支持数据类型的值进行操作。而在后面的 章节中将介绍对那些没有通用数学约定的类型进行数值改变操作(例如,日期/时间类型)的实际动作。

下面的表显示了允许使用的数学操作符。

表 1. Mathematical Operators
Operator Description Example Result
+ Addition 2 + 3 5
- Subtraction 2 - 3 -1
* Multiplication 2 * 3 6
/ Division (integer division truncates results) 4 / 2 2
** Exponentiation Operator 2 ** 3 8

下面的表显示了允许使用的数学函数。通过使用不同的参数类型,以多种方式使用这些函数。除非特别说明,任何形式的函数都返回和它的参数类型相同的值。对DOUBLE PRECISION类型数据进行操作的函数是在主机系统C程序库的顶层实现,根据所运行的主机平台,在界限的精度和系统行为方面是有所不同。

表 2. Mathematical Functions
Function Return Type Description Example Result
ABS(x) Same as X Absolute value ABS(-17.4) 17.4
CEIL(DOUBLE PRECISION or NUMBER) Same as input Smallest integer not less than argument CEIL(-42.8) -42
EXP(DOUBLE PRECISION or NUMBER) Same as input Exponential EXP(1.0) 2.71828182845904 52
FLOOR(DOUBLE PRECISION or NUMBER) Same as input Largest integer not greater than argument FLOOR(-42.8) 43
LN(DOUBLE PRECISION or NUMBER) Same as input Natural logarithm LN(2.0) 0.69314718055994 53
L0G(b NUMBER, X NUMBER) NUMBER Logarithm to base b L0G(2.0, 64.0) 6.00000000000000 00
MOD(y, X) Same as argument types Remainder of y/x M0D(9, 4) 1
NVL(x, y) Same as argument types; where both arguments are of the same data type If X is null, then NVL returns y NVL(9, 0) 9
POWER(a DOUBLE PRECISION, b DOUBLE PRECISION) DOUBLE PRECISION a raised to the power of b P0WER(9.0, 3.0) 729.000000000000 0000
POWER(a NUMBER, b NUMBER) NUMBER a raised to the power of b P0WER(9.0, 3.0) 729.000000000000 0000
Function Return Type Description Example Result
ROUND(DOUBLE PRECISION or NUMBER) Same as input Round to nearest integer ROUND(42.4) 42
ROUND(v NUMBER, s INTEGER) NUMBER Round to s decimal places ROUND(42.4382, 2) 42.44
SIGN(DOUBLE PRECISION or NUMBER) Same as input Sign of the argument (-1, 0, +1) SIGN(-8.4) -1
SQRT(DOUBLE PRECISION or NUMBER) Same as input Square root SQRT(2.0) 1.41421356237309 5
TRUNC(DOUBLE PRECISION or NUMBER) Same as input Truncate toward zero TRUNC(42.8) 42
TRUNC(v NUMBER, s INTEGER) NUMBER Truncate to s decimal places TRUNC(42.4382, 2) 42.43
WIDTH BUCKET( op NUMBER, b1 NUMBER, b2 NUMBER, count INTEGER) INTEGER Return the bucket to which op would be assigned in an equidepth histogram with count buckets, in the range b1 to b2 WIDTH BUCKET(5.35, 0.024, 10.06, 5) 3

下面的表显示了允许使用的三角函数,所有的三角函数的参数和返回值类型都是DOUBLEPRECISION。

表 3. Trigonometric Functions
Function Description
ACOS(x) Inverse cosine
ASIN(x) Inverse sine
ATAN(x) Inverse tangent
ATAN2(x, y) Inverse tangent of x/y
COS(x) Cosine
SIN(x) Sine
TAN(x) Tangent