如何使用一周中非标准的第一天来计算Oracle中的一周中的一周?(How do I calulate week of year in Oracle using a non

系统教程 行业动态 更新时间:2024-06-14 16:53:07
如何使用一周中非标准的第一天来计算Oracle中的一周中的一周?(How do I calulate week of year in Oracle using a non-standard first day of the week?)

我有一个查询需要返回日期字段的“一年中的一周”,但查询的客户使用一周中非标准的第一天,因此带有'IW' TO_CHAR未返回预期结果。 在这种情况下,一周的第一天是星期六,星期五是一周的第七天。

使用T-SQL我会使用DATEPART和SET DATEFIRST 。

什么是Oracle等价物? 我在谷歌找到的答案关于设置NLS_TERRITORY就像所以ALTER SESSION SET NLS_TERRITORY = 'UNITED KINGDOM'; 但我没有看到我可以选择任意一天(除了找到使用星期六的领域)。

I have a query that needs to return the "week of year" of a date field but the customer of the query uses a non-standard first day of the week so TO_CHAR with 'IW' isn't returning the expected result. In this case the first day of the week is Saturday and Friday is the seventh day of the week.

With T-SQL I'd use DATEPART and SET DATEFIRST.

What is the Oracle equivalent? The Oracle answers I've found in the google all talk about setting the NLS_TERRITORY like so ALTER SESSION SET NLS_TERRITORY = 'UNITED KINGDOM'; but I'm not seeing where I can pick an arbitrary day (other than perhaps finding a territory that uses Saturday).

最满意答案

IW适用于周一至周日的周,所以这应该可以满足您的需求。 基本上,从现在开始的2天内获得一周:

to_char(your_date + 2, 'IW')

IW works with a Monday - Sunday week, so this should get you what you are looking for. Basically, get the week according to the day 2 days from now:

to_char(your_date + 2, 'IW')

更多推荐

本文发布于:2023-04-05 21:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/233254b000ca91ca8c1d2bd90044cb17.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中非   如何使用   天来   标准   week

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!