DBMS Practicle File
DBMS Practicle File
DBMS Practicle File
MCA(2020-2022)
13. List all the employees who either belong to city names
starting with ‘K’ or from ‘Ghaziabad’
14. List all the employees who are drawing salary more than
10000 and belong to IT Department or HR Department.
15. List all the employees who are getting Salary in the range
5000 to 15000 and belong to city “Delhi”, “Bombay” or “
Madras”.
16. List the no. of employees and salary drawn by each
department
17. List the Cities and No. of Employees belong to that city.
19. List the names, Designation and Dept. name of all the
employees who are getting salary more than 20000 and are
placed at Noida, New Delhi or Ghaziabad.
26. Display Name, Age and Address with the help of given T1
and T2.
28. Display Name1, Age and Fname with the help of given Tab1
and Tab2. (Use Outer Join ) retaining all the values
corresponding name1 attribute.)
29. Create a view view1 from above Tab1 and Tab2 table given
in Q7, with NAME1, Age and Fname attribute
30. Write a PL/SQL code block to calculate the area of a circle
for a value of radius varying from 3 to 7. Store the radius and
the corresponding values of calculated area in a table, Areas
31. Write a PL/SQL block that will display the name, department
and salary of the first 10 employees getting the highest
salary.
33.
Write a PL/SQL code block that will accept an account
number from the user and debit an amount of RS. 2000 from
the account if the account has a minimum balance of R. 500
after the amount is debited. The process is to be fired on the
Account table.
5. Update given table set name attribute value is equal to “RAM” for the
Name value “PQR”
Program:
create table STUDENT(
S_Name varchar2(30),
Age integer,
S_ID integer,
RNo integer,
primary key(S_ID))
insert into STUDENT values('XYZ',25,1,2)
insert into STUDENT values('PQZ',26,2,3)
insert into STUDENT values('MNO',25,3,4)
insert into STUDENT values('PQR',26,4,5)
select * from STUDENT WHERE Age = 26 and S_NAME = 'PQR'
select S_Name,Age from STUDENT where RNO>3
delete from STUDENT where S_ID=1
UPDATE Student SET S_NAME = 'RAM' WHERE S_NAME = 'PQR'
drop table STUDENT
9. Create a Table named ‘Employee’ with the following specifications:
11. Add a new column Passport_No of the type character with a maximum
width of 30 with varying size.
13. List all the employees who either belong to city names starting with ‘K’ or
from ‘Ghaziabad’.
15. List all the employees who are getting Salary in the range 5000 to 15000
and belong to city “Delhi”, “Bombay” or “ Madras”.
16. List the no. of employees and salary drawn by each department.
17. List the Cities and No. of Employees belong to that city.
18. Remove the column Passport_No.
19. List the names, Designation and Dept. name of all the employees who are
getting salary more than 20000 and are placed at Noida, New Delhi or
Ghaziabad.
Program:
create table EMPLOYEE(
Emp_No number(4,0) NOT NULL,
Ename char(20),
Address char(30),
Dept_Name char(5),
Designation char(10),
Deptno number(2,0),
City char(15),
Phone number(10,0),
Salary number(10,2),
primary key (Emp_No),
check (Salary>1000));
select Count(Emp_No),Sum(salary),Dept_Name
from EMPLOYEE group by Dept_Name
select Count(Emp_No),City
from EMPLOYEE group by City
select Ename,Dept_Name,Designation
from EMPLOYEE where Salary>20000
and City='Noida' or City='NewDelhi' or City='Ghaziabad'
Name Type
2. LIST all records of EMP1 table with manager which is also employee.
Program:
create table Empl(
Emp_ID number(4,0),
ENAME char(25),
CITY char(25),
PHONE number(8,0),
DEPT_NO number(4,0) NOT NULL,
DESIGNATION char(10) NOT NULL,
SALARY number(10,2),
PASSPORT_NO char(10))
select T1.NAME1,T1.AGE,T2.ADDRESS
from T1 INNER JOIN T2
on T1.ID1 = T2.ID2
drop table T2
27. Create table for following values (Tab1 and Tab2).
Tab1 Tab2
Program :
select TAB1.NAME1,TAB1.AGE,TAB2.FNAME
from TAB1 FULL OUTER JOIN TAB2
on TAB1.NAME1 = TAB2.NAME2
DECLARE
r number(5);
area number(14,2);
pi constant number (4,2):=3.14;
BEGIN
r:=3;
while r<=7
loop
area:=pi*power(r,2);
insert into areas values(r,area );
r:=r+1;
end loop;
END;
Output :
31. Write a PL/SQL block that will display the name, department and salary
of the first 10 employees getting the highest salary.
declare
cursor c_emp is select Emp_code,Salary from Employee1;
str_emp_code Employee1.Emp_code%type;
num_salary Employee1.Salary%type;
num_raiseamt emp_raise.raise_amt%type;
begin
open c_emp;
if c_emp%isopen then
loop
fetch c_emp into str_emp_code,num_salary,num_raiseamt;
exit when c_emp%notfound;
update Employee1 set Salary = num_salary + num_raiseamt where Emp_code =
str_emp_code;
insert into emp_raise values(str_emp_code,Salary);
end loop;
close c_emp;
else
dbms_output.put_line('unable to open cursor');
end if;
end;
33. Write a PL/SQL code block that will accept an account number from the
user and debit an amount of RS. 2000 from the account if the account has a
minimum balance of R. 500 after the amount is debited. The process is to be
fired on the Account table.
Table Name: Account
Account Id Name Bal
AC001 Anuj 5000
AC002 Robert 10000
AC003 Mita 5000
AC004 Sunita 15000
AC005 Melba 10000
Program :
create table Accounts3(
Account_id varchar(5),
A_Name varchar(20),
Bal number(7,2));
declare
acct_balance number(7,2);
acct_no varchar2(6);
debit_amt number(7,2):=2000.00;
min_bal constant number(7,2):=500.00;
Begin
acct_no:= &Account_id;
select bal into acct_balance
from Accounts3
where account_id=acct_no;
acct_balance:=acct_balance-debit_amt;
if acct_balance>=min_bal then
update accounts3 set bal=bal-debit_amt
where account_id=acct_no;
end if;
end;