Professional Documents
Culture Documents
191 - Adrineel Saha - DBMS Lab
191 - Adrineel Saha - DBMS Lab
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)
);
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:-
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;
Output:-