首页 > 解决方案 > 下周在甲骨文

问题描述

我正在使用 oracle dbms,并且我在Employe表中有一个列Birthdate。我想写一个查询来显示下周过生日的员工。它是否正确 ?

select name 
from employe 
where  to_char(birthdate,'DD-MM')=to_char(next_day(sysdate,1)+7,'DD-MM');

标签: oracledate-arithmetic

解决方案


这不是正确用法next_day():该函数返回一天中下一个实例的日期。例如,要查找下周五的日期:

select next_day(sysdate, 'FRIDAY') from dual;

要查找生日在 7 天后的员工,您只需稍微调整一下查询:

select name 
from employe
where to_char(birthdate,'DD-MM') = to_char(sysdate+7,'DD-MM');

推荐阅读