我正在尝试创建一个成员函数,该奖章将授予监督一定数量员工并具有一定年经验的主管。然而,我一直得到标题中提到的错误任何帮助将不胜感激,因为我对此有点新鲜。
这是我的创造类型声明
create type employeeType under peopleType
(empID int,
supervisorID ref employeeType,
pos varchar2(20),
salary number(8,2),
bID ref branchType,
joinDate date,
member function awardStar(stars varchar2) return varchar2);
这是我创造的类型 - 身体声明
create or replace type body employeeType as
member function awardStar(stars varchar2)
return varchar2
is
medal varchar2;
years number;
emps number;
begin
select count (*)
into emps
from employee e
where Deref(e.supervisorID).empID = self.empID;
years := trunc(months_between(sysDate,self.joinDate))/12;
if years > 12 and emps > 6 then
medal := 'Gold Medal';
else if years > 6 and emps > 3 then
medal := 'Silver Medal';
else if years > 4 then
medal := 'Brown Medal';
end if;
return medal;
end awardStar;
end;
答案 0 :(得分:2)
问题是,当您真正打算使用else if
时,您已使用elsif
。您需要为每个子项添加end if
个,或者更正拼写错误。
我建议:
create or replace type body employeeType as
member function awardStar(stars varchar2)
return varchar2
is
medal varchar2;
years number;
emps number;
begin
select count(*)
into emps
from employee e
where Deref(e.supervisorID).empID = self.empID;
years := trunc(months_between(sysDate,self.joinDate))/12;
if years > 12 and emps > 6 then
medal := 'Gold Medal';
elsif years > 6 and emps > 3 then
medal := 'Silver Medal';
elsif years > 4 then
medal := 'Brown Medal';
end if;
return medal;
end awardStar;
end;
/
P.S。 Brown Medal
?您的意思是Bronze Medal
吗?