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;
相关文档:
select * from sys.smon_scn_time;
--scn 与时间的对应关系
每隔5分钟,系统产生一次系统时间标记与scn的匹配并存入sys.smon_scn_time表。
select * from student as of scn 592258
就可以看到在这个检查点的表的历史情况。
然后我们恢复到这个检查点
insert into student select * from student a ......
收集的几条在oracle中通过connect by prior来实现递归查询
Start with...Connect By子句递归查询一般用于一个表维护树形结构的应用。
创建示例表:
CREATE TABLE TBL_TEST
(
ID NUMBER,
NAME VARCHAR2(100 BYTE),
PID NUMBER ......
介绍一下内联、左联、右联
一.先看一些最简单的例子
例子
Table A
aid adate
1 a1
2 a2
3 a3
TableB
bid bdate
1 b1
2 b2
4 b4
两个表a,b相连接,要取出id相同的字段
select * from a inner join b on a.aid = b.bid这是仅取出匹配的数据.
此时的取出的是:
1 a1 b1
2 a2 b2
那么left join 指:
select * ......
ROLLUP,是GROUP BY子句的一种扩展,可以为每个分组返回小计记录以及为所有分组返回总计记录。
CUBE,也是GROUP BY子句的一种扩展,可以返回每一个列组合的小计记录,同时在末尾加上总计记录。
在文章的最后附上了相关表和记录创建的脚本。
1、向ROLLUP传递一列
SQL> select division_id,sum(salary)
2  ......
1. ASCII
返回与指定的字符对应的十进制数;
SQL> select ascii(A) A,ascii(a) a,ascii(0) zero,ascii( ) space from dual;
A A ZERO SPACE
--------- --------- --------- ---------
65 97 48 32
2. CHR
给出整数,返回对应的字符;
SQL> select chr(54740) zhao,chr(65) chr65 from dual;
ZH ......