oracle 如何查询一个时间段的数据?有没有计算时间+天数的的函数?
查询表中出生日期为最近一个星期的(向后推算)?那位大侠肯帮忙,定将高分送上. 问题点数:20、回复次数:9Top
1 楼boydgmx(授人以鱼不如授人以渔(baidu&google))回复于 2006-02-28 17:45:18 得分 0
select * from tt where csrq between trunc(sysdate) and trunc(sysdate+8)-1/(24*3600);Top
2 楼hezhudaozhai(九袋长老)回复于 2006-02-28 22:04:54 得分 0
其他办法想不出来 只有苯办法 测试通过
create table t_birthday (t_name varchar2(20) not null,t_birthday date);
select * from t_birthday
where trunc(sysdate)-to_date(substr(to_char(t_birthday,'yyyy-mm-dd'),6,2)||'-'||substr(to_char(t_birthday,'yyyy-mm-dd'),9,2)||'-'||to_char(sysdate,'yyyy'),'mm-dd-yyyy') between 0 and 6
最近一个星期 应该向前推一个星期 如 今天是2006-02-28 最近的一个星期应该从2006-02-22算起Top
3 楼wffffc(飞)回复于 2006-02-28 23:48:41 得分 0
select * from tablename where birthdate > sysdate-7;
Top
4 楼hgy82()回复于 2006-03-01 09:52:23 得分 0
最近一个星期 是要求向后推一个星期 如 今天是2006-02-22 其推算日期为2006-02-29
我的数据库为oracle 9i
问hezhudaozhai(九袋长老) :老兄,你的这个sql报 a non-numeric character was found where a numeric was expected 错.是什么问题了,语法不对还是少了什么参数?
问boydgmx(授人以鱼不如授人以渔(baidu&google)) :大侠,您好,能解释一下这个sql吗
“select * from tt where csrq between trunc(sysdate) and trunc(sysdate+8)-1/(24*3600);”
在此,先谢谢大家.
Top
5 楼hgy82()回复于 2006-03-01 10:14:57 得分 0
有重要的一点:就是是生日为最近一个星期的!所以这个日期应该怎么样来比较?Top
6 楼xiaoxiao1984(笨猫儿)回复于 2006-03-01 11:03:23 得分 0
当前 sysdate 为 2006-3-1 往后推一周 2006-3-8,生日在2006-3-2至2006-3-8之间的数据
select * from test where birthday >= trunc(sysdate+1) and birthday < trunc(sysdate+8)
trunc(sysdate+1) 表示 2006-3-2 00:00:00Top
7 楼wffffc(飞)回复于 2006-03-01 14:21:50 得分 0
select * from tablename where birthdate > sysdate-7;
这样不行吗?Top
8 楼hezhudaozhai(九袋长老)回复于 2006-03-01 22:43:41 得分 20
SQL> select * from t_birthday;
T_NAME T_BIRTHDAY
-------------------- ----------
DUDU 17-9月 -80
panpan 13-2月 -81
shasha 14-11月-82
mimi 20-2月 -82
xx 21-2月 -83
ss 03-3月 -83
ss 22-2月 -83
ss 23-2月 -83
ss 24-2月 -66
a 02-3月 -99
b 08-3月 -00
T_NAME T_BIRTHDAY
-------------------- ----------
c 09-3月 -61
已选择12行。
SQL> select sysdate from dual;
SYSDATE
----------
01-3月 -06
SQL> select * from t_birthday
2 where trunc(sysdate)-to_date(to_char(t_birthday,'mm-dd')||'-'||to_char(sysdate,'yyyy'),'mm-dd-yyyy') between -7 and -1
3 ;
T_NAME T_BIRTHDAY
-------------------- ----------
ss 03-3月 -83
a 02-3月 -99
b 08-3月 -00Top
9 楼hgy82()回复于 2006-04-18 17:29:33 得分 0
谢谢各位Top




