0

我尝试在 Oracle DB 表的某些行中更新错误日期(使用 0018 年而不是 2018 年)。所以我想为此增加 10 年。现在日期还是一样的问题。例如,日期可以是 10-JUL-0018 或 02-NOV-0018

我试过这个,但它不工作:

UPDATE MyTable SET MyDate= add_months(MyDate, 2000 * 12),'DD/MM/YYYY HH24:MI:SS'))
Where MyMainField_ID IN (
SELECT MyMainField_ID
FROM MyTable  
where TO_CHAR(MyDate,'YYYY') = 0018
)   

我收到此错误:

SQL 错误:ORA-01747:无效的 user.table.column、table.column 或列规范 01747。00000 -“无效的 user.table.column、table.column 或列规范” 您能帮我解决这个问题吗?

提前致谢

塞巴斯蒂安

4

3 回答 3

3

你把事情复杂化了。

update mytable
set mydate = mydate + interval '2000' year(4)
where mydate < date '0100-01-01'; -- some threshold date for when to apply the update

如果存在的话,这可能会使用 mydate 上的索引。

于 2018-10-29T11:33:11.363 回答
3

为什么不简化呢?

UPDATE MyTable SET MyDate= add_months(MyDate, 2000 * 12)
where TO_CHAR(MyDate,'YYYY') = 0018
于 2018-10-29T11:31:03.467 回答
1

删除,'DD/MM/YYYY HH24:MI:SS'))

UPDATE MyTable SET MyDate= add_months(MyDate, 2000 * 12)
Where MyMainField_ID IN (
SELECT MyMainField_ID
FROM MyTable  
where TO_CHAR(MyDate,'YYYY') = 0018
)

似乎已经从你的陈述中得到了一些改变......

于 2018-10-29T11:31:08.623 回答