oracle 时间差
//计算毫秒差(两个date类型的相减为天数差别,然后转换为毫秒)
select ceil(to_date('209-11-17 13:00:12','yyyy-mm-dd hh24:mi-ss')-to_date(2009-11-18 14:00:12','yyyy-mm-dd hh24:mi-ss') )from dual;
//计算相差月份
select (EXTRACT(year from to_date('209-11-17','yyyy-mm-dd'))-EXTRACT(year from to_date('2009-11-18','yyyy-mm-dd') ))*12+(EXTRACT(month from to_date('209-11-17','yyyy-mm-dd'))-EXTRACT(month from to_date('2009-11-18','yyyy-mm-dd') )) from dual;
//通过时间戳运算
select to_timestamp('2009-11-17 19:20:12 234','yyyy-mm-dd hh24:mi:ss ff')-to_timestamp('2009-11-16 11:12:34 167','yyyy-mm-dd hh24:mi:ss ff') from dual;
返回值为+000000010 00:02:24.00000000 字符串要转换为毫秒数字,自定义函数实现
//自定义用时间戳运算函数
create or replace function TIME_INTERVAL(endTime varchar2,startTime varchar2)
return number
IS
p_1 varchar2(40);
begin
p_1 := to_timestamp(endTime,'yyyy-mm-dd hh24:mi:ss ff')-to_timestamp(startTime,'yyyy-mm-dd hh24:mi:ss ff');
return trunc(to_number(substr((p_1),1,instr(p_1,' '))))*24*60*60+to_number(substr((p_1),instr((p_1),' ')+1,2))*60*60+to_number(substr((p_1),instr((p_1),' ')+4,2))*60+to_number(substr((p_1),instr((p_1),' ')+7,2));
end;
相关文档:
GROUPING函数可以接受一列,返回0或者1。如果列值为空,那么GROUPING()返回1;如果列值非空,那么返回0。GROUPING只能在使用ROLLUP或CUBE的查询中使用。当需要在返回空值的地方显示某个值时,GROUPING()就非常有用。
关于ROLLUP和CUBE函数的使用,请参见我的另一篇文章。
http://blog.csdn.net/wh62592855/archive/2009/1 ......
可以使用GROUPING_ID函数借助HAVING子句对记录进行过滤,将不包含小计或者总计的记录除去。GROUPING_ID()函数可以接受一列或多列,返回GROUPING位向量的十进制值。GROUPING位向量的计算方法是将按照顺序对每一列调用GROUPING函数的结果组合起来。
关于GROUPING函数的使用方法可以参见我前面写的一篇文章
http://blog.csdn ......
1.数学函数
①绝对值
l S:select abs(-1) value
l O:select abs(-1) value from dual
②取整(大)
l S:select ceiling(-001) value
l O:select ceil(-001) value from dual
③取整(小)
l S:select floor(-001) value  ......
1. ASCII: 返回与指定的字符对应的十进制数;
SQL> select ascii('A') A,ascii('a') a,ascii(0) zero,ascii('') space from dual;
A A ZERO SPACE
--------- --------- --------- ---------
65 97 48
2. CHR:给出整数,返回对应的字符;
SQ ......