-1

I have a written a program to calculate the average marks of students:

DECLARE 
    rno   NUMBER(10); 
    wt    NUMBER(10); 
    dbms  NUMBER(10); 
    se    NUMBER(10); 
    toc   NUMBER(10); 
    per   FLOAT(10); 
    total NUMBER(10); 
BEGIN 
    rno := &rno; 
    wt := &wt; 
    dbms := &dbms; 
    se := &se; 
    toc := &toc; 

    IF( wt < 40 OR se < 40 OR toc < 40 OR dbms < 40 ) THEN 

        dbms_output.Put_line('Fail'); 
        total := ( wt + se + toc + dbms ); 
        per := ( total / 400 ) * 100; 

        IF( per > 75 ) THEN 
            dbms_output.Put_line('grade A'); 
        ELSIF( per > 65 AND per < 75 ) THEN 
            dbms_output.Put_line('grade B'); 
        ELSIF( per > 40 AND per < 65 ) THEN 
            dbms_output.Put_line('grade c'); 
        ELSE 
            dbms_output.Put_line('Invalid Input'); 
        END IF; 

        dbms_output.Put_line('percentage is' ||per); 
    END IF; 
END; 
/ 

There is no error in the program. But The output of the program is as follows:

Enter value for rno: 1
old  10:  rno:=&rno;
new  10:  rno:=1;
Enter value for wt: 23
old  11:  wt:=&wt;
new  11:  wt:=23;
Enter value for dbms: 56
old  12:  dbms:=&dbms;
new  12:  dbms:=56;
Enter value for se: 74
old  13:  se:=&se;
new  13:  se:=74;
Enter value for toc: 84
old  14:  toc:=&toc;
new  14:  toc:=84;

PL/SQL procedure successfully completed.

SQL> /
Enter value for rno: 2
old  10:  rno:=&rno;
new  10:  rno:=2;
Enter value for wt: 45
old  11:  wt:=&wt;
new  11:  wt:=45;
Enter value for dbms: 25
old  12:  dbms:=&dbms;
new  12:  dbms:=25;
Enter value for se: 73
old  13:  se:=&se;
new  13:  se:=73;
Enter value for toc: 22
old  14:  toc:=&toc;
new  14:  toc:=22;

PL/SQL procedure successfully completed.

The program does not reach the 'if' statement and further. Please help.

Srini V
  • 11,045
  • 14
  • 66
  • 89
Tejas Tamkahne
  • 233
  • 2
  • 5
  • 11

1 Answers1

1

Like it says here Printing the value of a variable in SQL Developer, if you are using SQL Developer you have to turn on VIEW _> DBMS_OUTPUT, then click on the green plus sign to enable output. This works on my computer, it wasn't working before but doing what yours is doing now. Now the code you did works fine on my computer and I get the output:

Fail
Invalid Input
percentage is10

For SQL_Plus

set serveroutput on

does 2 things:

1) is tells SQLPLUS to dump the output after each statement 2) it makes sqlplus issue the dbms_output.enable

EDIT: second input of your question were fine actually

Fail
grade c
percentage is41.25
Community
  • 1
  • 1
Rika
  • 768
  • 1
  • 5
  • 16