oracle中的turnc,round,floor,ceil,coalesce函数
这四个函数有点类似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函数的更多相关文章
- Oracle中的NVL,NVL2,NULLIF以及COALESCE函数使用
首先注意空(null)值,空值加任何值都是空值,空值乘任何值也都是空值,依此类推. 1.NVL函数 NVL函数的格式如下:NVL(expr1,expr2) 含义是:如果oracle第一个参数为空那么显 ...
- SQL 中详解round(),floor(),ceiling()函数的用法和区别?
SQL 中详解round(),floor(),ceiling()函数的用法和区别? 原创 2013年06月09日 14:00:21 摘自:http://blog.csdn.net/yueliang ...
- MATLAB中取整函数(fix, floor, ceil, round)的使用
MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3 -3(2)floor(x):不超过x 的最大整数.(高斯取整) & ...
- paper 68 :MATLAB中取整函数(fix, floor, ceil, round)的使用
MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3 -3 (2)floor(x):不超过x 的最大整数.(高 ...
- C++中的 Round(),floor(),ceil()
2.1 2.6 -2.1 -2.6floor : 不大于自变量的最大整数 2 ...
- Matlab中的取整-floor,ceil,fix,round
FLOOR Round towards minus infinity. FLOOR(X) rounds the elements of X to the nearest integers toward ...
- sql中详解round(),floor(),ceiling()函数的用法和区别?
round() 遵循四舍五入把原值转化为指定小数位数,如:round(1.45,0) = 1;round(1.55,0)=2floor()向下舍入为指定小数位数 如:floor(1.45,0)= 1; ...
- 【Matlab】取整函数:fix/round/floor/ceil
fix-向零方向取整.(向中间取整) round-向最近的方向取整.(四舍五入) floor-向负无穷大方向取整.(向下取整) ceil-向正无穷大方向取整.(向上取整)
- Oracle中与日期时间有关的运算函数
1 ADD_MONTHS 格式:ADD_MONTHS(D,N) 说明:返回日期时间D加N月后对应的日期时间.N为正时则表示D之后:N为负时则表示为D之前:N为小数则会自动先删除小 ...
随机推荐
- UITableView简单使用
在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似于微信.QQ.新浪微博等软件基本上随处都是UITableView.当然它的广泛使用自然离不 ...
- css ::before和::after伪元素的用法
css ::before和::after伪元素的用法:http://blog.dimpurr.com/css-before-after/
- sql新建数据库表,及添加多个主键
create table tb_Modules(module_Id int identity(1,1) primary key, (自增)model_Name varchar(50) not nul ...
- uhttpd配置文件分析
文件位于 /etc/config/uhttpd. root@hbg:/etc/config# cat uhttpd config uhttpd 'main' list listen_ht ...
- Java中需要总结的几个问题
慢慢总结,不然每次百度挺心烦的. 1. java文件的读写 2. String和StringBuffer的区别
- poj 1142 Smith Numbers
Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh U ...
- css3的特效拓展...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- sql优化原则
尽量使用性能高的比如left join等,尽量减少数据查询的column,尽量不要查询冗余数据,like的话“%%”是没有 办法使用索引的,但是“%”是可以使用索引的 having以前一直不知道到底真 ...
- iOS自定义转场动画的实现
iOS中熟悉的是导航栏中的push和pop这两种动画效果,在这里我们可以自己实现自己想要的一些转场动画 下面是我自己创建转场动画的过程 1.新建一个文件继承自NSObject ,遵循协议UIViewC ...
- javacript没有多维数组只能模拟?
为什么说javacript没有多维数组只能模拟?但是我看到是可以实现多维数组的啊!这是为什么呢?下面我们来实验下. <!DOCTYPE html> <html lang=" ...