pl sql 如何获取 oracle db 日期的星期几
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6829567/
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
pl sql how to get the day of the week for oracle db date
提问by yoav.str
I have oracle date , I want to translate it to my date , for instance 24.7.2011 is sunday so i want a function to return 1 , for 25.7.2011 I want it to return 2 and so on...
我有 oracle 日期,我想将它转换为我的日期,例如 24.7.2011 是星期天,所以我想要一个函数返回 1,对于 25.7.2011 我希望它返回 2 等等......
I have been searching the wwb for examples but with no successes please help me.
我一直在 wwb 上搜索示例,但没有成功,请帮助我。
回答by Tony Andrews
The Oracle function for this is TO_DATE with the 'D' format model:
用于此的 Oracle 函数是 TO_DATE,具有“D”格式模型:
SQL> select to_char (date '2011-07-24', 'D') d from dual;
D
-
7
As you can see, this returns 7 for Sunday, not 1, when I run it. The value returned varies according to your NLS settings. If necessary you could do this to get what you want:
如您所见,当我运行它时,周日返回 7,而不是 1。返回的值因您的 NLS 设置而异。如有必要,您可以这样做以获得您想要的:
SQL> select to_char (date '2011-07-24'+1, 'D') d from dual;
D
-
1
More details about Oracle's date format models can be found here
可以在此处找到有关 Oracle 日期格式模型的更多详细信息
回答by pratik garg
just you have to write to_char(your_date_column_name,'D')
it will give the same answer what you have asked
只是你必须写to_char(your_date_column_name,'D')
它会给出与你所问相同的答案
just click herefor more details
只需点击这里了解更多详情