方法1: from_unixtime+ unix_timestamp
--20171205转成2017-12-05
select from_unixtime(unix_timestamp('20171205','yyyymmdd'),'yyyy-mm-dd') from dual;
--2017-12-05转成20171205
select from_unixtime(unix_timestamp('2017-12-05','yyyy-mm-dd'),'yyyymmdd') from dual;
方法2: substr + concat
--20171205转成2017-12-05
select concat(substr('20171205',1,4),'-',substr('20171205',5,2),'-',substr('20171205',7,2)) from dual;
--2017-12-05转成20171205
select concat(substr('2017-12-05',1,4),substr('2017-12-05',6,2),substr('2017-12-05',9,2)) from dual;
本文介绍两种在数据库中进行日期格式转换的方法:使用from_unixtime和unix_timestamp组合,以及利用substr和concat函数。这两种方法可以帮助你将日期从'yyyymmdd'格式转换为'yyyy-mm-dd'格式,反之亦然。

1万+

被折叠的 条评论
为什么被折叠?



