CREATE OR REPLACE Function GetSumTime(InDT Number) Return VarChar2 is
Result VarChar2(40);
Begin
--已过期
If InDT <= 0 Then
Result := '已过期';
Else --核算 天 小时 分
--天
If InDT >= 1 Then
Result := Trunc(InDT)|| '天';
Else
Result := '';
End If;
--小时
If (InDT - Trunc(InDT)) * 24 >= 1 Then
Result := Result ||SubStr(To_Char( Trunc((InDT - Trunc(InDT)) * 24), '09'), 2, 2) ||'小时';
End If;
--分
If ((InDT - Trunc(InDT)) * 24 - Trunc((InDT - Trunc(InDT)) * 24)) * 60 >= 1 Then
Result := Result || SubStr(To_Char(Trunc(((InDT - Trunc(InDT)) * 24 - Trunc((InDT - Trunc(InDT)) * 24)) * 60), '09'), 2, 2) ||'分钟';
End If;
End If;
Return(Result);
End GetSumTime;
SELECT (TO_DATE(SubStr('2020-01-09', 1, 10)||' '||SubStr('14:00:00', 12, 8), 'yyyy-mm-dd hh24:mi:ss') - SysDate) ,
GetSumTime(TO_DATE(SubStr('2020-01-09', 1, 10)||' '||SubStr('14:00:00', 12, 8), 'yyyy-mm-dd hh24:mi:ss') - SysDate)
FROM dual;