Fast and dirty hack:
create or replace FUNCTION calc_length(START_TIME number,
FINISH_TIME number)
RETURN VARCHAR2 IS
result varchar2(30);
lhs_start number(2) := FLOOR(START_TIME / 100);
lhs_finish number(2) := FLOOR(FINISH_TIME / 100);
rhs_start number(2) := (START_TIME / 100 - FLOOR(START_TIME / 100)) * 100;
rhs_finish number(2) := (FINISH_TIME / 100 - FLOOR(FINISH_TIME / 100)) * 100;
BEGIN
if (rhs_finish - rhs_start) > 0 then
result := to_char(lhs_finish - lhs_start) || ' hours ' ||
to_char(rhs_finish - rhs_start) || ' minutes';
else
result := to_char(lhs_finish - lhs_start - 1) || ' hours ' ||
to_char(rhs_finish - rhs_start + 60) || ' minutes';
end if;
return result;
END calc_length;
NOTE: I updated the code to handle negative minute intervals, but I have to warn that the whole approach is totally wrong. To calculate time intervals it is better to use appropriate datatypes (datetime
or interval
).