You are on page 1of 4

O8NA81A0570

DBMS LAB

Write a pl/sql block of code to add 2 numbers.


SQL> ed sum declare A number (5):=&a; B number (5):=&b; C number (5); begin C: =a+b; DBMS_Output.put_line (sum of:||c); End; / OUTPUT: @ sum Enter value for a: 23 Old 2: a number (5):=&a; New 2: a number (5):=23; Enter value for b: 34 Old 3: b number (5):=&b; New 3: b number (5):=34; Sum of : 67 PL/SQL procedure successfully completed.

SPHOORTHY ENGINEERING COLLEGE

PAGE NO:

O8NA81A0570

DBMS LAB

Write a pl/sql block of code to select student marks from the table and print for those who secured first class and an exception can be raised if no records were found.
SQL>ed stud declare no student.Sno % type:=&no; name student.Sname %type; m1 student.mar1 %type; m2 student.mar2 %type; m3 student.mar3 %type; tot number(4):=0; avg number(6,2); begin select sno,snme,mar1,mar2,mar3 into no,name,m1,m2,m3 from student where sno=no; tot:=m1+m2+m3; avg:=tot/3; case when avg>60 then dbms_output.put_line(1 division); when avg<60 and avg>35 then dbms_output.put_line(2 division); else dbms_output.put_line(3 division); end case; EXCEPTION When No_data_found then Dbms_output.put_line(no record found); End; / SQL>SELECT * FROM STUDENT; SNO -------101 102 103 104 SNAME -------------KEERTHI TEJASWI HUDA SREE M1 -----90 89 67 74 M2 M3 ------- -----80 79 67 78 78 56 40 60

OUTPUT:

SPHOORTHY ENGINEERING COLLEGE

PAGE NO:

O8NA81A0570

DBMS LAB

SQL>@ stud Enter value foe no : 101 Old 100:no:=&no; New 100:no:=101; Total is 249 First class PL/SQL procedure successfully complete. SQL>/ Enter value for no:106 Old 100:no:=&no; New 100:no:=106; No record found PL/SQL procedure successfully completed.

SPHOORTHY ENGINEERING COLLEGE

PAGE NO:

O8NA81A0570

DBMS LAB

SPHOORTHY ENGINEERING COLLEGE

PAGE NO:

You might also like