分享

ORACLE中sql语句常用的函数

 昵称8474447 2012-01-04
--向下取整
select floor(5.534) from dual          结果:5
union all
select trunc(5.534) from dual;        结果:5
------------------------------------------------------------------------------------------------------------

--向上取整
select ceil(5.534) from dual;          结果:6
------------------------------------------------------------------------------------------------------------
 
--四舍五入
select round(5.534) from dual     --四舍五入                                  结果:6
union all
select round(5.534,-1) from dual  --四舍五入取整数十位值        结果:10
union all
select round(5.534,0) from dual   --四舍五入取整数                     结果:6
union all
select round(5.534,1) from dual   --四舍五入取小数位为1位      结果:5.5
union all
select round(5.534,2) from dual   --四舍五入取小数位为2位      结果:5.53
union all
select round(5.534,3) from dual   --四舍五入取小数位为3位      结果:5.534
union all
select round(5.534,4) from dual   --四舍五入取小数位为4位,如果位数多余,还取原值     结果:5.534
------------------------------------------------------------------------------------------------------------

--保留N位小数,不四舍五入
select trunc(5.534,0) from dual  --取整数                     结果:5
union all
select trunc(5.534,1) from dual  --取小数位为1位        结果:5.5
union all
select trunc(5.534,2) from dual  --取小数位为2位        结果:5.53
union all
select trunc(5.534,3) from dual  --取小数位为3位        结果:5.534
union all
select trunc(5.534,4) from dual  --取小数位为4位,如果位数多余,还取原值        结果:5.534
------------------------------------------------------------------------------------------------------------
--数字格式化  to_char
--不足补零。
select to_char(12345.123,'99999999.9999') from dual        结果:12345.1230
union all
select to_char(12345.123,'99999999.9900') from dual        结果:12345.1230
union all
select to_char(0.123,'99999999.9900') from dual                 结果:.1230
union all
select to_char(0.123,'99999990.9999') from dual                 结果:0.1230

 

 

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多