时间类型转换函数

'Mon Aug 05 11:25:35 CST 2019'  类型转换成  2019-08-05 11:25:35

发现to_char和to_date也都不是那么理想,自己写一个吧。

 

Create function get_datetime(i varchar(255))
       returning varchar(255);
       define rec_time varchar(255);
       define rs_time varchar(255);
       define tmp_mon  varchar(255);
       define tmp_day  varchar(255);
       define tmp_year  varchar(255);
       define tmp_hour  varchar(255);
       let rec_time=i;

       set debug file to '/tmp/a.log';
       trace on;
       select  case   
           when substr(rec_time,5,3)='Jan' then '01'
           when substr(rec_time,5,3)='Feb' then '02'
           when substr(rec_time,5,3)='Mar' then '03'
           when substr(rec_time,5,3)='Apr' then '04'
           when substr(rec_time,5,3)='May' then '05'
           when substr(rec_time,5,3)='Jun' then '06'
           when substr(rec_time,5,3)='Jul' then '07'
           when substr(rec_time,5,3)='Aug' then '08'
           when substr(rec_time,5,3)='Sep' then '09'
           when substr(rec_time,5,3)='Oct' then '10'
           when substr(rec_time,5,3)='Nov' then '11'
           when substr(rec_time,5,3)='Dec' then '12' 
               end
       into tmp_mon from sysmaster:sysdual;
       select substr(rec_time,9,2) into tmp_day   from sysmaster:sysdual;
       select substr(rec_time,12,8) into tmp_hour from sysmaster:sysdual;
       select substr(rec_time,25,4) into tmp_year from sysmaster:sysdual;
       let rs_time=tmp_year||"-"||tmp_mon||"-"||tmp_day||" "||tmp_hour;

       return rs_time;
end function;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

请叫我曾阿牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值