You are on page 1of 11

CBS1007 – Database Systems

Lab Digital Assessment -V


(LAB SLOT :L59+60)

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

create table Student ( SID number(15),Sname char(50),Sex char(7),Major

char(20),Gpa float,Age number(2));

insert into Student values(1001,'Rohan Ram','M','Computer Science',9.8,18);

insert into Student values(1002,'Manish Chillar','M','Computer Science',10,19);

insert into Student values(2001,'Harshal Patel','M','Electrical', 9.4,19);

insert into Student values(2002,’Yogi Yadav','F','Electrical',8.8,20);

insert into Student values(3007,'Antar Anjal','F','Design',9.6,19);

insert into Student values(3010,'Sakshi Gupta','F','Mechanical',9.1,18);insert into Student

values(4021,'Omi','M','Civil',9.4,23);

insert into Student values(4075,'Raj Taneja ','F','Civil',8.8,22);

select * from Student;


INPUT SCREENSHOT:
OUTPUT SCREENSHOT:
2. Write a program to find whether the SID IS odd or even for each STUDENT. Create
SEPARate TABLES for STUDENTS with odd SID and ALSO for STUDENTS with even SID.

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 EVEN_STUDENT AS (select * from Student where mod(SID,2) = 0);

create table ODD_STUDENT AS (select * from Student where mod(SID,2) <> 0);

select * from EVEN_STUDENT;

select * from ODD_STUDENT;

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 :

You might also like