Oracle Decode function results with different formats

匿名 (未验证) 提交于 2019-12-03 00:58:01

问题:

SELECT DECODE (SYSDATE, SYSDATE + 1, NULL, SYSDATE)   FROM DUAL;   SELECT DECODE (SYSDATE, SYSDATE + 1, TO_DATE (NULL), SYSDATE)   FROM DUAL; 

why am i getting the results in different formats from the queries above?

i am using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

回答1:

the decode function result has the datatype of the third parameter. In the first case, since no datatype is specified for NULL, the default VARCHAR2 is used. In the second case, a DATE is explicitely asked for and therefore the result is a date.

In other words, the first query is the same as:

SELECT DECODE(SYSDATE, SYSDATE + 1, to_char(NULL), to_char(SYSDATE)) FROM DUAL; 

The output of this query will be formatted as per your NLS_DATE_FORMAT session parameter, while the second query will return a date which will be displayed according to your client settings.



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