Oracle performs rounding, rounding up, and rounding down.
In Oracle, rounding, ceiling, and floor can be achieved using different functions. Here are some commonly used functions:
- Round up:
To round up, use the ROUND function. The ROUND function takes two parameters, the first being the number to be rounded, and the second being the number of decimal places to retain. If the second parameter is 0, it rounds up to the nearest integer.
Example:
SELECT ROUND(3.14159, 2) FROM dual; -- 输出结果为3.14
SELECT ROUND(3.14159, 0) FROM dual; -- 输出结果为3
- Round up:
Use the CEIL function to achieve rounding up. The CEIL function takes one parameter, which is the number to be rounded up.
Example:
SELECT CEIL(3.14159) FROM dual; -- 输出结果为4
- Round down:
To achieve rounding down, use the FLOOR function. The FLOOR function takes one parameter, which is the number to be rounded down.
Example:
SELECT FLOOR(3.14159) FROM dual; -- 输出结果为3
It should be noted that the parameters of these functions can be any numerical expression, including column names, constants, and expressions.