我有一个查询需要返回日期字段的“一年中的一周”,但查询的客户使用一周中非标准的第一天,因此带有'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')更多推荐
发布评论