oracle 日期和时间转换

1、timestamp与字符串转换

timestamp转字符串:select to_char(t.timestamp,'yyyy-mm-dd HH24:mi:ss.ff') from tb_a t

 字符串转timestamp:update tb_a t set t.timestamp=to_timestamp('2012-12-12 12:12:12.0','yyyy-mm-dd hh24:mi:ss.ff')  where t.id='1'

2、date与字符串转换

select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual   //显示:08-11-07 13:22:42

select to_date('2005-12-25,13:25:59','yyyy-mm-dd hh24:mi:ss') from dual //显示:2005-12-25 13:25:59

3、hh24:mi:ss.ff 

 

ff后面的数字表示 秒后面的小数位

 

--查询当前系统日期:
Oracle: select to_char(sysdate, 'yyyy-mm-dd') from dual;
Mysql:select current_date();或者 select curdate();
--查询当前系统时间:
Oracle: select to_char(sysdate, 'hh24:mi:ss') from dual;
Mysql: select curtime();或者 select current_time();
--查询系统日期和时间:
Oracle: select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
Mysql: select sysdate(); 或者 select now();
--时间戳:
Oracle: select systimestamp from dual;
Mysql: select current_timestamp()

 

 4、oracle数据库 TIMESTAMP(6)时间戳类型

--时间戳类型,参数6指的是表示秒的数字的小数点右边可以存储6位数字,最多9位。由于时间戳的精确度很高,我们也常常用来作为版本控制。插入时,如下方式:
insert into test4 values(to_timestamp('2019-7-19 23:23:23.112324233','yyyy-mm--dd hh24:mi:ss.ff'));

 5、更新时间字段提示无效月份异常 

update  tableA  set yd_created_date=to_date('2024-03-28 12:59:59','yyyy-MM-dd hh24:mi:ss') where yd=xx

 

posted on 2020-09-14 10:14  小破孩楼主  阅读(3374)  评论(0编辑  收藏  举报