我试图将其显示为显示,但是当输出应为'是'
我正在尝试使其显示显示,但是当输出为“是”时,它使我无效
SELECT STRT_DT,END_DT,SYSDATE AS DT,
CASE
WHEN TO_CHAR(STRT_DT,'MON-YYYY') <= TO_CHAR(SYSDATE,'MON-YYYY')
AND TO_CHAR(END_DT,'MON-YYYY') = TO_CHAR(SYSDATE,'MON-YYYY') THEN 'Yes'
END AS D
FROM
(
SELECT TO_DATE('14-JAN-2022','DD-MON-YYYY') AS STRT_DT
, TO_DATE('05-APR-2022','DD-MON-YYYY') AS END_DT
FROM DUAL);
I'm trying to get it to display but it is fetching me null when the output should be 'YES'
SELECT STRT_DT,END_DT,SYSDATE AS DT,
CASE
WHEN TO_CHAR(STRT_DT,'MON-YYYY') <= TO_CHAR(SYSDATE,'MON-YYYY')
AND TO_CHAR(END_DT,'MON-YYYY') = TO_CHAR(SYSDATE,'MON-YYYY') THEN 'Yes'
END AS D
FROM
(
SELECT TO_DATE('14-JAN-2022','DD-MON-YYYY') AS STRT_DT
, TO_DATE('05-APR-2022','DD-MON-YYYY') AS END_DT
FROM DUAL);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于这一行而无法使用:
您在字符串上使用“比较运算符”,如果它是日期数据类型,则引擎会知道这两者之间的“更高”日期,但是由于它是字符串,因此此条件赢了' t按您预期的方式进行工作(它是按字母顺序比较这些字符串的方式),简单的解决方案就是将其替换为:
或者,如果您只想比较一个月和年份:
在这里我们截断了一个月,所以只有一个月和年份是相关的换句话说,如果
strt_dt
和sysdate
在同一年和月份中,即使strt_dt
是'reamight' (从该月的未来开始)然后sysdate
。It is not working because of this line:
you are using 'Comparison Operator' on a string, if it is a date datatype the engine would know what is a 'higher' date between these two but because it is a string this condition won't work the way you intended (it is comparing those strings on alphabetical basis), simple solution would be to replace it just with:
or if u want to compare only month and year:
here we are truncating month so only month and year are relevant for comparison in other words if
STRT_DT
andSYSDATE
are in the same year and month the condition will be satisfied even if theSTRT_DT
is 'higher' (day from the future of that month) thenSYSDATE
.它无法正常工作;您正在比较一个月名称。切换到其他格式模型,该模型允许有意义的比较,例如
yyyymm
,而不是mon-yyyy
:It can't work; you're comparing month names. Switch to a different format model which allows meaningful comparing, e.g.
YYYYMM
instead ofMON-YYYY
: