------------------------------------------------------------------------------------------------------------------------------------------
date类型:
时间戳格式:
SQL> desc t100;
Name Null? Type
----------------------------------------- -------- ----------------------------
STARTTIME DATE
ENDTIME DATE
create table t100(starttime date, endtime date);
insert into t100 values(to_date('2018-04-11 18:00:07', 'yyyy-mm-dd hh24:mi:ss'),to_date('2018-04-11 18:00:15', 'yyyy-mm-dd hh24:mi:ss'));
CREATE OR REPLACE FUNCTION esbtimediff(t1 timestamp,
t2 timestamp)
return number is
BEGIN
if (length(t1)!=0 and length(t2)!=0) then
return TO_NUMBER(substr(substr((T1-T2),15,9),0,2))*60*1000 + TO_NUMBER(substr(substr(T1-T2,15,9),4))*1000;
else
return 0;
end if;
end;
SQL> select starttime,endtime ,esbtimediff(endtime,starttime) from t100;
STARTTIME ENDTIME ESBTIMEDIFF(ENDTIME,STARTTIME)
------------------- ------------------- ------------------------------
2018-04-11 18:00:07 2018-04-11 18:00:15 8000
varchar2型:
SQL> select starttime,endtime ,esbtimediff(to_date(endtime,'yyyy-mm-dd hh24:mi:ss'),to_date(starttime,'yyyy-mm-dd hh24:mi:ss')) from t200;
STARTTIME ENDTIME
------------------------------------------------------------ ------------------------------------------------------------
ESBTIMEDIFF(TO_DATE(ENDTIME,'YYYY-MM-DDHH24:MI:SS'),TO_DATE(STARTTIME,'YYYY-MM-DDHH24:MI:SS'))
----------------------------------------------------------------------------------------------
2018-04-11 18:00:07 2018-04-11 18:00:15
8000