当前位置: 代码迷 >> Oracle管理 >> Oracle数据库用PLSQL怎么使用between and 查询
  详细解决方案

Oracle数据库用PLSQL怎么使用between and 查询

热度:468   发布时间:2016-04-24 05:37:18.0
Oracle数据库用PLSQL如何使用between and 查询
Oracle数据库用PLSQL如何使用between and 查询 我的表中的时间格式是 2009-11-2 8:47:14 这样的,请教,如何使用between and 这个时间段 ,如:select * from table where dj_date between ‘2009-11-1 8:47:14’ and '2009-12-1 8:47:14' 对否,请指教,麻烦给出正确写法

------解决方案--------------------
SQL code
select * from table where dj_date between to_date('2009-11-1 8:47:14','yyyy-mm-dd hh24:mi:ss') and to_date('2009-12-1 8:47:14','yyyy-mm-dd hh24:mi:ss')
------解决方案--------------------
楼上正解,无需多言,顶下。
------解决方案--------------------

参考 1#
------解决方案--------------------
oracle 日期范围查询问题 


select * from aaa where to_char(rq,'yyyymmdd') between '20011101' and '20020301';


直接在rq上加函数,如果应用大(这个表内数据很多时),查询速度会相当慢的,为了提高查询速度,强烈建议这样书写:
select * from aaa where rq between to_date('2001-11-01','yyyy-MM-DD') and to_date('2002-03-01' ,'YYYY-MM-DD');


推荐使用
select * from aaa where rq>;=to_date('2001-11-01','yyyy-MM-DD') and rq<=to_date('2002-03-01' ,'YYYY-MM-DD');

用between的函数可能会慢些
------解决方案--------------------
1楼正解,呵呵,学习了。
------解决方案--------------------
探讨
SQL codeselect*fromtablewhere dj_datebetween to_date('2009-11-1 8:47:14','yyyy-mm-dd hh24:mi:ss')and to_date('2009-12-1 8:47:14','yyyy-mm-dd hh24:mi:ss')

------解决方案--------------------
如果你表中的日期字段用的是varchar2型就用to_date(date,'yyyy-mm-dd hh24:mi:ss)转换一下后再,between and
  相关解决方案