oracle 错误 ORA-00932: 不一致的数据类型: 预期日期得到 NUMBER

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25855830/
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:30:45  来源:igfitidea点击:

ERROR ORA-00932: inconsistent datatypes: expected DATE got NUMBER

sqloracleextractto-date

提问by user3845574

I am trying to execute the following sql statement for an oracle database:

我正在尝试为 oracle 数据库执行以下 sql 语句:

UPDATE PARENT
SET RENEW_DATE = TO_DATE('08/31/' + EXTRACT(YEAR FROM JOINED), 'MM/dd/yyyy')
WHERE STATUS_IND = 'Active';

I am expecting to get the year piece from the field called Joined which is a date formatted like MM/dd/yyyy. I want the end result, or the value I am setting to look like '8/31/2015' for example.

我期待从名为 Joined 的字段中获取年份,这是一个格式为 MM/dd/yyyy 的日期。例如,我想要最终结果,或者我设置的值看起来像“8/31/2015”。

Any help is appreciated I have tried multiple things.

感谢任何帮助我尝试了多种方法。

采纳答案by Chris Barlow

Use a ||instead of the +sign to concatinate the date together.

使用 a||而不是+符号将日期连接在一起。

UPDATE PARENT 
  SET RENEW_DATE = TO_DATE('08/31/' || EXTRACT(YEAR FROM JOINED), 'MM/dd/yyyy') 
WHERE STATUS_IND = 'Active'