oracle中没有datediff()函数
来源:互联网 发布:淘宝店能卖图片吗 编辑:程序博客网 时间:2024/04/29 15:40
在oracle中没有datediff()函数
可以用以下方法在oracle中实现该函数的功能:
1.利用日期间的加减运算
天:
ROUND(TO_NUMBER(END_DATE - START_DATE))
小时:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24)
分钟:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60)
秒:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60)
毫秒:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60 * 60)
2.写函数
Create Or Replace Function CDate(Datechar In Varchar2) Return Date Is
ReallyDo Date;
Begin
Select to_date(to_char(to_date(to_char(Datechar), 'YYYY-MM-DD HH24:MI:SS'),
'YYYY-MM-DD'),
'YYYY-MM-DD')
Into ReallyDo
From Dual;
Return(ReallyDo);
End CDate;
Create Or Replace Function CDateTime(Datechar In Varchar2) Return Date Is
ReallyDo Date;
Begin
Select to_date(to_char(to_date(to_char(Datechar), 'YYYY-MM-DD HH24:MI:SS'),
'YYYY-MM-DD HH24:MI:SS'),
'YYYY-MM-DD HH24:MI:SS')
Into ReallyDo
From Dual;
Return(ReallyDo);
End CDateTime;
Create Or Replace Function Datediff
(
Datepart In Varchar2,
StartDate In Varchar2,
EndDate In Varchar2
) Return Number Is
ReallyDo Numeric;
Begin
Select Case Upper(Datepart)
When 'YYYY' Then
Trunc(Extract(Year From CDate(EndDate)) -
Extract(Year From CDate(StartDate)))
When 'M' Then
Datediff('YYYY', StartDate, EndDate) * 12 +
(Extract(Month From CDate(EndDate)) -
Extract(Month From CDate(StartDate)))
When 'D' Then
Trunc(CDate(EndDate) - CDate(StartDate))
When 'H' Then
Datediff('D', StartDate, EndDate) * 24 +
(to_Number(to_char(CDateTime(EndDate), 'HH24')) -
to_Number(to_char(CDateTime(StartDate), 'HH24')))
When 'N' Then
Datediff('D', StartDate, EndDate) * 24 * 60 +
(to_Number(to_char(CDateTime(EndDate), 'MI')) -
to_Number(to_char(CDateTime(StartDate), 'MI')))
When 'S' Then
Datediff('D', StartDate, EndDate) * 24 * 60 * 60 +
(to_Number(to_char(CDateTime(EndDate), 'SS')) -
to_Number(to_char(CDateTime(StartDate), 'SS')))
Else
-29252888
End
Into ReallyDo
From Dual;
Return(ReallyDo);
End Datediff;
- oracle中没有datediff()函数
- SQLSERVER 中DATEDIFF函数
- 在oracle中实现DateDiff函数的功能
- VB中DateDiff 函数解释
- Oracle日期函数dayadd/datediff/datepart
- DateDiff 函数
- DateDiff 函数
- DateDiff 函数
- DateDiff 函数
- DateDiff 函数
- datediff函数
- DateDiff 函数
- DateDiff函数
- DateDiff函数
- DateDiff 函数
- DateDiff()函数
- DateDiff函数
- DateDiff 函数
- 1 spring--IOC(控制反转,依赖注入)
- 更改表数据类型:ORA-01439:要更改数据类型,则要修改的列必须为空
- JavaScript——作用域
- Access截取时间
- Qt的控制台程序
- oracle中没有datediff()函数
- Leveldb源码分析--17
- 如何portingADSP中的sensor
- 春节你回家么?
- vim 中替换已有的字符
- BZOJ 1008 越狱 组合数学
- Access函数大全
- 被捧杀的小程序,高潮之后该冷静一下了
- Mybatis的参数