一個自定義函式

lnwxzyp發表於2009-01-08

今天寫一個儲存過程,需要對每個月的前五天做出判斷,以便做出相應的處理.
函式如下
create or replace function p_return_date
 return number
as
p_d1 date;
p_d2 date;
p_d3 date;
p_d4 date;
p_d5 date;
p_n  number;
begin
 select trunc(sysdate) into p_d1 from dual;
 select trunc(sysdate,'mm')+1 into p_d2 from dual;
 select trunc(sysdate,'mm')+2 into p_d3 from dual;
 select trunc(sysdate,'mm')+3 into p_d4 from dual;
 select trunc(sysdate,'mm')+4 into p_d5 from dual; 
 if p_d1=p_d2 then
    select 2 into p_n from dual;
 elsif p_d1=p_d3 then
    select 3 into p_n from dual;
 elsif p_d1=p_d4 then
    select 4 into p_n from dual;
 elsif p_d1=p_d5 then
    select 5 into p_n from dual;
 else
    select 1 into p_n from dual;
 end if;
 return p_n;
end;
將系統時間調到1月 2,3,4,5號均得到相應的返回值,測試完成.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12216142/viewspace-531929/,如需轉載,請註明出處,否則將追究法律責任。

相關文章