欢迎各位兄弟 发布技术文章
这里的技术是共享的
函数
create or replace function lastWorkDay_fun(date_p date)
return number
as
last_day_pf date;
week_pf number;
day_of number;
begin
select LAST_DAY(date_p) into last_day_pf from dual;
select to_char(last_day_pf,'dd') into day_of from dual;
select to_char(last_day_pf,'d') into week_pf from dual;
loop
exit when week_pf='1' or week_pf='7';
select last_day_pf-1 into last_day_pf from dual;
select to_char(last_day_pf,'dd') into day_of from dual;
select to_char(last_day_pf,'d') into week_pf from dual;
end loop;
return TO_NUMBER(day_of);
end;
调用语句块
declare
day_date date :=to_date('2020-08-05','yyyy-mm-dd');
begin
dbms_output.put_line(lastWorkDay_fun(day_date));
end;