oracle date 类型的范围是多少?

os: centos 7.6
db: oracle 19c

早上一哥们在说 oracle date 类型无法插入 3000年,自己也不敢确定到底可不可以,做了个实验。
事实还是挺打脸的.

# su - oracle
$ sqlplus / as sysdba;

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Sep 11 16:43:25 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL>
SQL> set lines 200;
set pages 300;

SQL> create table tmp_t0(
 c0 date
);

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


SQL> insert into tmp_t0
select to_date('3000-01-01 23:59:59','yyyy-mm-dd hh24:mi:ss')
from dual
;

SQL> select * from tmp_t0;

C0
-------------------
3000-01-01 23:59:59

看上去没啥问题,插入更大值看看

SQL> insert into tmp_t0
select to_date('9000-01-01 23:59:59','yyyy-mm-dd hh24:mi:ss')
from dual
;

SQL> select * from tmp_t0;

C0
-------------------
3000-01-01 23:59:59
9000-01-01 23:59:59

插入一个极大值看看

SQL> insert into tmp_t0
select to_date('9999-12-31 23:59:59','yyyy-mm-dd hh24:mi:ss')
from dual
;

SQL> select * from tmp_t0;

C0
-------------------
3000-01-01 23:59:59
9000-01-01 23:59:59
9999-12-31 23:59:59

看上去也没啥问题,插入极小值看看

SQL> insert into tmp_t0
select to_date('-9999-12-31 23:59:59','yyyy-mm-dd hh24:mi:ss')
from dual
;

ERROR at line 2:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0

哈哈,给出范围了.

666

参考:

你可能感兴趣的:(#,oracle,basic,knowledge)