oracle to_date 函数与 sysdate
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14108022/
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
to_date function with sysdate
提问by ?ll?ll? l? ?ll?ll?
select TO_CHAR(to_date(sysdate, 'DD-MON-YYYY'), 'DAY') FROM DUAL;
When I run this query the output was : SUNDAY. But we know today is Tuesday(1-1-2013). And
当我运行这个查询时,输出是:SUNDAY。但我们知道今天是星期二(1-1-2013)。和
then changed the query as
然后将查询更改为
select TO_CHAR(to_date('01-JAN-2013', 'DD-MON-YYYY'), 'DAY') FROM DUAL;
answer was :TUESDAY.
答案是:星期二。
then Changed query as
然后将查询更改为
select TO_CHAR(to_date(sysdate+1, 'DD-MON-YYYY'), 'DAY') FROM DUAL;
answer is :MONDAY.
答案是:星期一。
When I using the sysdate why it is show SUNDAY as output?
当我使用 sysdate 时,为什么它显示 SUNDAY 作为输出?
I am new in oracle db. Please help me.
我是 oracle db 的新手。请帮我。
回答by Nipun Jain
use this:
用这个:
select TO_CHAR(sysdate, 'DAY') FROM DUAL;
you are using this :
你正在使用这个:
to_date(sysdate, 'DD-MON-YYYY')
which is giving you date=1/1/0013 which is sunday
这给你 date=1/1/0013 这是星期天
回答by Yogendra Singh
Please refer the documentation for sysdate here. Sysdate is already a date data type.
请在此处参考 sysdate 的文档。Sysdate 已经是一种日期数据类型。
Your example query is inappropriate as to_date
function takes first parameter as String not date
.
您的示例查询不合适,因为to_date
函数将第一个参数作为 String not date
。
Try the simple query below:
试试下面的简单查询:
select TO_CHAR(sysdate, 'DAY') FROM DUAL;
This should return TUESDAY
as output.
这应该TUESDAY
作为输出返回。
回答by Ishani Gupta
To_date
is used to convert a strin to date. As sysdate
is already a date, one must not add add to_date.
To_date
用于将字符串转换为日期。由于sysdate
已经是日期,因此不得添加 add to_date。