You are on page 1of 3

6. Write a PL / SQL program to calculate the total, average and grade of given s tudent.

java number(10); dbms number(10); co number(10); mfcs number(10); total number(10); avgs number(10); per number(10); begin dbms_output.put_line('ENTER THE MARKS'); java:=&java; dbms:=&dbms; co:=&co; mfcs:=&mfcsl; total:=(java+dbms+co+mfcs); per:=(total/600)*100; if java<40 or dbms<40 or co<40 or mfcs<40 then dbms_output.put_line('FAIL'); 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>55 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; / OUTPUT: SQL> @ GRADE.sql Enter value for java: 80 old 11: java:=&java; new 11: java:=80; Enter value for dbms: 70 old 12: dbms:=&dbms; new 12: dbms:=70; Enter value for co: 89 old 13: co:=&co; new 13: co:=89; Enter value for mfcs: 71 old 14: mfcs:=&mfcs; new 14: mfcs:=71; GRADE A PERCENTAGE IS 77 PL/SQL procedure successfully completed. = = = = = = = = = = = = = = = = = = = = = = = = = == = = = = = = = = = = = = = = = = = = = = = = = = = 7. Write a program to find the biggest of three numbers input by the user. declare a number; b number;

c number; begin a:=&a; b:=&b; c:=&c; if a=b and b=c and c=a then dbms_output.put_line('ALL ARE EQUAL'); elsif a>b and a>c then dbms_output.put_line('A IS GREATER'); elsif b>c then dbms_output.put_line('B IS GREATER'); else dbms_output.put_line('C IS GREATER'); end if; end; / OUTPUT: SQL> @ GREATESTOF3.sql Enter value for a: 8 old 6: a:=&a; new 6: a:=8; Enter value for b: 9 old 7: b:=&b; new 7: b:=9; Enter value for c: 7 old 8: c:=&c; new 8: c:=7; B IS GREATER PL/SQL procedure successfully completed. = = = = = = = = = = = = = = = = = = = = = = = = = == = = = = = = = = = = = = = = = = = = = = = = = = = 8. Write a program that prints the factorial of a number input by the user. SQL> declare 2 i number; 3 a number; 4 f number:=1; 5 Begin 6 a:=&a; 7 for i in 1..a 8 loop 9 f:=f*i; 10 end loop; 11 dbms_output.put_line('The factorial is:'||f); 12 end; 13 / Output : Enter value for a: 4 old 6: a:=&a; new 6: a:=4; = = = = = = = = = = = = = = = = = = = = = = = = = == = = = = = = = = = = = = = = = = = = = = = = = = = 9. Write a program in PL/SQL to check the given number is even or odd. SQL> DECLARE 2 num NUMBER;

3 BEGIN 4 num:='&Input_Number'; 5 IF MOD(num,2)=0 THEN 6 DBMS_OUTPUT.PUT_LINE(num||' '||'Is Even Number!'); 7 ELSE 8 DBMS_OUTPUT.PUT_LINE(num||' '||'Is Odd Number!'); 9 END IF; 10 END; 11 / Enter value for input_number: 5 old 4: num:='&Input_Number'; new 4: num:='5'; 5 Is Odd Number! PL/SQL procedure successfully completed. = = = = = = = = = = = = = = = = = = = = = = = = = == = = = = = = = = = = = = = = = = = = = = = = = = = 14. Write a program to display the Fibonacci series for n given terms. Example: If the number of terms is 8 then the series is 0, 1, 1, 2, 3, 5, 8, 13 Write a PL/ SQL program to generate Fibonacci series declare a number; b number; c number; n number; i number; begin n:=&n; a:=0; b:=1; dbms_output.put_line(a); dbms_output.put_line(b); for i in 1..n-2 loop c:=a+b; dbms_output.put_line(c); a:=b; b:=c; end loop; end; / OUTPUT: SQL> @ FIBONACCI.sql Enter value for n: 3 old 8: n:=&n; new 8: n:=3; 0 1 1 PL/SQL procedure successfully completed.

You might also like