![](/img/trans.png)
[英]Getting a date for "start of the week", from week and year numbers on Oracle SQL
[英]Convert week of the year to date in oracle sql
如何在 Oracle SQL 中使用一年中的一周获取日期?
我需要搜索在本周开始之后创建的条目。 目前,我通过执行select to_char(sysdate,'WW') from dual;
获得一年中的一周select to_char(sysdate,'WW') from dual;
,但后来我做不到
select * from table where date > to_date(to_char(sysdate,'WW'), 'WW')
因为我得到
ORA-01820: format code cannot appear in date input format
01820. 00000 - "format code cannot appear in date input format"
*Cause:
*Action:
根据 ORA 文档:
ORA-01820: 格式代码不能出现在日期输入格式中
原因:日期规范包含无效的格式代码。 > 输入日期时只能指定以下内容:年、月、日、小时、分钟、秒、儒略日,> AM/PM 和 BC/AD
行动:从日期规范中删除无效的格式代码。
您不能将 weeknum 传递给 to_date() 函数。 你可以做的是,例如,以下
select * from table where date > (next_day(trunc(sysdate), 'SUNDAY') - 7)
基本上,next_day 返回满足指定工作日的第一个日期。 假设现在是 2020-09-07 星期一,next_day 将返回未来最接近的 SUNDAY,即 2020-09-13,因此您需要减去 7 以获得当前周的开始日期。 你可以在这里读更多关于它的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.