首页 > 数据库技术 > 详细

oracle日期时间型timestamp的深入理解

时间:2015-10-22 15:44:55      阅读:216      评论:0      收藏:0      [点我收藏+]

我们都知道date和timestamp都是对日期和时间的表示,只是两种类型的精确度不同,前者精确到秒,后者精确到小数秒,可以是 0 to 9,缺省是6。
下面对timestamp函数进行了详细的分析介绍。

1、字符型转成timestamp

  1. select to_timestamp(‘01-10月-15 07.46.41.000000000 上午‘,‘dd-MON-yy hh:mi:ss.ff AM‘)   from dual;

技术分享 

2、timestamp转成date型

select cast(to_timestamp(‘01-10月-15 07.46.41.000000000 上午‘,‘dd-MON-yy hh:mi:ss.ff AM‘) as date) timestamp_to_date from dual;

技术分享 

3、date型转成timestamp

select cast(sysdate as timestamp) date_to_timestamp  from dual;

技术分享 

4、获取timestamp格式的系统时间

select systimestamp from dual;

技术分享 

5、两date的日期相减得出的是天数,而两timestamp的日期相减得出的是完整的年月日时分秒小数秒

select systimestamp-systimestamp from dual;  
select sysdate-sysdate from dual;

注:timestamp要算出两日期间隔了多少秒,要用函数转换一下。

原文地址:http://bbs.delit.cn/thread-170-1-1.html

转载请注明出处:

撰写人:度量科技http://www.delit.cn

oracle日期时间型timestamp的深入理解

原文:http://delit.blog.51cto.com/5487020/1705233

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!