Oracle-SQL 中没有时间值的日期是否始终为 00:00:00?
嘿嘿,
我需要从日期 A 00:00:00 和日期 B 00:00:00 执行的操作中获取一些数据(在本例中) 日期 A:2010 年 7 月 16 日 日期 B: 20.07.2010) 所以我写了这个选择语句:
Select avg(cnt),fext from (
Select
to_char(mytable.dateadded, 'DD.MM.YYYY') dateadded,
fext,
count(id) cnt
from mytable
where dateadded between
to_date('16.07.2010', 'dd,MM,YYYY') and
to_date('20.07.2010', 'dd,MM,YYYY')
group by
to_char(mytable.dateadded, 'DD.MM.YYYY'),
fext)
group by fext;
原始(和工作)语句有:
to_date('16.07.2010 00:00:00', 'dd,MM,YYYY HH24:Mi:SS') and
to_date('20.07.2010 00:00:00', 'dd,MM,YYYY HH24:Mi:SS')
所以问题是:是否
to_date('16.07.2010', 'dd,MM,YYYY') and
to_date('20.07.2010', 'dd,MM,YYYY')
已经将日期 A 和 B 的时间设置为 00:00:00?
格瑞兹
Heyho,
I need to grab some datas from actions which been done from date A 00:00:00 and date B 00:00:00 (in this case
Date A: 16.07.2010
Date B: 20.07.2010)
so i wrote this select-statement:
Select avg(cnt),fext from (
Select
to_char(mytable.dateadded, 'DD.MM.YYYY') dateadded,
fext,
count(id) cnt
from mytable
where dateadded between
to_date('16.07.2010', 'dd,MM,YYYY') and
to_date('20.07.2010', 'dd,MM,YYYY')
group by
to_char(mytable.dateadded, 'DD.MM.YYYY'),
fext)
group by fext;
The original (and working) statement had:
to_date('16.07.2010 00:00:00', 'dd,MM,YYYY HH24:Mi:SS') and
to_date('20.07.2010 00:00:00', 'dd,MM,YYYY HH24:Mi:SS')
so the question is: does the
to_date('16.07.2010', 'dd,MM,YYYY') and
to_date('20.07.2010', 'dd,MM,YYYY')
already set the time to date A and B to 00:00:00?
Greetz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您未指定日期的时间部分,则将为 00:00:00。
如果您担心时间部分,您总是可以截断时间部分:
If you does not specify time part of date it will be 00:00:00.
If you worry about time part you always can truncate time part:
最简单的方法是使用 ANSI 日期文字,它不允许指定时间,因此内部有 00:00:00 时间部分:
您的表达式看起来很奇怪,因为您的日期字符串以点作为时间分量分隔符,但你的日期格式有逗号。不过 Oracle 接受它:
为了简单起见,我会使用 ANSI 日期文字。
问候,
抢。
The easiest way is to use ANSI date literals, which doesn't allow time to be specified and is thus with a 00:00:00 time part internally:
Your expressions look odd, as your date string has dots as the time component separator, but your date format has commas. Oracle accepts it though:
I'd use the ANSI date literal for its simplicity.
Regards,
Rob.
此查询将返回您一行,它回答您的问题,我认为:
this query will returns you one row which answers your question i think :
这是 SQL 一致的一件事 - 如果您没有在包含时间部分的 DATE 数据类型上提供时间部分(IE Oracle、PostgreSQL,而 MySQL 和 SQL Server 明确称其为 DATETIME),则时间部分为默认为该日期的午夜 - 00:00:00。午夜意味着日期的开始 - 如果您想在日期比较中包含整个日期,则该值的时间部分需要为 23:49:49 - 午夜之前的一秒。
This is one thing that SQL is consistent about - if you don't provide a time portion on a DATE data type that includes a time portion (IE Oracle, PostgreSQL while MySQL and SQL Server explicitly call it DATETIME), then the time portion is defaulting to exactly midnight of that date - 00:00:00. And being midnight, that means the start of the date - if you want to include the entire date in a date comparison, the value's time portion needs to be 23:49:49 -- a second to midnight.
23:59:59 距离午夜还有一秒。本质上午夜定义为一天的开始:00:00:00。然后秒针一直计时到一天结束。
23:59:59 is a second to midnight. Essentially midnight is defined as the start of a day: 00:00:00. Then the seconds clock up to the end of the day.