本文介绍了Oracle-获取星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天是星期二.

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

How come when I run this SQL statement, it says it's not Tuesday?

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之类的

OR as ajmalmhd04 suggested, you can try with FmDay like,

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;

这篇关于Oracle-获取星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 21:49