Professional Documents
Culture Documents
Submitted By:
Name: Bhavesh Yadav
Reg No. 20BBS0200
Submitted To:
DR. KANNAN A
1. Create a table called STUDENT with atTRIBUTES Sid, Sname, Sex, Major, Gpa and Age.
CODE:
# Creating Table
values(4021,'Omi','M','Civil',9.4,23);
CODE:
# Program to find whether the sid is odd or even for each student
DECLARE
CURSOR c IS select * from Student;
tmp c%rowtype;
BEGIN
OPEN c;
LOOP
FETCH c into tmp; EXIT
WHEN c%notfound;
IF mod(tmp.SID , 2) = 0 THEN
dbms_output.put_line('THE SID OF '|| tmp.Sname ||'IS EVEN');
ELSE
dbms_output.put_line('THE SID OF '||tmp.Sname ||'IS ODD');
END IF;
END LOOP;
CLOSE c;
END;
SCREENSHOT:
# Create separate tables for students with odd sid and students with even sid
create table ODD_STUDENT AS (select * from Student where mod(SID,2) <> 0);
SCREENSHOT :
INPUT :
OUTPUT :
3. Write a program to check whether a given SID prESENT the table created for
odd SID IS a prime number or COMPOSITE number.
CODE:
# Program to check whether a given sid present the table created for odd sid is a
prime number or composite number.
DECLARE
CURSOR c IS select * from ODD_STUDENT;
tmp c%rowtype;
n number;
i number;
temp number;
BEGIN
OPEN c;
LOOP
FETCH c into tmp; EXIT
WHEN c%notfound;
n := tmp.SID; i
:= 2;
temp := 1;
FOR i in 2..n/2 LOOP
IF mod(n, i) = 0 THEN
temp := 0;
EXIT;
END IF;
END
LOOP;
IF temp = 1
THEN
dbms_output.put_line('THE SID OF '|| tmp.Sname || 'IS
PRIME');
ELS
E dbms_output.put_line('THE SID OF '|| tmp.Sname || 'IS
COMPOSITE')
;
END IF;
END
LOOP;
CLOSE c;
END;
INPUT SCREENSHOT :
OUTPUT SCREENSHOT :