Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
  1  DECLARE
  2  SNO NUMBER(10):=&ENO;
  3  SNAME VRACHAR2(10):='&ENAME';
  4  M1 NUMBER(6):=&M1;
  5  M2 NUMBER(6):=&M2;
  6  M3 NUMBER(6):=&M3;
  7  TOTAL NUMBER(6);
  8  AVRG NUMBER(6);
  9  RESULT VARCHAR2(6);
 10  GRADE CHAR;
 11  BEGIN
 12  IF M1>40 AND M2>40 AND M3>40 THEN
 13  RESULT:='PASS';
 14  IF AVRG>=75 THEN
 15  GRADE:='A';
 16  ELSIF AVRG>=60 THEN
 17  GRADE:='B';
 18  IF AVRG>=45 THEN
 19  GRADE:='C';
 20  ELSE
 21  GRADE:='D';
 22  END IF;
 23  ELSE
 24  RESULT:='FAIL';
 25  GRADE:='_';
 26  ENDIF;
 27  DBMS_OUTPUT.PUT_LINE

('________________________________________');
 28  DBMS_OUTPUT.PUT_LINE('SNO: ' || SNO);
 29  DBMS_OUTPUT.PUT_LINE('SNAME:' || SNAME);
 30  DBMS_OUTPUT.PUT_LINE('TOTAL:' || TOTAL);
 31  DBMS_OUTPUT.PUT_LINE('AVRG:' || AVRG);
 32  DBMS_OUTPUT.PUT_LINE('RESULT' || RESULT);
 33  DBMS_OUTPUT.PUT_LINE('GRADE' || GRADE);
 34  DBMS_OUTPUT.PUT_LINE

('________________________________________');
 35* END;
 36  /
Enter value for eno: 23
old   2: SNO NUMBER(10):=&ENO;
new   2: SNO NUMBER(10):=23;
Enter value for ename: TYU
old   3: SNAME VRACHAR2(10):='&ENAME';
new   3: SNAME VRACHAR2(10):='TYU';
Enter value for m1: 67
old   4: M1 NUMBER(6):=&M1;
new   4: M1 NUMBER(6):=67;
Enter value for m2: 77
old   5: M2 NUMBER(6):=&M2;
new   5: M2 NUMBER(6):=77;
Enter value for m3: 89
old   6: M3 NUMBER(6):=&M3;
new   6: M3 NUMBER(6):=89;
END;


the following pl/sql programme raise the error

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


please help me.
thank u
Posted
Comments
PIEBALDconsult 31-Jul-15 12:28pm    
Well? At line 35, shouldn't END; be END IF; ?
[no name] 31-Jul-15 12:29pm    
Looks to me like you are missing an END IF. You have 3 IFs and 2 END IFs.

1 solution

It seems that you have misspelled one END IF.
On line 26 you have
SQL
ENDIF;

while it should be
SQL
END IF;


As a side note the innermost IF looks like it's not needed. So instead of having:
SQL
DECLARE
   SNO NUMBER(10):=&ENO;
   SNAME VRACHAR2(10):='&ENAME';
   M1 NUMBER(6):=&M1;
   M2 NUMBER(6):=&M2;
   M3 NUMBER(6):=&M3;
   TOTAL NUMBER(6);
   AVRG NUMBER(6);
   RESULT VARCHAR2(6);
   GRADE CHAR;
BEGIN
   IF M1>40 AND M2>40 AND M3>40 THEN
      RESULT:='PASS';
      IF AVRG>=75 THEN
         GRADE:='A';
      ELSIF AVRG>=60 THEN
         GRADE:='B';
         IF AVRG>=45 THEN
            GRADE:='C';
         ELSE
            GRADE:='D';
         END IF;
      ELSE
         RESULT:='FAIL';
      GRADE:='_';
   END IF;
   DBMS_OUTPUT.PUT_LINE('________________________________________');
   DBMS_OUTPUT.PUT_LINE('SNO: ' || SNO);
   DBMS_OUTPUT.PUT_LINE('SNAME:' || SNAME);
   DBMS_OUTPUT.PUT_LINE('TOTAL:' || TOTAL);
   DBMS_OUTPUT.PUT_LINE('AVRG:' || AVRG);
   DBMS_OUTPUT.PUT_LINE('RESULT' || RESULT);
   DBMS_OUTPUT.PUT_LINE('GRADE' || GRADE);
   DBMS_OUTPUT.PUT_LINE('________________________________________');
END;
/

Why not simplify it to
SQL
DECLARE
   SNO NUMBER(10):=&ENO;
   SNAME VRACHAR2(10):='&ENAME';
   M1 NUMBER(6):=&M1;
   M2 NUMBER(6):=&M2;
   M3 NUMBER(6):=&M3;
   TOTAL NUMBER(6);
   AVRG NUMBER(6);
   RESULT VARCHAR2(6);
   GRADE CHAR;
BEGIN
   IF M1>40 AND M2>40 AND M3>40 THEN
      RESULT:='PASS';
      IF AVRG>=75 THEN
         GRADE:='A';
      ELSIF AVRG>=60 THEN
         GRADE:='B';
      ELSIF AVRG>=45 THEN
         GRADE:='C';
      ELSIF ADD_THE_CORRECT_LIMIT_HERE
         GRADE:='D';
      ELSE
         RESULT:='FAIL';
      GRADE:='_';
   END IF;
   DBMS_OUTPUT.PUT_LINE('________________________________________');
   DBMS_OUTPUT.PUT_LINE('SNO: ' || SNO);
   DBMS_OUTPUT.PUT_LINE('SNAME:' || SNAME);
   DBMS_OUTPUT.PUT_LINE('TOTAL:' || TOTAL);
   DBMS_OUTPUT.PUT_LINE('AVRG:' || AVRG);
   DBMS_OUTPUT.PUT_LINE('RESULT' || RESULT);
   DBMS_OUTPUT.PUT_LINE('GRADE' || GRADE);
   DBMS_OUTPUT.PUT_LINE('________________________________________');
END;
/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900