如何在 Oracle 中将周数提取为周格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18661262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to extract week number as week format in Oracle?
提问by jompi
I have a column of timestamp ...
我有一列时间戳...
I'm going to use OBIEE and the user told me that need graphics per day, week and month...
我将使用 OBIEE,用户告诉我每天、每周和每月都需要图形......
Of the timestamp I'm extracting day, and month ... like this :
我正在提取日期和月份的时间戳......像这样:
--day
select to_char(register_dt, 'DAY DD') as "Day"
from XX;
--by week
--by month
select to_char(register_dt, 'FMMONTH') as "Month"
from XX;
I found
我发现
select to_char( register_dt, 'WW' ) as "Week"
from XX;
but that only give me the number of the week like 36 etc, Can anybody help me to figure it out how to display a week range? like
但这只能给我一周的数字,比如 36 等,有人能帮我弄清楚如何显示一周的范围吗?喜欢
I mean this is Sept 6, like
我的意思是这是 9 月 6 日,比如
1 / Sept / 7
1 / 九月 / 7
8 / Sept / 14
8 / 九月 / 14
etc.. etc..
等等等等。
Please !! Thanks in advance
请 !!提前致谢
回答by Justin Cave
You can truncate the date
to the beginning of the prior week and then manipulate that. So, for example, you can run something like
您可以将 截断date
到前一周的开始,然后对其进行操作。因此,例如,您可以运行类似
select trunc(sysdate, 'W') as first_of_week,
trunc( sysdate + 7, 'W' ) - 1 as last_of_week,
to_char( trunc(sysdate, 'W'), 'DD-MON-YYYY' ) || ' to ' ||
to_char( trunc( sysdate + 7, 'W' ) - 1, 'DD-MON-YYYY' ) as week_range
from dual
to get a string 01-SEP-2013 to 07-SEP-2013
as the week_range
得到一个字符串01-SEP-2013 to 07-SEP-2013
作为week_range