Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PLS-00103: Encountered the symbol ";" when expecting one of the following:

what is wrong in my code

    SQL> declare
  2  mark number :=50;
  3  begin
  4  mark :=& mark;
  5  if (mark between 85 and 100)
  6  then
  7  dbms_output.put_line('mark is A ');
  8  else if (mark between 50 and 65) then
  9  dbms_output.put_line('mark is D ');
 10  else if (mark between 66 and 75) then
 11  dbms_output.put_line('mark is C ');
 12  else if (mark between 76 and 84) then
 13  dbms_output.put_line('mark is B');
 14  else 
 15  dbms_output.put_line('mark is F');
 16  end if;
 17  end;
 18  /
Enter value for mark: 65
old   4: mark :=& mark;
new   4: mark :=65;
end;
   *

ERROR at line 17: ORA-06550: line 17, column 4: PLS-00103: Encountered the symbol ";" when expecting one of the following: if

like image 520
Moh-ksa Madinah Avatar asked Nov 18 '13 21:11

Moh-ksa Madinah


2 Answers

The problem is that the else and if are two operators here. Since you open a new 'if' you need a corresponding 'end if'.

Thus:

declare
mark number :=50;
begin
  mark :=& mark;
  if (mark between 85 and 100) then
    dbms_output.put_line('mark is A ');
  else 
    if (mark between 50 and 65) then
      dbms_output.put_line('mark is D ');
    else 
      if (mark between 66 and 75) then
        dbms_output.put_line('mark is C ');
      else 
        if (mark between 76 and 84) then
          dbms_output.put_line('mark is B');
        else 
          dbms_output.put_line('mark is F');
        end if;
      end if;
    end if;
  end if;
end;
/

Alternatively you can use elsif:

declare
mark number :=50;
begin
  mark :=& mark;
  if (mark between 85 and 100)
    then
    dbms_output.put_line('mark is A ');
  elsif (mark between 50 and 65) then
    dbms_output.put_line('mark is D ');
  elsif (mark between 66 and 75) then
    dbms_output.put_line('mark is C ');
  elsif (mark between 76 and 84) then
    dbms_output.put_line('mark is B');
  else 
    dbms_output.put_line('mark is F');
  end if;
end;
/
like image 163
Richard Avatar answered Nov 20 '22 07:11

Richard


The IF statement has these forms in PL/SQL:

IF THEN

IF THEN ELSE

IF THEN ELSIF

You have used elseif which in terms of PL/SQL is wrong. That need to be replaced with ELSIF.

DECLARE
  mark NUMBER :=50;
BEGIN
  mark :=& mark;
  IF (mark BETWEEN 85 AND 100) THEN
    dbms_output.put_line('mark is A ');
  elsif (mark BETWEEN 50 AND 65) THEN
    dbms_output.put_line('mark is D ');
  elsif (mark BETWEEN 66 AND 75) THEN
    dbms_output.put_line('mark is C ');
  elsif (mark BETWEEN 76 AND 84) THEN
    dbms_output.put_line('mark is B');
  ELSE
    dbms_output.put_line('mark is F');
  END IF;
END;
/
like image 3
Dulith De Costa Avatar answered Nov 20 '22 07:11

Dulith De Costa