Saturday 15 June 2013

database - What is wrong with my PL/SQL block? -



database - What is wrong with my PL/SQL block? -

i have written programme calculate 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 ) dbms_output.put_line('fail'); total := ( wt + se + toc + dbms ); per := ( total / 400 ) * 100; if( per > 75 ) dbms_output.put_line('grade a'); elsif( per > 65 , per < 75 ) dbms_output.put_line('grade b'); elsif( per > 40 , per < 65 ) 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 no error in program. output of programme follows:

enter value rno: 1 old 10: rno:=&rno; new 10: rno:=1; come in value wt: 23 old 11: wt:=&wt; new 11: wt:=23; come in value dbms: 56 old 12: dbms:=&dbms; new 12: dbms:=56; come in value se: 74 old 13: se:=&se; new 13: se:=74; come in value toc: 84 old 14: toc:=&toc; new 14: toc:=84; pl/sql procedure completed. sql> / come in value rno: 2 old 10: rno:=&rno; new 10: rno:=2; come in value wt: 45 old 11: wt:=&wt; new 11: wt:=45; come in value dbms: 25 old 12: dbms:=&dbms; new 12: dbms:=25; come in value se: 73 old 13: se:=&se; new 13: se:=73; come in value toc: 22 old 14: toc:=&toc; new 14: toc:=22; pl/sql procedure completed.

the programme not reach 'if' statement , further. please help.

like says here printing value of variable in sql developer, if using sql developer have turn on view _> dbms_output, click on greenish plus sign enable output. works on computer, wasn't working before doing yours doing now. code did works fine on computer , output:

fail invalid input percentage is10

for sql_plus

set serveroutput on

does 2 things:

1) tells sqlplus dump output after each statement 2) makes sqlplus issue dbms_output.enable

edit: sec input of question fine actually

fail grade c percentage is41.25

sql database stored-procedures plsql relational-database

No comments:

Post a Comment