oracle时间过滤
❶ oracle中从一张表中筛选出不再多个时间段内的时间
oracle中从一张表中筛选出不再多个时间段内的时间
建表和插入数据
create table table_a( t1 date, t2 date);
insert into table_a values(to_date('20140501','yyyymmdd') ,to_date('20140503','yyyymmdd'));
insert into table_a values(to_date('20140508','yyyymmdd') ,to_date('20140509','yyyymmdd'));
create table table_b(t date,id int)
insert into table_b values(to_date('20140501','yyyymmdd'),1);
insert into table_b values(to_date('20140502','yyyymmdd'),2);
insert into table_b values(to_date('20140503','yyyymmdd'),3);
insert into table_b values(to_date('20140504','yyyymmdd'),4);
insert into table_b values(to_date('20140505','yyyymmdd'),5);
insert into table_b values(to_date('20140506','yyyymmdd'),6);
insert into table_b values(to_date('20140507','yyyymmdd'),7);
insert into table_b values(to_date('20140508','yyyymmdd'),8);
insert into table_b values(to_date('20140509','yyyymmdd'),9);
insert into table_b values(to_date('20140510','yyyymmdd'),10);
insert into table_b values(to_date('20140511','yyyymmdd'),11);
查询语句
select * from table_b where t not in(
select distinct b.t from table_b b,table_a a where b.t between a.t1 and a.t2)
❷ oracle 筛选一个时间大于当前时间100个小时的语句
SELECT*FROMTabWHEREtab.date_xx>(SYSDATE-100/24);
❸ Oracle中按照时间范围以及时间间隔抽取数据的问题
这里TT是指定的时间间隔,单位:秒 下面语句可查出任意给定时间间隔的所有记录。
select * from tab
where CreateTime between to_date('2012-10-01 01:00:00','yyyy-mm-dd hh24:mi:ss') and
to_date('2012-10-01 12:00:00','yyyy-mm-dd hh24:mi:ss') and
CreateTime in (select to_date('2012-10-01 01:00:00','yyyy-mm-dd hh24:mi:ss')
+TT*rownum/24/60/60 from al
CONNECT BY rownum<=
(to_date('2012-10-01 12:00:00','yyyy-mm-dd hh24:mi:ss')-
to_date('2012-10-01 01:00:00','yyyy-mm-dd hh24:mi:ss'))*24*60*60/TT);
在上面的语句中,下列部分是构造时间间隔的所有可能存在的记录。每TT秒一条记录。
(select to_date('2012-10-01 01:00:00','yyyy-mm-dd hh24:mi:ss') +TT*rownum/24/60/60
from al CONNECT BY rownum<=
(to_date('2012-10-01 12:00:00','yyyy-mm-dd hh24:mi:ss')-
to_date('2012-10-01 01:00:00','yyyy-mm-dd hh24:mi:ss'))*24*60*60/TT)
不知道我理解的对不对,仅供参考。
❹ oracle中表中含有的日期字段如何作为筛选条件
日期需要进行格式匹配之后才能进行条件处理。
date 函数 和 to_date 两个函数。
❺ Oracle过滤掉无用的日期数据问题
日期强烈不建议使用字符串。。。。。
写存储过程可以搞搞
❻ Oracle数据库中对时间类型字段的检索
主要你也没说根据什么条件来查
先随便给你写个
select*fromAwhere时间起in(select时间起fromAwhere主键=1)
❼ oracle中如何筛选时间每天晚上9点之後
select * from test1 where substr9to_char(gxsj,'YYYY-MM-DD hh24:mi:ss'),12,2) > '21';
21是指晚上九点
❽ Oracle Sql 查询按时分过滤时间区段
SQL>CREATETABLET(KSSJDATE,JSSJDATE);
表已创建。
SQL>INSERTINTOTVALUES(to_date('09:30','HH24:MI'),to_date('11:30','HH24:MI'));
已创建1行。
SQL>COMMIT;
提交完成。
SQL>SELECTTO_CHAR(KSSJ+((ROWNUM-1)/48),'HH24:MI')KSSJ,TO_CHAR(KSSJ+(ROWNUM/48),'HH24:MI')JSSJ
2FROMTCONNECTBYROWNUM<=4;
KSSJJSSJ
----------
09:3010:00
10:0010:30
10:3011:00
11:0011:30
是你说回的意思答不?
❾ Oracle SQL 表中时间筛选的问题,求大神
第一种:直接用语句
date1与date2是字符串
SQL.Tet:='select * from table where 字段 between '+Quotedstr(date1)+' and '+Quotedstr(date2);
date1与date2是日期专
SQL.Tet:='select * from table where 字段 between '+Quotedstr(DateTimeToStr(date1))+' and '+Quotedstr(DateTimeToStr(date2));
第二属种:用参数形式:
SQL.Tet:='select * from table where 字段 between :d1 and :d2';
Parameters.ParamByName('d1').Value:=date1;
Parameters.ParamByName('d2').Value:=date2;
❿ oracle去除不合法日期
2个办法:
1. 用游标,逐行进行to_date(datecol,'yyyymmdd'),如果出现exception,则日期格式错误。
2. 自己写一个函数,输入专日期字符串,输出1/0
判断此格属式的字符串是否是正确的日期,函数中可以:
a. 用to_date(datecol,'yyyymmdd'),如果出现exception,则日期格式错误,返回0;否则返回1。
或者
b. 自己进行日期的规则判断:1年有12个月,各个月有多少天(闰年的2月需要特别处理)
然后update或者delete
比如 delete from table where f_date_validate(datecol) = 0;