今天是星期二。

为什么运行此SQL语句却说不是星期二呢?

SELECT
CASE
WHEN TO_CHAR(sysdate, 'Day') = 'Tuesday' THEN 'Its Tuesday'
ELSE 'Its Not Tuesday'
END AS case_result,
TO_CHAR(sysdate, 'Day') AS day
FROM DUAL

返回值:
CASE_RESULT DAY
It's Not Tuesday    Tuesday

最佳答案

这样尝试

SELECT CASE
       WHEN trim(TO_CHAR(SYSDATE, 'Day')) = 'Tuesday' THEN 'Its Tuesday'
       ELSE 'Its Not Tuesday'
       END AS case_result,
       TO_CHAR(SYSDATE, 'Day') AS DAY
FROM  DUAL;

或者按照ajmalmhd04的建议,您可以尝试使用FmDay,例如
SELECT CASE
       WHEN TO_CHAR(SYSDATE, 'FmDay') = 'Tuesday' THEN 'Its Tuesday'
       ELSE 'Its Not Tuesday'
       END AS case_result,
       TO_CHAR(SYSDATE, 'Day') AS DAY
FROM  DUAL;

10-07 14:41