七、Oracle学习笔记:数值函数

(1)函数:四舍五入函数

--格式:
  round(p,n):对p四舍五入,n表示保留多少位小数,n不写,默认为零,n可以为负数   
--练习:对数字3.14进行四舍五入
  select round(3.14) as 四舍五入 from dual;
--练习:对数字0.648四舍五入保留两位小数
  select round(0.648,2) as 四舍五入 from dual;
--练习:对数字6478四舍五入保留到百位
  select round(6478,-2) as 四舍五入 from dual;

(2)函数:数字截取函数

--格式:
  trunc(p,n):对p进行截取,保留小数点后n位,n不写,默认为零,n可以为负数
--练习:对数字3.14进行截取,仅保留一位小数
  select trunc(3.14,1) as 截取 from dual;

(3)函数:取余数函数

--格式:mod(m,n):表示m对n做除法取余数
--练习:计算100对3取余
  select mod(100,3) from dual;

(4)函数:向上\向下取整

--格式:ceil(m)对m进行向上取整
--格式:floor(m)对m进行向下取整
--练习:对99.99向上取整,向下取整
  select ceil(99.99),floor(99.99) from dual;

猜你喜欢

转载自blog.csdn.net/qq_38741971/article/details/81411640