--返回两个日期人可以直接看懂的时间差(格式:1天6小时13分钟37秒)
create or replace function fn_tm(p_end_time in date, p_start_time in date)
  return varchar2 is
  v_result varchar2(200);
  v_day  varchar2(200) := 0;
  v_time varchar2(200) := 0;
begin
  select trunc(p_end_time - p_start_time) into v_day from dual;
  select to_char(to_date(trunc(((p_end_time - p_start_time) -
                               trunc(p_end_time - p_start_time)) * 86400),
                         'SSSSS'),
                 'fmhh24"小时"mi"分钟"ss"秒"')
    into v_time
    from dual;
  if v_day is null or v_time is null then
    return '';
  end if;
  v_result := v_day || '天' || v_time;
  return v_result;
end;