oracle 如何从日期中获取星期几名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8004645/
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 get the week day name from a date?
提问by user1025901
Given 03/09/1982
how can we say it is which week day. In this case it will be Tue
.
鉴于03/09/1982
我们怎么能说它是哪个星期几。在这种情况下,它将是Tue
.
Is it possible to get in a single query?
是否可以进入单个查询?
回答by Zohaib
SQL> SELECT TO_CHAR(date '1982-03-09', 'DAY') day FROM dual;
DAY
---------
TUESDAY
SQL> SELECT TO_CHAR(date '1982-03-09', 'DY') day FROM dual;
DAY
---
TUE
SQL> SELECT TO_CHAR(date '1982-03-09', 'Dy') day FROM dual;
DAY
---
Tue
(Note that the queries use ANSI date literals, which follow the ISO-8601 date standard and avoid date format ambiguity.)
(请注意,查询使用 ANSI 日期文字,它遵循 ISO-8601 日期标准并避免日期格式歧义。)
回答by cluelessgumshoe
To do this for oracle sql, the syntax would be:
要为 oracle sql 执行此操作,语法将是:
,SUBSTR(col,INSTR(col,'-',1,2)+1) AS new_field
,SUBSTR(col,INSTR(col,'-',1,2)+1) AS new_field
for this example, I look for the second '-' and take the substring to the end
对于这个例子,我寻找第二个 '-' 并将子字符串带到最后