admin

Oracle-获取星期几

sql

今天是星期二。

为什么运行此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

阅读 186

收藏
2021-06-07

共1个答案

admin

这样尝试

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;
2021-06-07