查询1
select *
from a
where to_date('2012-3-31 13:00:01',
'yyyy-mm-dd hh24:mi:ss') between start_date and end_date如果用这句查询就不能查询出数据
查询2
select *
from a
where to_date('2012-3-31',
'yyyy-mm-dd hh24:mi:ss') between start_date and end_date
如果去掉时分秒,就能查询出数据。
这是为什么呢?
start_date 和end_date字段都是DATE类型我自己做了个测试declare
v_date date;
begin
select to_date('2011-3-31 13:00:01', 'yyyy-mm-dd hh24:mi:ss')
into v_date
from dual;
if v_date > to_date('2011-3-31', 'yyyy-mm-dd') then
dbms_output.put_line('1');
else
dbms_output.put_line('2');
end if;
exception
when others then
dbms_output.put_line('3');
end;最后返回了 1 ,说明带时分秒的是可以和不带时分秒的比较的啊。。
我有点迷茫了。。
那位大神告诉我下原因。。
select *
from a
where to_date('2012-3-31 13:00:01',
'yyyy-mm-dd hh24:mi:ss') between start_date and end_date如果用这句查询就不能查询出数据
查询2
select *
from a
where to_date('2012-3-31',
'yyyy-mm-dd hh24:mi:ss') between start_date and end_date
如果去掉时分秒,就能查询出数据。
这是为什么呢?
start_date 和end_date字段都是DATE类型我自己做了个测试declare
v_date date;
begin
select to_date('2011-3-31 13:00:01', 'yyyy-mm-dd hh24:mi:ss')
into v_date
from dual;
if v_date > to_date('2011-3-31', 'yyyy-mm-dd') then
dbms_output.put_line('1');
else
dbms_output.put_line('2');
end if;
exception
when others then
dbms_output.put_line('3');
end;最后返回了 1 ,说明带时分秒的是可以和不带时分秒的比较的啊。。
我有点迷茫了。。
那位大神告诉我下原因。。
解决方案 »
- 想请教大家一个问题: 现在数据库有两万条记录,有两个字段, 其中“流水号”字段 值唯一 、 “结果”字段 数值。 现在,我想用SQL语句,第一次随机选择某些
- 如何把oracle中导出的.sql文件利用sqlplus导入
- windows2003下安装oracle8i到配置工具net8 configuration Assistant配置时过不去
- 在线等 菜鸟测试存储过程 附值
- ORACLE “TNS:无法处理服务名!”
- normal与sysdba权限访问数据库
- 特急!高分求助!帮忙解题!
- 在oracle10g的pro*c/c++中从c变为c++时的错误
- 请问least() 及NUL()涵数怎用 ?
- Oracle817初级问题?多谢,一直在线!
- 一个数据库查询语句的疑问
- oracle数据库访问权限可以限制到某些机器吗?
你的查询没数据出来,应该是表字段里对时间进行了截取,enddate只到'2011-3-31 00:00:00'吧
没有指定时分秒的话相当于时分秒是0例如to_date('2012-3-31',
'yyyy-mm-dd hh24:mi:ss')等同于to_date('2012-3-31 00:00:00',
'yyyy-mm-dd hh24:mi:ss')