跳到主要内容

Numeric Functions

This page provides a comprehensive overview of Numeric functions in Databend, organized by functionality for easy reference.

Basic Arithmetic Functions

FunctionDescriptionExample
PLUS / ADDAddition operator5 + 38
MINUS / SUBTRACTSubtraction operator5 - 32
MULTIPLYMultiplication operator5 * 315
DIVDivision operator10 / 25.0
DIV0Division that returns 0 instead of error for division by zeroDIV0(10, 0)0
DIVNULLDivision that returns NULL instead of error for division by zeroDIVNULL(10, 0)NULL
INTDIVInteger division10 DIV 33
MOD / MODULOModulo operation (remainder)10 % 31
NEG / NEGATENegation-5-5

Rounding and Truncation Functions

FunctionDescriptionExample
ROUNDRounds a number to specified decimal placesROUND(123.456, 2)123.46
FLOORReturns the largest integer not greater than the argumentFLOOR(123.456)123
CEIL / CEILINGReturns the smallest integer not less than the argumentCEIL(123.456)124
TRUNCATETruncates a number to specified decimal placesTRUNCATE(123.456, 1)123.4

Exponential and Logarithmic Functions

FunctionDescriptionExample
EXPReturns e raised to the power of xEXP(1)2.718281828459045
POW / POWERReturns x raised to the power of yPOW(2, 3)8
SQRTReturns the square root of xSQRT(16)4
CBRTReturns the cube root of xCBRT(27)3
LNReturns the natural logarithm of xLN(2.718281828459045)1
LOG10Returns the base-10 logarithm of xLOG10(100)2
LOG2Returns the base-2 logarithm of xLOG2(8)3
LOGXReturns the logarithm of y to base xLOGX(2, 8)3
LOGBXReturns the logarithm of x to base bLOGBX(8, 2)3

Trigonometric Functions

FunctionDescriptionExample
SINReturns the sine of xSIN(0)0
COSReturns the cosine of xCOS(0)1
TANReturns the tangent of xTAN(0)0
COTReturns the cotangent of xCOT(1)0.6420926159343306
ASINReturns the arc sine of xASIN(1)1.5707963267948966
ACOSReturns the arc cosine of xACOS(1)0
ATANReturns the arc tangent of xATAN(1)0.7853981633974483
ATAN2Returns the arc tangent of y/xATAN2(1, 1)0.7853981633974483
DEGREESConverts radians to degreesDEGREES(PI())180
RADIANSConverts degrees to radiansRADIANS(180)3.141592653589793
PIReturns the value of πPI()3.141592653589793

Other Numeric Functions

FunctionDescriptionExample
ABSReturns the absolute value of xABS(-5)5
SIGNReturns the sign of xSIGN(-5)-1
FACTORIALReturns the factorial of xFACTORIAL(5)120
RANDReturns a random number between 0 and 1RAND()0.123... (random)
RANDNReturns a random number from standard normal distributionRANDN()-0.123... (random)
CRC32Returns the CRC32 checksum of a stringCRC32('Databend')3899655467