Oracle的默认日期格式为YYYY-MM-DD,为什么? [英] Oracle's default date format is YYYY-MM-DD, WHY?

查看:865
本文介绍了Oracle的默认日期格式为YYYY-MM-DD,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Oracle的默认日期格式为YYYY-MM-DD.这意味着如果我这样做:

Oracle's default date format is YYYY-MM-DD. Which means if I do:

 select some_date from some_table

...我丢失了日期中的时间部分.

...I lose the time portion of my date.

是的,我知道您可以使用以下方法修复"此问题:

Yes, I know you can "fix" this with:

 alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

但是认真的说,为什么不是上面的默认值吗?尤其是在DBMS中,两个主要的时间跟踪数据类型(DATE和TIMESTAMP)都具有一个至少包含1秒精度的时间分量.

But seriously, why isn't the above the default? Especially in a DBMS where the two primary time-tracking data types (DATE and TIMESTAMP) both have a time component that includes (at least) accuracy down to 1 second.

推荐答案

如果使用此查询为数据仓库生成输入文件,则需要适当格式化数据.实质上,在这种情况下,您要将日期(确实具有时间成分)转换为字符串.您需要显式设置字符串格式或更改nls_date_format来设置默认值.在查询中,您只需执行以下操作即可:

If you are using this query to generate an input file for your Data Warehouse, then you need to format the data appropriately. Essentially in that case you are converting the date (which does have a time component) to a string. You need to explicitly format your string or change your nls_date_format to set the default. In your query you could simply do:

select to_char(some_date, 'yyyy-mm-dd hh24:mi:ss') my_date
  from some_table;

这篇关于Oracle的默认日期格式为YYYY-MM-DD,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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