下周在甲骨文

瑙尔·萨米利

我正在使用oracle dbms,并且在Employe表中有一列Birthdate我想编写一个查询,以显示下周生日的员工。这个对吗 ?

select name 
from employe 
where  to_char(birthdate,'DD-MM')=to_char(next_day(sysdate,1)+7,'DD-MM');
劳伦兹·阿尔伯

正确的解决方案是

SELECT name
FROM employe
WHERE to_char(birthdate
              /* "move" the birthdate to the current year
                 to get a reliable week number */
              + CAST((EXTRACT(year FROM current_date)
                      - EXTRACT(year FROM birthdate)) || '-0'
                     AS INTERVAL YEAR TO MONTH),
              'IW')
    = to_char(current_date + 7, 'IW');

IW格式返回包含日期的ISO周,这可能是您要查找的日期。如果您在星期天开始一周,则在两个日期中添加一个。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章