Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3895467
  • 博文数量: 534
  • 博客积分: 10470
  • 博客等级: 上将
  • 技术积分: 4800
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-26 14:08
文章分类

全部博文(534)

文章存档

2021年(1)

2019年(1)

2017年(1)

2016年(2)

2013年(2)

2012年(10)

2011年(43)

2010年(10)

2009年(17)

2008年(121)

2007年(253)

2006年(73)

分类: Oracle

2006-12-26 11:11:14

日期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.
阅读(4592) | 评论(0) | 转发(0) |
0

上一篇:C快速产生随机字符串

下一篇:ORA-01405

给主人留下些什么吧!~~