这四个函数有点类似java中的函数,首先是
trunc(number,[decimals]) 这个函数类似截取函数
number:表示你要输入的数
decimals(小数): 表示你要截取的位数【正数表示小数点向右保留多少位,负数向左依次置零且小数点右边的截断】
eg:

  • select trunc(35.34,1) from dual; result: 35.3
  • select trunc(35.34,3) from dual; result:35.34
  • select trunc(35.34,-1) from dual; result:30
  • select trunc(35.34,-2) from dual; result: 0;

trunc(data,[format]) --这个是针对于日期来说的
data: 是一个日期值
format: 这是一个日期格式

  • 1.select trunc(sysdate) from dual --2016-08-06 今天的日期为2016-08-06
  • 2.select trunc(sysdate, 'mm') from dual --2016-08-01 返回当月第一天.
  • 3.select trunc(sysdate,'yy') from dual --2016-08-01 返回当年第一天
  • 4.select trunc(sysdate,'dd') from dual --2016-08-06 返回当前年月日
  • 5.select trunc(sysdate,'yyyy') from dual --2016-08-01 返回当年第一天
  • 6.select trunc(sysdate,'d') from dual --2016-08-06 (星期天)返回当前星期的第一天
  • 7.select trunc(sysdate, 'hh') from dual --2016-08-06 17:00:00 当前时间为17:35
  • 8.select trunc(sysdate, 'mi') from dual --2016-08-06 17:35:00 TRUNC()函数没有秒的精确

round(number,[decimals]) 这个函数其实就是一个四舍五入函数
number: 要处理的数值
decimals: 四舍五入后,要保留几位

  • select round(123.346,0) from dual; result: 0
  • select round(123.346,2) from dual; result: 123.35
  • select round(-123.346,2) from dual; result: -123.35

ceil和floor函数
ceil(n) 取大于等于n的最小整数
floor(n) 取小于等于n的最大整数

eg:

  • select ceil(34.3) from dual; result: 35
  • select floor(34.3) from dual; result: 34

coalesce:

COALESCE (expression_1, expression_2, ...,expression_n)依次参考各参数表达式,遇到非null值即停止并返回该值。如果所有的表达式都是空值,最终将返回一个空值。

使用COALESCE在于大部分包含空值的表达式最终将返回空值。

eg:

    SELECT COALESCE(NULL,NULL,3,4,5) FROM dual  result: 3

oracle中的turnc,round,floor,ceil,coalesce函数的更多相关文章

  1. Oracle中的NVL,NVL2,NULLIF以及COALESCE函数使用

    首先注意空(null)值,空值加任何值都是空值,空值乘任何值也都是空值,依此类推. 1.NVL函数 NVL函数的格式如下:NVL(expr1,expr2) 含义是:如果oracle第一个参数为空那么显 ...

  2. SQL 中详解round(),floor(),ceiling()函数的用法和区别?

    SQL 中详解round(),floor(),ceiling()函数的用法和区别? 原创 2013年06月09日 14:00:21   摘自:http://blog.csdn.net/yueliang ...

  3. MATLAB中取整函数(fix, floor, ceil, round)的使用

    MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3    -3(2)floor(x):不超过x 的最大整数.(高斯取整) & ...

  4. paper 68 :MATLAB中取整函数(fix, floor, ceil, round)的使用

    MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans =      3    -3 (2)floor(x):不超过x 的最大整数.(高 ...

  5. C++中的 Round(),floor(),ceil()

     2.1             2.6               -2.1               -2.6floor : 不大于自变量的最大整数             2          ...

  6. Matlab中的取整-floor,ceil,fix,round

    FLOOR Round towards minus infinity. FLOOR(X) rounds the elements of X to the nearest integers toward ...

  7. sql中详解round(),floor(),ceiling()函数的用法和区别?

    round() 遵循四舍五入把原值转化为指定小数位数,如:round(1.45,0) = 1;round(1.55,0)=2floor()向下舍入为指定小数位数 如:floor(1.45,0)= 1; ...

  8. 【Matlab】取整函数:fix/round/floor/ceil

    fix-向零方向取整.(向中间取整) round-向最近的方向取整.(四舍五入) floor-向负无穷大方向取整.(向下取整) ceil-向正无穷大方向取整.(向上取整)

  9. Oracle中与日期时间有关的运算函数

    1            ADD_MONTHS 格式:ADD_MONTHS(D,N) 说明:返回日期时间D加N月后对应的日期时间.N为正时则表示D之后:N为负时则表示为D之前:N为小数则会自动先删除小 ...

随机推荐

  1. [妙味DOM]第一课:DOM基础概念、操作

    知识点总结 childNodes.children子节点列表集合.nodeType节点类型.nodeName.nodeValue.attributes属性列表集合 childNodes和childre ...

  2. PHP截取中文字符串方法总结

    <?php @header('Content-type: text/html; charset=UTF-8'); $arr = "sa撒的发dfa多少sfd看sdf得12上24飞452 ...

  3. putty 中使用git

    提交git pwd 查看当前目录 进入目录cd /home/gongfu/tripb/master 修改代码目录 git status 查看 修改的文件(新增的,删除的) git commit -m ...

  4. json_encode转成带 花括号的{ } 和 中括号的[ ] 2种 形式 json数据

    //提交多个出差人员 .命名为数组 name="apply_members[] " //php接收到数据 为 数组  $aa = array('0'=>11,'1'=> ...

  5. HTML中的<audio>和<video>标签讲解

    关于<audio>标签讲解:点击这里 这里来一段简单的html5的音频代码: <audio src="someaudio.wav"> 您的浏览器不支持 au ...

  6. openwrt拦截snmp报文

    SNMP使用的协议为UDP,默认端口为161和162. 使用iptables 命令如下: iptables -A INPUT -p udp -m udp --dport 161:162 -j DROP ...

  7. HDU 1264 Counting Squares(模拟)

    题目链接 Problem Description Your input is a series of rectangles, one per line. Each rectangle is speci ...

  8. AFNetWoring导入报错解决方案

    第一个当报cannot find interface declaration for 'UIImage或者use of undeclared identifier 'UIImage'时我们要在报错页面 ...

  9. 常用 ajax js 表单

    $(function () { /** * 图片点击放大处理 */ $('.mini_img').click(function () { $(this).hide().next().show(); } ...

  10. 《Windows驱动开发技术详解》之Windows内核函数

    内核模式下字符串操作 ANSI_STRING和UNICODE_STRING分别定义如下: