Oracle Date类型与SQLT_DAT分析

日期DATE对应的OCI类型为SQLT_DAT,可以保存为7Bytes。下面是一个日期类型保存的事例:

Example (for 30-NOV-1992, 3:17 PM)
----------------------------------------------------------
Byte       1       2     3      4     5     6      7
----------------------------------------------------------
Meaning    Century Year  Month  Day   Hour  Minute Second    
Values     119     192   11     30    16    18     1
----------------------------------------------------------

解释:
Oracle的DATE类型的取值范围是公元前4712年1月1日至公元9999年12月31日。而且根据日期的特定,要不然是公元1年,要不然是公元前1年,

不会出现0年的情况。
  日期类型长度是7,7个字节分别表示世纪、年、月、日、时、分和秒。
  由于不会出现0的情况,月和日都是按照原值存储的,月的范围是1~12,日的范围是1~31。
  由于时、分、秒都会出现0的情况,因此存储时采用原值加1的方式。0时保存为1,13时保存为14,23时保存为24。分和秒的情况与小时类似。小时的范围是0~23,在数据库中以1~24保存。分和秒的范围都是0~59,在数据库中以1~60保存。
  年和世纪的情况相对比较复杂,可分为公元前和公元后两种情况。由于最小的世纪的值是-47(公元前4712年),最大值是99(公元9999年)。为了避免负数的产生, oracle把世纪加100保存在数据库中。公元2000年,世纪保存为120,公元9999年,世纪保存为199,公元前101年,世纪保存为99 (100+(-1)),公元前4712年,世纪保存为53(100+(-47))。
  注意,对于公元前1年,虽然已经是公元前了,但是表示世纪的前两位的值仍然是0,因此,这时的保存的世纪的值仍然是100。世纪的范围是-47~99,保存的值是53~199。
  年的保存与世纪的保存方式类似,也把年的值加上100进行保存。对于公元2000年,年保持为100,公元1年保存为101,公元2004年保存为104,公元9999 年保存为199,公元前1年,保存为99(100+(-1)),公元前101年,保存为99(100+(-1)),公元前4712年保存为88(100+(-12))。对于公元前的年,保存的值总是小于等于100,对于公元后的年,保存的值总是大于等于100。年的范围是0~99,保存的值是1~199。
  注意:一般的世纪,都包含了100年,而对于0世纪,由于包含公元前和公元后两部分且不包含0年,因此包含了198年。

Oracle OCI 文档内容如下:
DATE
The DATE datatype can update, insert, or retrieve a date value using the Oracle internal date binary format. A date in binary

format contains seven bytes, as shown in Table 3-4.

Table 3-4 Format of the DATE Datatype
Byte                     1     2     3     4     5     6     7
Meaning                 Century Year     Month     Day     Hour     Minute     Second
Example (for 30-NOV-1992, 3:17 PM)     119     192     11     30     16     18     1

The century and year bytes (bytes 1 and 2) are in excess-100 notation. The first byte stores the value of the year, which is

1992, as an integer, divided by 100, giving 119 in excess-100 notation. The second byte stores year modulo 100, giving 192.

Dates Before Common Era (BCE) are less than 100. The era begins on 01-JAN-4712 BCE, which is Julian day 1. For this date, the

century byte is 53, and the year byte is 88. The hour, minute, and second bytes are in excess-1 notation. The hour byte

ranges from 1 to 24, the minute and second bytes from 1 to 60. If no time was specified when the date was created, the time

defaults to midnight (1, 1, 1).

When you enter a date in binary format using the DATE external datatype, the database does not do consistency or range

checking. All data in this format must be carefully validated before input.
 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值