Welcome 微信登录

首页 / 数据库 / MySQL / Oracle中关于处理小数点位数的几个函数

关于处理小数点位数的几个Oracle函数()
1. 取四舍五入的几位小数
select round(1.2345, 3) from dual;
结果:1.235
2. 保留两位小数,只舍
select trunc(1.2345, 2) from dual;
结果:1.23select trunc(1.2399, 2) from dual;
结果:1.23
3.取整数
返回大于或等于x的最大整数: 
        SQL>         select         ceil(23.33)         from         dual; 
结果:   24  返回等于或小于x的最大整数: 
        SQL>         select         floor(23.33)         from         dual; 
结果:   23 
  
返回舍入到小数点右边y位的x值:rcund(x,[y]) 
        SQL>         select         round(23.33)         from         dual; 
结果:    23 
  
返回截尾到y位小数的x值:trunc(x,[y]) 
        SQL>         select         trunc(23.33)         from         dual; 
结果:   23 
格式化数字 The following are number examples for the to_char function.
to_char(1210.73, "9999.9") would return "1210.7"
to_char(1210.73, "9,999.99") would return "1,210.73"
to_char(1210.73, "$9,999.00") would return "$1,210.73"
to_char(21, "000099") would return "000021"
to_char函数特殊用法
to_char(sysdate,"d") 每周第几天
to_char(sysdate,"dd") 每月第几天
to_char(sysdate,"ddd") 每年第几天
to_char(sysdate,"ww") 每年第几周
to_char(sysdate,"mm") 每年第几月
to_char(sysdate,"q") 每年第几季
to_char(sysdate,"yyyy") 年
比如要找某个时间为每周第几天就可以
SQL> select to_char(to_date("20070101","yyyymmdd"),"d") from dual;Oracle 入门之控制文件multiplexOracle 入门之EM配置相关资讯      oracle 
  • [INS-32052] Oracle基目录和Oracle  (07/22/2014 07:41:41)
  • Oracle 4个大对象(lobs)数据类型  (02/03/2013 12:33:05)
  • Oracle按时间段分组统计  (07/26/2012 10:36:48)
  • [Oracle] dbms_metadata.get_ddl的  (07/12/2013 07:37:30)
  • Liferay Portal 配置使用Oracle和  (07/31/2012 20:07:18)
  • Concurrent Request:Inactive   (07/20/2012 07:44:05)
本文评论 查看全部评论 (0)
表情: 姓名: 字数