
假设要查询2011-05-02到2011-05-30之间的数据,实现方式如下:
to_date方式:
select
*
from
tablename
where
time>=to_date('2011-05-02','yyyy-mm-dd')
and
time
<=
to_date('2011-05-30','yyyy-mm-dd')
运行的结果是:可以显示05-02的数据,但是不能显示05-30的数据。
运行的结果是:可以显示05-02的数据,但是不能显示05-30的数据。
所有可以得出结论:
①如果想显示05-30的数据可以to_date('2011-05-31','yyyy-mm-dd'),这样就能显示30号的了。
②如果想要显示05-30的数据可以to_date('2011-05-30
23:59:59
999','yyyy-mm-dd
hh24:mi:ss')也是可以查出来的。
to_char方式:
同样查询上面两个日期
select
*
from
tablename
where
to_char(time,'yyyy-mm-dd')>=2011-05-02
and
to_char(time,'yyyy-mm-dd')<=2011-05-3
查询结果:可以同时显示05-02和05-30的数据。
另外:可以用between
and
代替
>=符号
假设是数组形式如:需要查1,2,3,4,5,6的数据就用in :select * from table where num in(1,2,3,4,5,6)如果需要查询范围内的,如:查询1-6范围内的可以:
select * from table where num >1
and num <6
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)