[英]DateTime on Where Clause Oracle
it seems there are lot of query syntax to fetch data on oracle database, here I just want to ask about the query that works fine but I cant understand at all. 似乎有很多查询语法可以在oracle数据库上获取数据,在这里我只想问一下可以正常工作的查询,但我根本无法理解。 The query is :
查询是:
Select
....
From
...
Where
TO_CHAR(TO_DATE('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS') +
(create_date / ( 60 * 60 * 24 )),
'MM/DD/YY HH24:MI:SS') = '06/30/14 21:41:11'
;
From the query above it's work fine. 从上面的查询可以正常工作。 But I cant understand why there's TO_DATE('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS and (create_date / ( 60 * 60 * 24 )), 'MM/DD/YY HH24:MI:SS')
但是我不明白为什么会有TO_DATE('01 / 01/1970 00:00:00','MM / DD / YYYY HH24:MI:SS和(create_date /(60 * 60 * 24)),'MM / DD / YY HH24:MI:SS')
on the create_date fields it show unix datetime such as 1404164471 在create_date字段上,它显示UNIX日期时间,例如1404164471
Can anybody explain about this? 有人可以解释一下吗?
thanks in advance 提前致谢
TO_DATE('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
converts a string (first argument) in certain format (second argument) to a date. TO_DATE('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
将某种格式的字符串(第一个参数)(第二个参数)转换为日期。
(create_date / ( 60 * 60 * 24 ))
create_date contains seconds, this expression converts them into the number of days (1 minute = 60 seconds, 1 hour = 60 minutes, 1 day = 24 hours => 60*60*24 = the number of seconds in a day). (create_date / ( 60 * 60 * 24 ))
create_date包含秒,此表达式将它们转换为天数(1分钟= 60秒,1小时= 60分钟,1天= 24小时=> 60 * 60 * 24 =一天中的秒数)。 When you add a number to a date Oracle thinks that this number contains days that's why you need such a conversation. 当您在日期中添加数字时,Oracle认为该数字包含几天,因此您需要进行此类对话。
TO_DATE('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS') + (create_date / ( 60 * 60 * 24 ))
gives you a date stored in create_date but in "traditional" format TO_DATE('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS') + (create_date / ( 60 * 60 * 24 ))
为您提供一个存储在create_date但位于“传统”格式
It seems you need to compare unix time with date. 看来您需要将Unix时间与日期进行比较。 It would be better to use this condition:
最好使用以下条件:
Select
....
From
...
Where create_date = trunc( (TO_DATE('06/30/14 21:41:11', 'MM/DD/YY HH24:MI:SS')
- TO_DATE('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
) * 24 * 60 * 60
);
The outer to_char(,) creates a string from the calculated date. 外部to_char(,)从计算出的日期创建一个字符串。 This is so that it can be compared with the string '06/30/14 21:41:11'.
这样可以将其与字符串“ 06/30/14 21:41:11”进行比较。
Inside the to_char some calculation is going on, the addition of to date values. 在to_char内部,进行了一些计算,即添加了date值。
TO_DATE('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
+ (create_date / ( 60 * 60 * 24 ))
The to_date function takes a date value in string format ('01/01/1970 00:00:00'), and a format string ('MM/DD/YYYY HH24:MI:SS') to tell it how to interpret the date value. to_date函数采用字符串格式('01 / 01/1970 00:00:00')的日期值和格式字符串('MM / DD / YYYY HH24:MI:SS')来告诉它如何解释日期值。
create_date seems to be a number in seconds 9probably since 01-01-1970). create_date似乎是一个以秒为单位的数字(很可能是1970年1月1日以来的秒数)。 It is devided by the number of seconds in a day so that will result in a number of days.
它由一天中的秒数划分,因此将需要几天的时间。 So what you get is the create date in real calendar value.
因此,您得到的是实际日历值中的创建日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.