溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Oracle計(jì)算時(shí)間跨度的函數(shù)

發(fā)布時(shí)間:2020-07-05 16:55:04 來(lái)源:網(wǎng)絡(luò) 閱讀:366 作者:易仔阿克 欄目:關(guān)系型數(shù)據(jù)庫(kù)

顯示距離當(dāng)前時(shí)間的跨度

-- 計(jì)算時(shí)間跨度:返回值為X天y時(shí)z分

declare

  ln_day_count      number(10);

  ln_hour_count     number(10);

  ln_min_count      number(10);

  ls_time_sent_last varchar2(20) := '2015-06-07 08:40:20';

  ls_timespan varchar2(100) := '';

begin 

  -- 計(jì)算天數(shù)

  select floor(sysdate - To_date(ls_time_sent_last, 'yyyy-mm-dd hh34-mi-ss'))  into ln_day_count FROM dual;

  if ln_day_count != 0 then

    ls_timespan := to_char(ln_day_count) || '天';

    dbms_output.put_line(ls_timespan);

  end if;

  -- 計(jì)算小時(shí)數(shù)

  select mod(floor(((sysdate - To_date(ls_time_sent_last, 'yyyy-mm-dd hh34-mi-ss'))) * 24),24) into ln_hour_count FROM dual;

  if ln_hour_count != 0 then

    ls_timespan := ls_timespan || to_char(ln_hour_count) || '時(shí)';

    dbms_output.put_line(ls_timespan);

  end if;

  -- 計(jì)算分鐘數(shù)

  select mod(mod(floor(((sysdate - To_date(ls_time_sent_last, 'yyyy-mm-dd hh34-mi-ss'))) * 24 * 60),24*60),60) into ln_min_count FROM dual;

  if ln_min_count != 0 then

    ls_timespan := ls_timespan || to_char(ln_min_count) || '分';

    dbms_output.put_line(ls_timespan);

  end if;

end; 



向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI