to_date function with sysdate

瘦欲@ 提交于 2019-11-28 08:42:49

问题


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

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?

I am new in oracle db. Please help me.


回答1:


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




回答2:


Please refer the documentation for sysdate here. Sysdate is already a date data type.

Your example query is inappropriate as to_date function takes first parameter as String not date.

Try the simple query below:

     select TO_CHAR(sysdate, 'DAY') FROM DUAL; 

This should return TUESDAY as output.




回答3:


To_date is used to convert a strin to date. As sysdate is already a date, one must not add add to_date.



来源:https://stackoverflow.com/questions/14108022/to-date-function-with-sysdate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!