1、创建测试表,
create table test_date_conv(id varchar2(20),v_date varchar2(200));
2、插入测试数据;
insert into test_date_conv values(1, 20190101122359);
insert into test_date_conv values(2, 20190115132359);
insert into test_date_conv values(3, 20190125052359);
insert into test_date_conv values(4, 20190125122359);
insert into test_date_conv values(5, 2019013119359);
commit;
3、查询表中全量数据;select t.*, rowid from test_date_conv t;
4、编写语句,转换成成YYYY-MM-DD HH:mm:ss格式;
select t.*, to_char(to_date(v_date,'yyyymmddhh24miss'),'yyyy-mm-dd hh24:mi:ss') v2 sec from test_date_conv t;
select to_char(to_date('20150413090101','yyyymmddhh24miss'),'yyyy-mm-dd hh24:mi:ss') from dual
substr(a,9, 2) || ':' || substr(a,11, 2) || ':' || substr(a,13, 2)
from dual
select to_date('20150413092155','yyyy-mm-dd hh24:mi:ss') from dual
谢谢,如果要是转换成YYYY-MM-DD HH:mm 格式就应该是to_date('20150413092155','yyyy-mm-dd hh24:mi')的吧?但是我用上以后实际效果就成这样了“2015-03-24 17:25:00.0”,数据库里的数据是“201503241725”,怎么把做后的00.0s去掉呢?
广告 您可能关注的内容 |