oracle中,有一个test表,表中有一date类型的date字段,如何根据条件查询date数据啊?



select * from test where date='2013-5-22' 这样为什么查不出来数据??
各位看一下,这样写为啥报错?tcrq是date型代码:

错误:

以下每一句效果都一样:

1、Select * from a where date between to_date('2018-1-1', 'yyyy-mm-dd') and to_date('2018-8-1','如搭yyyy-mm-dd')

2、Select * from a where date between to_date('2018/1/1', 'yyyy/mm/dd') and to_date('2018/8/1','yyyy/mm/dd')

3、Select * from a where date between to_date('2018-1-1', 'yyyy/mm/dd') and to_date('2018/8/1','yyyy-mm-dd'基团)

扩展资料

数据库中Date与DateTime的区别

Date:代表xxxx年xx月xx日 只表示前面的日期,是SQL Server 2008新引进的数据类型。它表示一个日子,不包含时间部分,可以表示的日期范围从公元元年1月1日到9999年12月31日,只需要3个字节的存储空间。

DateTime:代表xxxx年xx月xx日xx时xx分xx秒 精确到时分秒,用于做时间戳,日期和时间部分,可以表示的日期范围从公元1753年1月1日00:00:00.000 到9999年12月31日搏橡橘23:59:59.997 ,精确到3.33毫秒,它需要8个字节的存储空间。


select * from test where to_char(date,'yyyy-mm-dd')='橘拦旁2013-5-22'

oracle中的日期需要衡陪用圆橡to_char格式化一下
使用羡首trunc函数
select * from test where trunc(date)='2013-5-22'
date类睁派世型默认值是悉肢年月日时分秒的,不是年月日
字段名字是date? 最好腔敏历不好这伍搜样命名
select * from test where date=to_date('2013-5-22','yyyy-mm-dd'拿袭);
select * from test where date=to_date('2013-5-22','败嫌yyyy-mm-dd')

应该氏枯谈是这样歼碰