create or replace package PKG_GENERAL is
TYPE ROW_CURSOR IS REF CURSOR;
–返回指定日期的月份中有多少天
function daysInMonth(rq date) return number;
–返回指定日期离月底还有多少天
function daysLeft(rq date) return number;
–返回指定日期离年底还有多少天
function daysLeftOfYear(rq date) return number;
–返回指定日期当年有多少天
function daysOfYear(rq date) return number;
end PKG_GENERAL;
create or replace package body PKG_GENERAL is
–select extract(day from sysdate) year from dual 返回日期中指定的年月日 如:年2006 月7 日30
function daysInMonth
(rq in date)
return number
as
daysOfMonth number(2);
begin
select (last_day(trunc(rq))-trunc(rq,‘Month’)+1) into daysOfMonth from dual;
return daysOfMonth;
end daysInMonth;
–返回指定日期离月底还有多少天
function daysLeft
(rq in date)
return number
as
dl number(2);
begin
select last_day(trunc(rq))-trunc(rq) into dl from dual;
return dl;
end daysLeft;
–返回指定日期离年底还有多少天
function daysLeftOfYear
(rq date)
return number
as
dys number(3);
tempDate date :=add_months(rq,1);
begin
dys:=daysLeft(rq);
while to_char(tempDate,‘yyyy’)=to_char(rq,‘yyyy’) loop
dys:=dys+daysInMonth(tempDate);
tempDate:=add_months(tempDate,1);
end loop;
return dys;
end daysLeftOfYear;
–返回指定日期当年的天数
function daysOfYear(rq date)
return number
as
dys number(3);
tempDate date :=add_months(trunc(rq,‘yyyy’),1);
begin
dys:=daysLeft(trunc(rq,‘yyyy’));
while to_char(tempDate,‘yyyy’)=to_char(rq,‘yyyy’) loop
dys:=dys+daysInMonth(tempDate);
tempDate:=add_months(tempDate,1);
end loop;
return dys+1;
end daysOfYear;
end PKG_GENERAL;
需要了解更多数据库技术:Oracle 存储过程 游标及计算天数的函数,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。
如若转载,请注明出处:https://www.ctvol.com/dtteaching/795926.html