Oracle 儲存過程 游標及計算天數的函式

2021-10-08 16:09:51 字數 1855 閱讀 9991

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

asdaysofmonth 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

asdl number(2);

begin

select last_day(trunc(rq))-trunc(rq) into dl from dual;

return dl;

end daysleft;

–返回指定日期離年底還有多少天

function daysleftofyear

(rq date)

return number

asdys 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

asdys 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儲存過程,游標

oracle儲存過程,游標 2010 07 07 13 01 create or replace procedure p tb task log is 功能 插入任務到任務日誌表 v task start date date v task end date date v sql code numbe...

oracle 儲存過程 游標

create or replace procedure exception3 as 使用者自定義異常 e too high sal exception 宣告自定義異常 v sal employees.salary type begin select salary into v sal from em...

oracle儲存過程及游標使用例項

create or replace procedure t table count test as v tablename varchar2 50 v count integer str sql varchar2 200 從all tables裡面獲取的所有表的表名稱,儲存在游標內 cursor m...