0% found this document useful (0 votes)
29 views9 pages

191 - Adrineel Saha - DBMS Lab

Uploaded by

ADRINEEL SAHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views9 pages

191 - Adrineel Saha - DBMS Lab

Uploaded by

ADRINEEL SAHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Name-Adrineel Saha

Year-3rd
Enrollment
no-12019002003114
Sec-C
Roll no-191
Subject-DBMS Lab
Subject code-PCCCS591
Date-04/01/2022
1. Create both tables and insert at least 3 values in both of them.
AND
2. First row in Staff table should contain your information (Mainly Your name in Staff_Name,
Your Roll in Staff_Id).

Code:-
Create Table Dependent(
Dependent_Name varchar2(10),
Dependent_id number(5) Primary Key,
Age number(2),
Staff_Id number(3)
);

Create Table Staff(


Staff_Name varchar2(10),
Staff_Id number(3) Primary Key,
Address varchar2(10),
Dependent_Id number(5),
Dept_Name varchar2(3),
Foreign Key (Dependent_Id) References Dependent(Dependent_ID)
);

Output:-
Code:-

INSERT ALL
INTO Dependent VALUES('Souradip',1234,35,10)
INTO Dependent VALUES('Akash',4321,36,20)
INTO Dependent VALUES('Dhritesh',12345,40,18)
SELECT * FROM DUAL;

INSERT ALL
INTO Staff VALUES('Samya',187,'Kolkata',4321,'CSE')
INTO Staff VALUES('Adrineel',191,'Asansol',12345,'ECE')
INTO Staff VALUES('Ayush',197,'Bihar',1234,'CSE')
SELECT * FROM DUAL;

Output:-
3. Write a query to those Staff names who have more than one dependent.

Code:-

Alter Table Staff


Drop column Dependent_Id;

Update Dependent
Set Staff_Id=191 where Staff_Id=10;

Update Dependent
Set Staff_Id=191 where Staff_Id=18;

Update Dependent
Set Staff_Id=187 where Staff_Id=20;

Output:-
Code:-

SELECT Staff.Staff_Name
FROM Staff
INNER JOIN Dependent
ON Staff.Staff_Id =Dependent.Staff_Id
GROUP BY Staff.Staff_Name
HAVING COUNT(*) > 1;

Output:-
4. Write a function to return the sum of the digits in your roll number. Show
output through a PL/SQL Block.

Code:-
Creating Function:-
CREATE OR REPLACE
FUNCTION SUM_OF_DIGITS(p_num NUMBER)
RETURN NUMBER IS
num INTEGER;
temp_sum INTEGER;
r INTEGER;
BEGIN

temp_sum := 0;
num :=p_num;

WHILE num <> 0 LOOP


r := MOD(num, 10);
temp_sum := temp_sum + r;
num := Trunc(num / 10);
END LOOP;
RETURN temp_sum;
END;
/

Running Through PL/SQL Block:-


Begin
dbms_output.put_line(SUM_OF_DIGITS(191));
End;
/

Output:-

You might also like