nacasc_181696
nacasc_181696

Reputation: 11

Error Message-PLS-00103: Encountered the symbol "LOOP" when expecting one of the following: if

I'm attempting to create a procedure that updates a students grade and will insert the grade into a grades table. I'm pulling from a different table, the course table, to get the information I need. If the course_name ends with a certain letter, a grade is assigned which is then inserted into Grade in the grades table. Here's what I have:

create or replace procedure grade is
  assign_grade varchar2(1);
  assign_class varchar2(30);

  cursor c1 is
  select course_name from course;

begin

  for assign_class in c1
  loop

    if (assign_class.course (substr(course_name, -1, 1) between 'A' and 'F')) then
      assign_grade.grades :='A';

    else if
      (assign_class.course (substr(course_name, -1, 1) between 'G' and 'K')) then assign_grade.grades :='B';

    else if
      (assign_class.course (substr(course_name, -1, 1) between 'L' and 'P')) then assign_grade.grades :='C';

    else if
      (assign_class.course (substr(course_name, -1, 1) between 'Q' and 'T')) then assign_grade.grades :='D';

    else if
      assign_class.course (substr(course_name, -1, 1) between 'U' and 'Z')) then assign_grade.grades :='E';

    end if;

  end loop;

  dbms_output.put_line('students grade is: ' || s_grade);

end;

My issue is I'm getting the error message posted in the title. There's an issue with my loop, but I can't pinpoint what. I'm not sure if I'm not inserting the data correctly in the look and that's the issue.

Any help is appreciated. Thanks.

Upvotes: 1

Views: 181

Answers (1)

Aman Singh Rajpoot
Aman Singh Rajpoot

Reputation: 1479

Wrong else if syntax.

CREATE OR REPLACE PROCEDURE grade
IS

assign_grade varchar2(1);
assign_class varchar2(30);

CURSOR c1 is
select course_name from course;

BEGIN

FOR assign_class in c1
LOOP

IF
(assign_class.course (Substr(course_name, -1, 1) between 'A' and 'F')) THEN assign_grade.grades :='A';

ELSIF
(assign_class.course (Substr(course_name, -1, 1) between 'G' and 'K')) THEN
 assign_grade.grades :='B';

ELSIF
(assign_class.course (Substr(course_name, -1, 1) between 'L' and 'P')) THEN
assign_grade.grades :='C';

ELSIF
(assign_class.course (Substr(course_name, -1, 1) between 'Q' and 'T')) 
THEN
assign_grade.grades :='D';

ELSIF
assign_class.course (Substr(course_name, -1, 1) between 'U' and 'Z')) 
THEN
assign_grade.grades :='E';



END IF;

END LOOP;

DBMS_OUTPUT.PUT_LINE('students grade is: ' || s_grade);

END;

Upvotes: 2

Related Questions