今天写一个存储过程,需要对每个月的前五天做出判断,以便做出相应的处理.
函数如下
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博客 ” ,链接:https://blog.itpub.net/12216142/viewspace-531929/ ,如需转载,请注明出处,否则将追究法律责任。