Oracle 在日期之间更新

问题描述 投票:0回答:1

因此,我尝试根据日期是否位于两个日期范围之间来更新表格,而不是如果日期超出两个范围则更新字段,而不是更新字段

update tablex
set field = 1 
where tableid = 1
and to_date('10/14/2024', 'mm/dd/yyyy') not between trunc(sysdate) and trunc(sysdate - 15);

这是否应该跳过更新字段,因为 10/14/24 日期介于

sysdate
sysdate-15
(9/30/2024)
之间?

sql oracle
1个回答
0
投票

您的“to_date('10/14/2024', 'mm/dd/yyyy')”格式似乎不正确。

如果包含日期的列已经采用日期格式,您需要执行以下操作:

-- 将 your_date_column 替换为正确的列名称 --

update tablex
set field = 1 
where tableid = 1
and (your_date_column not between trunc(sysdate - 15) and trunc(sysdate));

如果包含日期的列不是日期格式,您需要执行以下操作:

-- 将 your_date_column 替换为正确的列名称 --

update tablex
set field = 1 
where tableid = 1
and (to_date(your_date_column, 'MM/DD/YYYY') not between trunc(sysdate - 15) and trunc(sysdate));
© www.soinside.com 2019 - 2024. All rights reserved.