Oracle SQL语句实现数字四舍五入取整
程序员文章站
2022-05-01 18:51:12
取整(向下取整):
复制代码 代码如下:select floor(5.534) from dual;
select trunc(5.534) from dual;
上...
取整(向下取整):
复制代码 代码如下:
select floor(5.534) from dual;
select trunc(5.534) from dual;
select trunc(5.534) from dual;
上面两种用法都可以对数字5.534向下取整,结果为5.
如果要向上取整 ,得到结果为6,则应该用ceil
复制代码 代码如下:
select ceil(5.534) from dual;
四舍五入:
复制代码 代码如下:
select round(5.534) from dual;
select round(5.534,0) from dual;
select round(5.534,1) from dual;
select round(5.534,2) from dual;
select round(5.534,0) from dual;
select round(5.534,1) from dual;
select round(5.534,2) from dual;
结果分别为 6, 6, 5.5, 5.53
保留n位小数(不四舍五入):
复制代码 代码如下:
select trunc(5.534,0) from dual;
select trunc(5.534,1) from dual;
select trunc(5.534,2) from dual;
select trunc(5.534,1) from dual;
select trunc(5.534,2) from dual;
结果分别是 5,5.5,5.53,其中保留0位小数就相当于直接取整了。
数字格式化:
复制代码 代码如下:
select to_char(12345.123,'99999999.9999') from dual;
结果为12345.123
复制代码 代码如下:
select to_char(12345.123,'99999999.9900') from dual;
小数后第三第四为不足补0,结果为12345.1230
复制代码 代码如下:
select to_char(0.123,'99999999.9900') from dual;
select to_char(0.123,'99999990.9900') from dual;
select to_char(0.123,'99999990.9900') from dual;
结果分别为 .123, 0.123
以上就是的小编为大家整理的oracle中对数字常用的操作,需要的小伙伴可以参考一下。
上一篇: Oracle中判断字段是否为数字
下一篇: Oracle 如何创建和使用全文索引