1 Declare2 3L_start Date:=To_date ('2015-04-29 01:02:03','YYYY-MM-DD Hh24:mi:ss');4L_end Date:=To_date ('2015-05-15 11:22:33','YYYY-MM-DD Hh24:mi:ss');5 6L_ym interval Year to Month;7L_ds interval Day tosecond;8L_year Number;9L_month Number;TenL_day Number; OneL_hour Number; AL_minute Number; -L_second Number; -L_strvarchar2( -); the begin -L_ym:=Numtoyminterval (Trunc (Months_between (L_end, L_start)),'Month'); -L_ds:=Numtodsinterval (l_end- - add_months (L_start, + trunc (Months_between (l_end, L_start )), - ' Day'); + A SelectExtract Year fromL_YM), Extract (Month fromL_ym) at intoL_year, L_month - fromdual; - - SelectExtract Day froml_ds), -Extract (Hour froml_ds), -Extract (minute froml_ds), inExtract (second fromL_ds) - intoL_day, L_hour, L_minute, L_second to fromdual; + -L_STR:=Lpad (To_char (l_year),4,'0')|| 'years' || theLpad (To_char (L_month),2,'0')|| 'Month' || *Lpad (To_char (L_day),2,'0')|| 'days' || ' ' || $Lpad (To_char (L_hour),2,'0')|| ':' ||Panax NotoginsengLpad (To_char (L_minute),2,'0')|| ':' || -Lpad (To_char (L_second),2,'0'); the + Dbms_output.put_line (L_STR); A the End;
Oracle database time difference years, months, days, hours, minutes, seconds