You are on page 1of 3

create table student(roll_no integer,name char(10),sub char(8),m1 integer,m2 integer,m3 integer,per

number(5,2));
SQL> select * from student;
ROLL_NO NAME
SUB
M1
M2
M3
---------- ---------- -------- ---------- ---------- ---------- ---------1 ram
maths
50
90
80
2 shyam phy
60
80
70
3 sita
maths
70
70
60
4 geeta phy
80
50
50
5 mohan maths
90
60
40
6 sohan maths
50
40
90
7 rohan phy
90
70
50
8 pooja phy
80
60
60

PRE

SQL> UPDATE STUDENT SET per=(m1+m2+m3)/3;
8 rows updated.
SQL> select * from student;
ROLL_NO NAME
SUB
M1
M2
M3
PRE
---------- ---------- -------- ---------- ---------- ---------- ---------1 ram
maths
50
90
80 73.33
2 shyam phy
60
80
70
70
3 sita
maths
70
70
60 66.67
4 geeta phy
80
50
50
60
5 mohan maths
90
60
40 63.33
6 sohan maths
50
40
90
60
7 rohan phy
90
70
50
70
8 pooja phy
80
60
60 66.67
DECLARE
CURSOR CRSR_MATHS IS
SELECT name,per FROM student
WHERE sub='maths'
ORDER BY PER DESC;
CURSOR CRSR_PHY IS
SELECT name,per FROM student
WHERE sub='phy'
ORDER BY PER DESC;
s_name CHAR(10);

PUT_LINE('NAME: '||S_NAME||' X:=X+1. OPEN CRSR_PHY. DBMS_OUTPUT.PUT_LINE('______________________________________________'). PERCENTAGE: '||S_PER). EXIT WHEN Y=3. X:=0.PUT_LINE('UNABLE TO OPEN CURSOR').PUT_LINE('-------------------------------------------------------------------------').PUT_LINE('UNABLE TO OPEN CURSOR'). DBMS_OUTPUT. BEGIN OPEN CRSR_MATHS.s_per. END. Y INTEGER:=0. DBMS_OUTPUT. X INTEGER:=0.PUT_LINE('______________________________________________'). EXIT WHEN X=3.s_per NUMBER(5. IF CRSR_PHY%ISOPEN THEN LOOP FETCH CRSR_PHY INTO s_name.PUT_LINE('-------------------------------------------------------------------------').PUT_LINE('THE FIRST 3 MERIT STUDENTS IN PHY SUBJECT ARE:'). IF CRSR_MATHS%ISOPEN THEN LOOP FETCH CRSR_MATHS INTO s_name.s_per. ELSE DBMS_OUTPUT. DBMS_OUTPUT.PUT_LINE('THE FIRST 3 MERIT STUDENTS IN MATHS SUBJECT ARE:'). END IF. END IF.2). END LOOP. DBMS_OUTPUT. END LOOP. CLOSE CRSR_MATHS. . DBMS_OUTPUT. Y:=0. ______________________________________________ THE FIRST 3 MERIT STUDENTS IN MATHS SUBJECT ARE: PERCENTAGE: '||S_PER). DBMS_OUTPUT. CLOSE CRSR_PHY. ELSE DBMS_OUTPUT. DBMS_OUTPUT.PUT_LINE('NAME: '||S_NAME||' Y:=Y+1.

.67 NAME: mohan PERCENTAGE: 63.33 ______________________________________________ THE FIRST 3 MERIT STUDENTS IN PHY SUBJECT ARE: -------------------------------------------------------------NAME: shyam PERCENTAGE: 70 NAME: rohan PERCENTAGE: 70 NAME: pooja PERCENTAGE: 66.67 PL/SQL procedure successfully completed.33 NAME: sita PERCENTAGE: 66.-------------------------------------------------------------NAME: ram PERCENTAGE: 73.