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;
相关文档:
1. 选用适合的Oracle优化器
Oracle的优化器共有3种:
a. RULE (基于规则)
b. COST (基于成本)
c. CHOOSE (选择性)
设置缺省的优化器,可以通过对init.ora文件中OPTIMIZER_MODE参数的各种声明,如RULE,COST,CHOOSE,ALL_ROWS,FIRST_ROWS . 你当然也在SQL句级或是会话(session)级对其进行覆盖。 ......
2.根据Oracle 数据库scott 模式下的emp 表和dept 表,完成下列操作:
(1) 查询20号部门的所有员工信息;
(2) 查询所有工种为CLERK 的员工的员工号、员工名和部门号;
(3) 查询奖金COMM 高于工资SAL 的员工信息;
  ......
介绍一下内联、左联、右联
一.先看一些最简单的例子
例子
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 * ......
表1:temp1
AA BB CC
1 1 1
1 1 2
1 1 3
表2:temp2
AA BB ......
索引( Index )是常见的数据库对象,它的设置好坏、使用是否得当,极大地影响数据库应用程序和Database 的性能。虽然有许多资料讲索引的用法, DBA 和 Developer 们也经常与它打交道,但笔者发现, ......