具有不同格式的Oracle Decode函数结果 [英] Oracle Decode function results with different formats

查看:175
本文介绍了具有不同格式的Oracle Decode函数结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

我正在使用Oracle数据库10g企业版10.2.0.4.0-64bi

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

推荐答案

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;

此查询的输出将按照您的NLS_DATE_FORMAT会话参数设置格式,而第二个查询将返回一个日期,该日期将根据您的客户端设置显示.

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.

这篇关于具有不同格式的Oracle Decode函数结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆