Oracle对象上的成员函数错误(17,5):PLS-00103:遇到符号" AWARDSTAR"期待以下之一时:if

时间:2015-03-16 16:38:52

标签: oracle plsql

我正在尝试创建一个成员函数,该奖章将授予监督一定数量员工并具有一定年经验的主管。然而,我一直得到标题中提到的错误任何帮助将不胜感激,因为我对此有点新鲜。

这是我的创造类型声明

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;

1 个答案:

答案 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吗?