Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 下周在甲骨文_Oracle_Date Arithmetic - Fatal编程技术网

Oracle 下周在甲骨文

Oracle 下周在甲骨文,oracle,date-arithmetic,Oracle,Date Arithmetic,我正在使用oracle dbms,我在Employe表中有一列Birthdate。我想写一个查询,显示下周有生日的员工。 这是正确的吗 select name from employe where to_char(birthdate,'DD-MM')=to_char(next_day(sysdate,1)+7,'DD-MM'); 这不是next_day()的正确用法:该函数返回一天的下一个实例的日期。例如,要查找下周五的日期: select next_day(sysdate, 'FRID

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

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

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

select next_day(sysdate, 'FRIDAY') from dual;
要查找七天后生日的员工,只需稍微调整一下查询:

select name 
from employe
where to_char(birthdate,'DD-MM') = to_char(sysdate+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周,这可能就是您要查找的日期。如果你的一周从周日开始,那么在两个日期中都添加一个。

这回答了“从现在起一周后谁过生日”而不是问题中所说的“下周谁过生日”。但也许这就是我们想要的…@LaurenzAlbe-我更正了OP最初的查询,但你猜到了他们的实际需求:)这不可靠。例如,根据年份的不同,1月1日可以是第52周、第53周或第1周。”“2000-01-01”是第52周,而“2018-01-01”是第01周。尝试
从dual connect按级别<10>选择字符(添加月份(日期'2000-11-25',12*级别),'IW'),您将获得第47周和第48周,具体取决于年份。顺便说一句,format
WW
也有同样的问题。是的,谢谢你的提示。我已尝试修复该查询。