简体   繁体   English

oracle无效提取源中的提取函数错误

[英]Extract function error in oracle invalid extract source

I was trying to extract minute from a datetime field .我试图从日期时间字段中提取分钟。 But i am getting the below issue .但我得到了以下问题。 Please share any thoughts.请分享任何想法。

code :-
select extract( minute from UPD_Action_STRT_Holi_update ) from my table

Error
ORA-30076: invalid extract field for extract source

Sample Data :-
UPD_Action_STRT_Holi_update 
9/3/2021 12:39:27 PM
``
Extract source is datetime field

Oracle does not have a DATETIME<\/code> data type; Oracle 没有DATETIME<\/code>数据类型; it has either a DATE<\/code> or a TIMESTAMP<\/code> and they both have year, month, day, hour, minute and second components;它有一个DATE<\/code>或一个TIMESTAMP<\/code> ,它们都有年、月、日、小时、分钟和秒的组成部分; TIMESTAMP<\/code> can, optionally, have fractional seconds and time zone components. TIMESTAMP<\/code>可以选择包含小数秒和时区组件。

You get that error if your column has the DATE<\/code> data type.如果您的列具有DATE<\/code>数据类型,则会收到该错误。

The EXTRACT<\/code> function documentation<\/a> states that: EXTRACT<\/code>函数文档<\/a>指出:

you can extract only YEAR<\/code> , MONTH<\/code> , and DAY<\/code> from a DATE<\/code> value.您只能从DATE<\/code>值中提取YEAR<\/code> 、 MONTH<\/code>和DAY<\/code> 。

<\/blockquote>

If you want to use EXTRACT<\/code> to get the MINUTE<\/code> value then cast the DATE<\/code> to a TIMESTAMP<\/code> :如果要使用EXTRACT<\/code>获取MINUTE<\/code>值,则将DATE<\/code>转换为TIMESTAMP<\/code> :

 select extract( minute from CAST(UPD_Action_STRT_Holi_update AS TIMESTAMP) ) from my_table<\/code><\/pre>

db<>fiddle here<\/a><\/em> db<> 在这里<\/a>摆弄<\/em>

"

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

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