该程序是创建一个包计数的。员工根据组织的位置休假的数量。例如:- 如果 XYZ 公司是一家位于许多地点的公司。每个地点都有自己的一套规则……在某些地点,周六工作,而在某些地点,周六和周日都被视为假期。我制作了如下包装,但我认为它可以变得更容易。
Create or replace package Body
Leave_location
Procedure Leave_location_proc(Person_id number,
Start_date Date
)
as
k Number;
count_weekend number;
Cursor c_var
is
select pt.person_id,
lt.end_date-lt.start_date Number_of_leaves_excluding_the_end_date,
lt.Start_date //Start leave date,
lt.Saturday // 1 if saturday is not working, null if working
lt.Sunday ,
loc.location_id
from person_table pt,
leave_table lt
and leave_table.person_id=person_table.person_id
and loc.location_id=pt.person_id \\filtering the location for the particular employee;
Begin
Count_weekend :=0;
for cursor_var in c_var
k :=cursor_var.Number_of_leaves_excluding_the_end_date+1
loop
for i in..k
loop
if(to_char(cursor_var.start_date,'DY') in ('Sat','Sun')
Then
if(cursor_var.Saturday is not null and cursor_var.sunday is not null))
Then
Count_weekend :=2;
Else
count_weekend :=1;
end if ;
end if;
cursor_var.Start_date :=cursor_var.Start_date+1;
No_of_leaves :=K-Count_weekends;
Count_weekends:=Count_weekends+1;
end loop;
end loop;
End Leave_location;
Leave_location_proc;
这段代码似乎效率不高。还有更好的方法