带有时间戳的 Oracle 截断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26862108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:36:51  来源:igfitidea点击:

Oracle trunc with timestamp

sqloracle

提问by RNJ

I have a timestamp which I want to truncate. I am using the truncfuntion in oracle. This seems to do what I want however from the documentation it should only accept a dateand not a timestamp

我有一个要截断的时间戳。我在 oracle 中使用了trunc功能。这似乎做了我想要的但是从文档中它应该只接受日期而不是时间戳

select TRUNC(TO_DATE('22-AUG-13'), 'YEAR') from dual;
select TRUNC(to_timestamp('2013-08-22 06:00:00','YYYY-MM-DD HH24:MI:SS'), 'YEAR') from dual;

Both of the above return the same result.

以上两者都返回相同的结果。

I presume it works because timestamp is an extension of the date format as quoted here

我认为它有效,因为时间戳是此处引用的日期格式的扩展

The TIMESTAMP data type is an extension of the DATE data type. It stores the year, month, and day of the DATE data type, plus the hour, minute, and second values. It has no time zone. The TIMESTAMP data type has the following form:

TIMESTAMP 数据类型是 DATE 数据类型的扩展。它存储 DATE 数据类型的年、月和日,以及小时、分钟和秒值。它没有时区。TIMESTAMP 数据类型具有以下形式:

My question is what is the type of the return value? Is it always the type of the parameter value? Timestamp if parameter is timestamp. Date if parameter is date.

我的问题是返回值的类型是什么?它总是参数值的类型吗?时间戳,如果参数是时间戳。如果参数为日期,则为日期。

How can I find out the return type?

如何找出返回类型?

Thanks

谢谢

回答by Multisync

From Oracle reference:
https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions201.htm

来自 Oracle 参考:https:
//docs.oracle.com/cd/B19306_01/server.102/b14200/functions201.htm

The TRUNC (date) function returns date with the time portion of the day truncated to the unit specified by the format model fmt. This function is not sensitive to the NLS_ CALENDAR session parameter. It operates according to the rules of the Gregorian calendar. The value returned is always of data type DATE, even if you specify a different datetime data type for date.

TRUNC( date) 函数返回日期,其中日期的时间部分被截断为格式模型fmt指定的单位。此函数对 NLS_CALENDAR 会话参数不敏感。它根据公历的规则运作。返回的值始终是数据类型 DATE,即使您为date指定了不同的日期时间数据类型