oracle - 没有时间存储日期是否使用更少的字节?

标签 oracle date oracle11g

我看到了这个linkthis :

If you specify a date value without a time component, then the default time is midnight. If you specify a date value without a date, then the default date is the first day of the current month.

Oracle DATE columns always contain fields for both date and time. If your queries use a date format without a time portion, then you must ensure that the time fields in the DATE column are set to midnight.

解决方案是对日期数据类型的列施加约束,并在插入或更新表中的行时创建触发器(使用 TRUNC())。

如果我使用此解决方案,是否可以保证 Oracle 确实会为没有时间的日期存储更少的字节?

Oracle 使用此标准日期时间类型会产生歧义。创建一个日期类型(只包含一个日期)这么难?这是我的看法(我来自 MSSQL)。

最佳答案

不,您没有任何保证......无论发生什么,Oracle 都会存储现在是午夜的事实。您不能存储没有时间的日期。

如果创建下表:

create table a ( dt date);
insert into a values(sysdate);
insert into a values(trunc(sysdate));

然后运行这个查询:

select dt, dump(dt) from a

SQL Fiddle

返回值是:

+-----------------------------+------------------------------------+
|             DT              |              DUMP(DT)              |
+-----------------------------+------------------------------------+
| June, 12 2013 18:03:15+0000 | Typ=12 Len=7: 120,113,6,12,19,4,16 |
| June, 12 2013 00:00:00+0000 | Typ=12 Len=7: 120,113,6,12,1,1,1   |
+-----------------------------+------------------------------------+

DUMP()返回数据类型、字节长度和数据的内部表示。

换句话说,带时间的日期和被截断的日期都有 7 个字节。它们的长度相同。


顺便说一句,我建议不要因为担心空间问题而破坏可能有用的数据。

关于oracle - 没有时间存储日期是否使用更少的字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17072147/

相关文章:

C# ToString ("MM/dd/yy") 删除前导 0

database - ORA-19602 : cannot backup or copy active file in NOARCHIVELOG mode

apache - Oracle + NiFi => 所有字段转换为字符串

mysql - Oracle 11g 对比 MySQL 对比 Hadoop :- benchmarking for 10^6 to 10^9 records

oracle - 在 oracle 10g 中,如何在循环中接受用户输入?

asp.net - 数据库关系查询

甲骨文函数 : Replicate wm_concat

javascript - 为什么 +new Date() 返回的结果与 new Date().getTime() 相同?

sql - 从 VARIABLE ‘创建表空间’

java - 按 Java java.sql.Timestamp 中的方式检索 Oracle 日期/时间戳字段,无需转换为 DST