2014-05-05 67 views

回答

1

首先,你需要你的時間轉換爲正確的數據類型,然後提取EPOCH得到秒。

select 
extract (EPOCH from to_timestamp(to_char(current_date,'YYYY-MM-DD') 
||' '||sample.dt_str,'YYYY-MM-DD MI:SS')-current_date) 
from 
(
     select '01:23' as dt_str 
) sample 

另外,如果你安裝了SQL Functions Toolkit,你可以簡單地運行它。

select sql_functions.admin.second ('01:01:23') 
0
select '1:23' aTime, position(':' in aTime) pos, 
    cast(substring(aTime from 1 for (pos-1)) as int)*3600 HR, 
    cast(substring(aTime from (pos+1)) as int) * 60 mins, 
    hr+mins secs