Oracle中的TIMESTAMP类型[转]

原文:http://wangyaobeijing.blog.163.com/blog/static/158330320113276114762/

  1 SQL> create table test_time (col_time timestamp);
  2
  3 表已创建。
  4
  5 SQL> insert into test_time values (to_timestamp(‘0001-1-1 0:0:0.0‘, ‘syyyy-mm-dd hh24:mi:ss.ff‘));
  6
  7 已创建 1 行。
  8
  9 SQL> insert into test_time values (to_timestamp(‘2000-1-1 0:0:0.0‘, ‘syyyy-mm-dd hh24:mi:ss.ff‘));
 10
 11 已创建 1 行。
 12
 13 SQL> insert into test_time values (to_timestamp(‘9999-12-31 23:59:59.999999‘, ‘syyyy-mm-dd hh24:mi:ss.ff‘));
 14
 15 已创建 1 行。
 16
 17 SQL> insert into test_time values (to_timestamp(‘-0001-1-1 0:0:0.0‘, ‘syyyy-mm-dd hh24:mi:ss.ff‘));
 18
 19 已创建 1 行。
 20
 21 SQL> insert into test_time values (to_timestamp(‘-0100-3-4 13:2:3.234015‘, ‘syyyy-mm-dd hh24:mi:ss.ff‘));
 22
 23 已创建 1 行。
 24
 25 SQL> insert into test_time values (systimestamp);
 26
 27 已创建 1 行。
 28
 29
 30 SQL> insert into test_time values (to_timestamp(‘2000-1-1 0:0:0.123456789‘, ‘syyyy-mm-dd hh24:mi:ss.ff9‘));
 31
 32 已创建 1 行。
 33
 34 SQL> commit;
 35
 36 提交完成。
 37
 38 SQL> select to_char(col_time, ‘syyyy-mm-dd hh24:mi:ss.ff9‘) time, dump(col_time) dump_time
 39   2  from test_time;
 40
 41 TIME                           DUMP_TIME
 42 ------------------------------ ----------------------------------------------------
 43  0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,101,1,1,1,1,1
 44  2000-01-01 00:00:00.000000000 Typ=180 Len=7: 120,100,1,1,1,1,1
 45  9999-12-31 23:59:59.999999000 Typ=180 Len=11: 199,199,12,31,24,60,60,59,154,198,24
 46 -0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,99,1,1,1,1,1
 47 -0100-03-04 13:02:03.234015000 Typ=180 Len=11: 99,100,3,4,14,3,4,13,242,201,24
 48  2004-12-15 16:14:52.738000000 Typ=180 Len=11: 120,104,12,15,17,15,53,43,252,252,128
 49  2000-01-01 00:00:00.123457000 Typ=180 Len=11: 120,100,1,1,1,1,1,7,91,205,232
 50
 51 已选择7行。
 52
 53 与DATE类型对比可以发现,对于TIMESTAMP类型,如果不包含微秒信息或者微秒值为0,那么存储结果和DATE完全相同。当微秒值为0时,Oracle为了节省空间,不会保存微秒信息。
 54
 55 如果毫秒值不为0,Oracle把微秒值当作一个9位数的数字来保存。
 56
 57 比如999999000,保存为59,154,198,24。234015000保存为13,242,201,24。
 58
 59 SQL> select to_char(999999000, ‘xxxxxxxxxx‘) from dual;
 60
 61 TO_CHAR(999
 62 -----------
 63    3b9ac618
 64
 65 SQL> select to_number(‘3b‘, ‘xxx‘) one, to_number(‘9a‘, ‘xxx‘) two,
 66   2  to_number(‘c6‘, ‘xxx‘) three, to_number(‘18‘, ‘xxx‘) four from dual;
 67
 68        ONE        TWO      THREE       FOUR
 69 ---------- ---------- ---------- ----------
 70         59        154        198         24
 71
 72 SQL> select to_char(234015000, ‘xxxxxxxx‘) from dual;
 73
 74 TO_CHAR(2
 75 ---------
 76   df2c918
 77
 78 SQL> select to_number(‘d‘, ‘xxx‘) one, to_number(‘f2‘, ‘xxx‘) two,
 79   2  to_number(‘c9‘, ‘xxx‘) three, to_number(‘18‘, ‘xxx‘) four from dual;
 80
 81        ONE        TWO      THREE       FOUR
 82 ---------- ---------- ---------- ----------
 83         13        242        201         24
 84
 85
 86
 87 另外,注意一点,不指定精度的情况下,TIMESTAMP默认取6位。长度超过6位,会四舍五入到6位。如果希望保存9位的TIMESTAMP,必须明确指定精度。
 88
 89 SQL> alter table test_time modify (col_time timestamp(9));
 90
 91 表已更改。
 92
 93 SQL> insert into test_time values (to_timestamp(‘2000-1-1 0:0:0.123456789‘, ‘syyyy-mm-dd hh24:mi:ss.ff9‘));
 94
 95 已创建 1 行。
 96
 97 SQL> select to_char(col_time, ‘syyyy-mm-dd hh24:mi:ss.ff9‘) time, dump(col_time) dump_time
 98   2  from test_time;
 99
100 TIME                           DUMP_TIME
101 ------------------------------ ---------------------------------------------------
102  0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,101,1,1,1,1,1
103  2000-01-01 00:00:00.000000000 Typ=180 Len=7: 120,100,1,1,1,1,1
104  9999-12-31 23:59:59.999999000 Typ=180 Len=11: 199,199,12,31,24,60,60,59,154,198,24
105 -0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,99,1,1,1,1,1
106 -0100-03-04 13:02:03.234015000 Typ=180 Len=11: 99,100,3,4,14,3,4,13,242,201,24
107  2004-12-15 16:14:52.738000000 Typ=180 Len=11: 120,104,12,15,17,15,53,43,252,252,128
108  2000-01-01 00:00:00.123457000 Typ=180 Len=11: 120,100,1,1,1,1,1,7,91,205,232
109  2000-01-01 00:00:00.123456789 Typ=180 Len=11: 120,100,1,1,1,1,1,7,91,205,21
110 已选择8行。
时间: 2024-08-09 17:47:20

Oracle中的TIMESTAMP类型[转]的相关文章

对oracle中date/timestamp的操作

设置oracle中date的会话格式为 'yyyy-mm-dd hh24:mi:ss' alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; 设置oracle中timestamp的会话格式为 ‘yyyy-mm-dd hh24.mi.ss.ff’ alter session set nls_timestamp_format='yyyy-mm-dd hh24.mi.ss.ff'; c#中向oracle中插入date 可以直接操作日期数据

在JSP中获取oracle中的时间戳类型的字段并显示

在oracle中有一种特殊的时间显示类型——Timestamp时间戳 通常我们将当前时间转化为时间戳的语法如下: select cast (sysdate as timestamp ) from dual 在一个JSP页面中,需要获取一个时间戳字段,以显示在页面上 首先,是对JDBC的操作 sql语句用: select * from testlibrary 假设testlibrary中的modifydate字段的类型为TIMESTAMP(6) Testlibrary tlb= new Testl

Oracle中的字符串类型及相关函数详解

1.概述 本文介绍String类型及相关的函数,基于当前最新的Oracle 12c 为基础作介绍. 下文将字符串简称为串. Oracle函数的工作方式有两种: 1.根据旧的对象创建新的对象--他们对原来的信息进行修改,如改变字母的大小写. 2.告诉用户有关的信息,如一个单词或句子中有几个字符. 后续会更新另外两种处理文本的方式:Oracle中的正则表达式 和 Oracle Text工具,等文章编辑完成,会在此处添加链接. Oracle中主要有两种字符串类型:CHAR和VARCHAR2,他们以字母

0014-Hive中的Timestamp类型日期与Impala中显示不一致分析

温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看. 1.问题描述 Hive表中存储的Timestamp类型的字段显示日期与Impala中查询出来的日期不一致. 2.问题复现 1.创建一个简单的测试表 2.向表中插入一条测试数据 insert into date_test4 values(1,'1503751615','2017-08-26 08:46:55'); 获取当前系统时间存入表中: 3.通过Hive查询时间显示如下 select id,create_date_str,from

Oracle 中的Interger类型

引自 wolfAone, oracle有没有integer类型,这种类型的最大值是多少啊. Integer是Number类型的子类型: NUMBER Type You use the NUMBER datatype to store fixed or floating point numbers of virtually any size.  You can specify precision, which is the total number of digits, and scale, wh

oracle中的number类型

number 数据类型 number (precision,scale) a)    precision表示数字中的有效位,如果没有指定precision的话,oracle将使用38作为精度: b)    如果scale大于零,表示数字精度到小数点右边的位数:scale默认设置为0:如果scale小于零,oracle将把该数字取舍到小数点左边的指定位数. c)    Precision 的取值范围是[1-38];scale的取值范围是[-84-127]. d)    Number整数部分允许的长

oracle中关于clob类型字段的查询效率问题

今天,公司项目某个模块的导出报如下错误: HTTP Status 500 – Internal Server Error Type Exception Report Message Handler dispatch failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded Description The server encountered an unexpected condition

ORACLE中对LONG类型进行处理的方法

原文来自 Techfox IT技术论坛 1.在block中处理:不过PL/SQL代码只能处理不超过32K的数据,超过这个限制,就无法通过PL/SQL来处理. SQL> SET SERVEROUT ON SQL> BEGIN 2 FOR I IN (SELECT * FROM T_LONG) LOOP 3 IF INSTR(I.LONG_COL, 'WORLD') > 0 THEN 4 DBMS_OUTPUT.PUT_LINE(I.ID); 5 END IF; 6 END LOOP; 7

如何在Oracle中向Collection类型的变量中逐条插入数据

这篇文章将要介绍如果需要生成一个新的Collection并且向其中添加数据的方法. procedure insert_object(d in dept_array, d2 out dept_array) isbegin --First way to insert data into a new array. SELECT CAST(MULTISET (SELECT DNO, name, location FROM department_teststruct) AS dept_array) INT