Oracle计算时间差表达式

上一篇 / 下一篇  2009-02-10 22:07:16 / 个人分类:Oracle

  • 文件版本: V1.0
  • 开发商: 本站原创
  • 文件来源: 本地
  • 界面语言: 简体中文
  • 授权方式: 免费
  • 运行平台: Win9X/Win2000/WinXP
--获取两时间的相差豪秒数51Testing软件测试网(VgMTy Q
select ceil((To_date('2008-05-02 00:00:00' , 'yyyy-mm-dd hh24-mi-ss') - To_date('2008-04-30 23:59:59' , 'yyyy-mm-dd hh24-mi-ss')) * 24 * 60 * 60 * 1000) 相差豪秒数 FROM DUAL;51Testing软件测试网:x.]0H8|6bLM;x {
/*51Testing软件测试网'VH"l7a9n+_P
相差豪秒数
)K{ K1Gi&p/a5I0----------
!A(r]6QJ$h+a0  86401000
K'MM mv1B01 row selected
j{RxK0
*/
i~+H#r"cq#k3_8b h8J0
%PxdaX@:KO0
--获取两时间的相差秒数51Testing软件测试网rO5Q d/R`l8^X\u
select ceil((To_date('2008-05-02 00:00:00' , 'yyyy-mm-dd hh24-mi-ss') - To_date('2008-04-30 23:59:59' , 'yyyy-mm-dd hh24-mi-ss')) * 24 * 60 * 60) 相差秒数 FROM DUAL;
vU`U'zcO0
/*
;F]]5Ea+l(d SC0相差秒数
'zz5Xv0TIvi"y0----------51Testing软件测试网}@1ECo%_.j
     8640151Testing软件测试网 j"IGFV H[p
1 row selected51Testing软件测试网4Nh)~Pia
*/51Testing软件测试网Y,N/q o P7q@Bm

kq8j&nO0s9e0
--获取两时间的相差分钟数
B4bpL,IjR ]oM0
select ceil(((To_date('2008-05-02 00:00:00' , 'yyyy-mm-dd hh24-mi-ss') - To_date('2008-04-30 23:59:59' , 'yyyy-mm-dd hh24-mi-ss'))) * 24 * 60)  相差分钟数 FROM DUAL;51Testing软件测试网(}~*p&|qkc)k(r
/*51Testing软件测试网s2}R W,vw
相差分钟数51Testing软件测试网 p |H2d6Tl!e
----------51Testing软件测试网$^.IJeQEQvQ8u
      1441
{9|-vb e4s)_w!u*jv01 row selected
KXI w}0
*/
7XtNK.o L&C051Testing软件测试网t.x X&LK4F3j
--获取两时间的相差小时数51Testing软件测试网0`E1N8H|3Dt `3X
select ceil((To_date('2008-05-02 00:00:00' , 'yyyy-mm-dd hh24-mi-ss') - To_date('2008-04-30 23:59:59' , 'yyyy-mm-dd hh24-mi-ss')) * 24)  相差小时数 FROM DUAL;
-W,x^[:_0
/*51Testing软件测试网_9|9Iw1T;W7\"t
相差小时数51Testing软件测试网%T.c(gc3Y;CQ&Z2Fl
----------
&O3Mr;SV0        2551Testing软件测试网!c#Ls(a7`&a8t }u{ i*C
1 row selected51Testing软件测试网pr@a P&V
*/
6g3N)UOj051Testing软件测试网Iep;@v IL
--获取两时间的相差天数51Testing软件测试网4hf~PUyg%}6b0F_
select ceil((To_date('2008-05-02 00:00:00' , 'yyyy-mm-dd hh24-mi-ss') - To_date('2008-04-30 23:59:59' , 'yyyy-mm-dd hh24-mi-ss')))  相差天数 FROM DUAL;
j0e { ^r8`S0
/*51Testing软件测试网AY"~!C!} X:kp/y5I
相差天数51Testing软件测试网!W6u`*t*s
----------51Testing软件测试网0g!?!@}H]
         2
hRq~N _3nI01 row selected
m_Mr0?3U-?0
*/
$~8bA]wn wF051Testing软件测试网!~6D3~5O0L
--获取两时间月份差
N#o,n0` g9o}6Oa/R&y0
select (EXTRACT(year FROM to_date('2009-05-01','yyyy-mm-dd')) - EXTRACT(year FROM to_date('2008-04-30','yyyy-mm-dd'))) * 12 +
*HA N&]-p$f$`%Kazw0       EXTRACT(
month FROM to_date('2008-05-01','yyyy-mm-dd')) - EXTRACT(month FROM to_date('2008-04-30','yyyy-mm-dd')) months51Testing软件测试网;p v]{,y0\
from dual;
"op{:R ^$m0gpQ0
/* MONTHS---------- 131 row selected */51Testing软件测试网"E3P~6SI.k @
51Testing软件测试网kp.HhE
--获取两时间年份差
5oP*E1o:|*T8^un0
select EXTRACT(year FROM to_date('2009-05-01','yyyy-mm-dd')) - EXTRACT(year FROM to_date('2008-04-30','yyyy-mm-dd')) years from dual;51Testing软件测试网W'o#Ex5u6u
/*
l&r7Z1bpY0YEARS
(CX:dRBs0----------51Testing软件测试网 Ax+]Xr%|A
         1
G-zHIC:P2kJ01 row selected
_.W!o | u4[Fp l0
*/

TAG: Oracle

 

评分:0

我来说两句

Open Toolbar