計算Oracle兩個TIMESTAMP相差的毫秒數

來源:互聯網
上載者:User

CREATE OR REPLACE FUNCTION uf_timestamp_diff(endtime in TIMESTAMP,starttime in TIMESTAMP)

RETURN INTEGER

AS

 str VARCHAR2(50);

 misecond INTEGER;

 seconds INTEGER;

 minutes INTEGER;

 hours INTEGER;

 days INTEGER;

BEGIN

 str:=to_char(endtime-starttime);

 misecond:=to_number(SUBSTR(str,INSTR(str,' ')+10,3));

 seconds:=to_number(SUBSTR(str,INSTR(str,' ')+7,2));

 minutes:=to_number(SUBSTR(str,INSTR(str,' ')+4,2));

 hours:=to_number(SUBSTR(str,INSTR(str,' ')+1,2));

 days:=to_number(SUBSTR(str,1,INSTR(str,' ')));


 RETURN days*24*60*60*1000+hours*60*60*1000+minutes*60*1000+seconds*1000+misecond;

END;

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.