Is Oracle (10g) doing a proper TIME comparison here, or do I need to convert to decimal time and then compare? E.g.,
IF (SELECT TO_CHAR(sysdate,'HH24:MI:SS') from dual) <= '15:00'
THEN (...)
Thanks.
Is Oracle (10g) doing a proper TIME comparison here, or do I need to convert to decimal time and then compare? E.g.,
IF (SELECT TO_CHAR(sysdate,'HH24:MI:SS') from dual) <= '15:00'
THEN (...)
Thanks.
IF (sysdate <= trunc(sysdate)+15/24)
THEN (...)
应该做的伎俩...
您不能select
在if
语句中执行 a,但可以与 sysdate 进行直接比较。如果您这样做,最好使用数字而不是依赖隐式转换。你也不需要额外的时间等等。比如,
begin
if to_number(to_char(sysdate,'HH24')) <= 15 then
-- do something
end if;
end;
如果您确实想使用分钟,那么通过将其转换为不带冒号的字符串,您可以进行更直接的比较。只要日期/时间以 24 小时格式转换,没有额外的和反向的,年、月、日、小时等比较总是准确的,例如
begin
if to_char(sysdate,'HH24MI') <= '1515' then
-- do something
end if;
end;
但是,通常最好进行日期比较,因为@cagcowboy 在我到达那里之前刚刚发布!
使用以下代码
SELECT TO_CHAR(SYSDATE, 'HH24MI') INTO V_SYS_TIME FROM DUAL; 如果 V_SYS_TIME 在 V1_TIME 和 V2_TIME 之间,那么 (……)