KingbaseES时间类数据类型和oracle时间类数据类型的区别

本文详细对比了KingbaseES和Oracle在时间类型(包括Date、Timestamp和Timestamp with time zone)以及Interval类型上的差异。Oracle的Date类型时间跨度为公元前4712年至公元9999年,而KingbaseES在兼容Oracle模式下可达到公元前4713年至公元294276年。在Timestamp类型上,两者精度有所不同,Oracle默认为6位毫秒,KingbaseES默认也为6位,但超过该精度会给出警告并自动修正。Interval类型方面,Oracle有Year to Month和Day to Second两类,KingbaseES提供更灵活的间隔数据支持。
摘要由CSDN通过智能技术生成

关键字:
数据类型、时间类型

Oracle日期时间类型有两类,一类是日期时间类型,包括Date, Timestamp with time zone,Timestamp with local time zone。另一类是Interval类型,主要有Interval year to month 和Interval day to second两种。
KingbaseES也有类似的两类时间类型。其中日期时间类型包括Timestamp with time zone, Timestamp without time zone,Date,Time with time zone , Time without time zone五种。Interval类型为Interval。此外,KingbaseES扩展了Date数据类型,在兼容oracle模式时date的值“年月日时分秒”与oracle一致,在pg模式下则为“年月日”。
1、 日期时间类型
1.1. Date 类型
Oracle的Date类型包括年、月、日、时、分、秒六个字段,时间跨度是公元前4712年1月1日~公元9999年12月31日。
 Oracle date:
SQL> create table o_test(value date);
Table created.
SQL> insert into o_test values(to_date(’-4712-01-01 00:30:45’, ‘syyyy-mm-dd hh24:mi:ss’));
1 row created.
SQL> insert into o_test values(to_date(’-4712-01-01 00:30:45’, ‘syyyy-mm-dd hh24:mi:ss’) - interval ‘1’ day);
insert into o_test values(to_date(’-4712-01-01 00:30:45’, ‘syyyy-mm-dd hh24:mi:ss’) - interval ‘1’ day)
*
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
SQL> insert into o_test values(to_date(‘9999-12-31 12:30:45’, ‘yyyy-mm-dd hh24:mi:ss’));
1 row created.
SQL> insert into o_test values(to_date(‘9999-12-31 12:30:45’, ‘yyyy-mm-dd hh24:mi:ss’) + interval ‘1’ day);
insert into o_test values(to_date(‘9999-12-31 12:30:45’, ‘yyyy-mm-dd hh24:mi:ss’) + interval ‘1’ day)
*
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0

SQL> select to_char(value, ‘syyyy/mm/dd hh24:mi:ss’) from o_test;

TO_CHAR(VALUE,‘SYYYY/MM/DDHH24:MI:SS’)

-4712/01/01 00:30:45
9999/12/31 12:30:45
KingbaseES在兼容oracle模式下可以直接使用date数据类型或者使用 Timestamp(0) without time zone 类型来对应。时间跨度从公元前4713年~公元294276年。
 KingbaseES Date 和 Timestamp(0) without time zone
test=# create table test1(value timestamp(0) without time zone,value1 date);
CREATE TABLE
test=# insert into test1 values(‘4712-01-01 00:30:45BC’,‘4712-01-01 00:30:45BC’);
INSERT 0 1
insert into test1 values(to_timestamp(‘4712-01-01 00:30:45BC’,‘yyyy-mm-dd hh24:mi:ssBC’) - interval ‘1 day’,to_timestamp(‘4712-01-01 00:30:45BC’,‘yyyy-mm-dd hh24:mi:ssBC’) - interval ‘1 day’);
INSERT 0 1
test=# insert into test1 values(‘9999-12-31 23:59:59’,‘9999-12-31 23:59:59’);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值