gpt4 book ai didi

sql - 带有时间戳的 Oracle 截断

转载 作者:行者123 更新时间:2023-12-04 21:52:56 30 4
gpt4 key购买 nike

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

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;

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

我认为它有效,因为时间戳是引用的日期格式的扩展 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:



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

如何找出返回类型?

谢谢

最佳答案

从 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.

关于sql - 带有时间戳的 Oracle 截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26862108/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com