1. 程式人生 > >Oracle將時分秒格式的字串轉換為秒進行計算

Oracle將時分秒格式的字串轉換為秒進行計算

        最近的需求中一個日期格式為'時分秒'且該欄位的資料型別是字串,然後需要計算總的時間,於是想了想,在sql中這樣處理可達到我想要的效果,程式碼如下

 select (hours+minutes+seconds) AS total_seconds from(
     select to_number(substr('00:12:20',0,2))*60*60 AS hours,
        to_number(substr('00:12:20',4,2))*60 AS minutes, 
        to_number(substr('00:12:20',7,2)) AS seconds  from dual
 )