ITPub博客

首页 > 数据库 > Oracle > [20261106]ANSI DATE and TIMESTAMP SQL syntax.txt

[20261106]ANSI DATE and TIMESTAMP SQL syntax.txt

原创 Oracle 作者:lfree 时间:2026-11-08 20:41:44 0 删除 编辑

[20261106]ANSI DATE and TIMESTAMP SQL syntax.txt

--//更正自己以前的一些错误认知,以为timestamp不支持秒后面的数字,实际上支持的,看如下例子:
--//补充说明:date仅仅支持年月日,timestamp不能没有时分秒。
--//以前链接:[20230207]ANSI DATE and TIMESTAMP SQL syntax.txt

SCOTT@book01p> select count(*) from dba_objects where created > timestamp'2012-01-01 08:12:34.00001';

  COUNT(*)
----------
     75211

SCOTT@book01p> select count(*) from dba_objects where created > timestamp'2012-01-01 08:12:34';

  COUNT(*)
----------
     75211


SCOTT@book01p> select count(*) from dba_objects where created > timestamp'2012-01-01';
select count(*) from dba_objects where created > timestamp'2012-01-01'
                                                          *
ERROR at line 1:
ORA-01861: literal does not match format string
--//反倒不支持date格式。

SCOTT@book01p> select count(*) from dba_objects where created > timestamp'2012-01-01 08:12:34.1234567891';
select count(*) from dba_objects where created > timestamp'2012-01-01 08:12:34.1234567891'
                                                          *
ERROR at line 1:
ORA-01873: the leading precision of the interval is too small

SCOTT@book01p> select count(*) from dba_objects where created > timestamp'2012-01-01 08:12:34.123456789';
  COUNT(*)
----------
     75211

--//最多9位小数。

SCOTT@book01p> select count(*) from dba_objects where created > timestamp'2012/01/01 08:12:34.123456789';
select count(*) from dba_objects where created > timestamp'2012/01/01 08:12:34.123456789'
                                                          *
ERROR at line 1:
ORA-01861: literal does not match format string

--//不支持/分割。

SCOTT@book01p> select count(*) from dba_objects where created > timestamp'2012 - 01 -01 08 : 12 : 34.123456789';
  COUNT(*)
----------
     75211
--//中间存在空格没问题。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-3188150/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4017
  • 访问量
    7991556