where子句中的Oracle-complexer case语句

where子句中的Oracle-complexer case语句,oracle,case,where-clause,Oracle,Case,Where Clause,在Oracle中,我需要根据当前年份的月份设置MYDATE的where子句。 如果月份等于或大于4月,则将MYDATE限制为当前年份01.01.year-31.12.year 否则将MYDATE限制为比当前时间早的所有日期 我需要一个纯SQL解决方案,如果可能的话,不是PL/SQL。我试图调整我在网络和stackoverflow.com上发现的内容,但语法错误: SELECT text, mydate FROM mytable WHERE CASE WHEN to_number(TO_C

在Oracle中,我需要根据当前年份的月份设置MYDATE的where子句。 如果月份等于或大于4月,则将MYDATE限制为当前年份01.01.year-31.12.year 否则将MYDATE限制为比当前时间早的所有日期

我需要一个纯SQL解决方案,如果可能的话,不是PL/SQL。我试图调整我在网络和stackoverflow.com上发现的内容,但语法错误:

SELECT text, mydate
FROM mytable
WHERE
CASE
    WHEN to_number(TO_CHAR(sysdate, 'MM')) >= 4 -- if month of current year >= april
        THEN mydate >=TRUNC(LAST_DAY(SYSDATE), 'YYYY') --beginning of current year
        AND mydate  < TRUNC(LAST_DAY(SYSDATE)+1, 'YYYY') -- end of current year
    ELSE -- if month of current year < april
        mydate < sysdate;   
有人能帮我吗

事先非常感谢。

您不需要箱子。只要和/或在哪里就行

SELECT text, mydate
FROM mytable
WHERE
   (     to_number(TO_CHAR(sysdate, 'MM')) >= 4 -- if month of current year >= april
     AND mydate >=TRUNC(LAST_DAY(SYSDATE), 'YYYY') --beginning of current year
     AND mydate < TRUNC(LAST_DAY(SYSDATE)+1, 'YYYY') -- end of current year
   ) OR (
         to_number(TO_CHAR(sysdate, 'MM')) < 4 
    AND  mydate < sysdate)
   );