1、oracle时间类型的使用
--时间类型的使用
select * from bureau_info where bur_end_date > to_date('2011-09-30','yyyy-mm-dd');
--获取当前时间
select to_char(sysdate,'yyyy') from dual;
select sysdate from files; --files是用户创建的任意一张表=,表中不包含sysdate字段
--计算两时间差精确到天
select to_date(bur_end_date)-to_date(bur_begin_date) from bureau_info where rownum = 1;
--得到当前时间是当前年的那一个星期
select to_char(sysdate,'WW') from dual
--取本周第一天喝最后一天的两种写法
select count(*) from bureau_info where to_char(update_date,'yyyy') = to_char(sysdate,'yyyy') and
to_char(update_date,'ww') = to_char(sysdate+1,'WW')
select count(*) from bureau_info where update_date between trunc(sysdate,'day')+1 and trunc(sysdate,'day') + 8;
--得到当前月份的第一天和最后一天
select to_char(sysdate,'yyyy/mm')||'/01' firstday, to_char(last_day(sysdate),'yyyy/mm/dd') lastday from dual
--时间约束
create table c (
sss date,
constraint ck_sss check(sss >to_date('2011-09-30','yyyy-mm-dd') and sss < to_date('2012-09-30','yyyy-mm-dd'))
)
--oracle常用数据类型
2、自定义排序,bur_state为列名;启动'。。。。为列的值
order by DECODE(bur_state, '启动',1,'结束',2,'中止',3,'跟踪',4,'准备',5)
3、sql语句中时间字段查询,在字段上不用函数,而是在字符串上用函数
oracle,时间类型不用函数的比较:
alarmtime between to_date(dqksTime, 'YYYYMMDDHH24mi') and to_date(dqjsTime, 'YYYYMMDDHH24mi')
oracle,时间比较中时间的计算:
alarmtime between to_date(dqksTime, 'YYYYMMDDHH24mi') - 2 and to_date(dqksTime, 'YYYYMMDDHH24mi')
说明:alarmtime 表字段中时间类型的字段