简体   繁体   English

Oracle SQL:特定日期格式的条件

[英]Oracle SQL: condition for a specific date format

I have a date column which usually constists of data + hour + minutes.我有一个日期列,通常由数据 + 小时 + 分钟组成。 Sometimes it's just a date.有时它只是一个约会。 I want to make a condition in where clause, to fetch records only if they have data, hour and minute.我想在 where 子句中创建一个条件,仅当它们有数据、小时和分钟时才获取记录。 How can I do that?我怎样才能做到这一点?

In Oracle, a DATE data type is a binary data type consisting of 7 bytes that represent: century, year-of-century, month, day, hour, minute and second.在 Oracle 中, DATE数据类型是由 7 个字节组成的二进制数据类型,分别代表:世纪、世纪、月、日、小时、分钟和秒。 It ALWAYS has those 7 bytes and it is NEVER stored in any particular (human-readable) format.总是有这 7 个字节,并且永远不会以任何特定的(人类可读的)格式存储。

Given this, your question does not make sense as you cannot have a DATE data type that does not have hour, minute or second components.鉴于此,您的问题没有意义,因为您不能拥有没有小时、分钟或秒组件的DATE数据类型。 If the time components are not provided then default values will be used and set the hours, minutes and/or seconds to 0.如果未提供时间组件,则将使用默认值并将小时、分钟和/或秒设置为 0。

If we rephrase the question to:如果我们将问题改写为:

I want to make a condition in where clause, to fetch records only if the time component of the date is not midnight.我想在 where 子句中创建一个条件,仅当日期的时间部分不是午夜时才获取记录。 How can I do that?我怎样才能做到这一点?

SELECT *
FROM   table_name
WHERE  date_column > TRUNC(date_column);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM