Labb
Labb
EXPERIMENT-1
1. To Write a query to display the empno, ename, job, hiredate, provide alias for each
column, display employees who is working as PRESIDENT or ANALYST, and
employees belonging to deptno 10 or 20,and ename should not starts with S.
select deptno as d, empno as e, ename as n, job as j, hiredate as h from emp where (job
in ('MANAGER','ANALYST')) and deptno!=40 AND deptno!=30 and job not like
'S%';
2. WAQ to display ename, salary, comm, calculate total salary and annual salary of all
employees whose salary ranges from 1000 and 2500, and employees are belong to
department 10 or 30. And who is working as SALESMAN.
3. Write a query to display ENAME, SAL, DEPTNO, display only employees who is not
working under any manager.
4. Write a query to display ENAME, SAL, HIRDATE display Details of employees who
have been with the company for more than thirty years, who is not drawing salary from
1500 to 3000.
5. WAQ to display ename, deptno, salary, comm and find increment of salary by 10%,
and increment of commission by 5% for all employees and sort salary and department
number.
EXPERIMENT-2
1. WAQ to display the details of all employees whose name is Smith. But you are not
sure in which case enames are stored. Which statement will list all the employees whose
ename is Smith?
2. WAQ to display ename, mgr, sal and comm where employees are not working under
any manager as a value as NO MANAGER and comm as NO COMMISSION where
employees are not taking any commission from the deptno 10 0r 20.
3. WAQ to display the sum of the salary of all employees according to department and
job whose sum of the salary more than 5000, sort the deptno column in ascending order.
select sum(sal), deptno from emp group by deptno having sum(sal)>300 order by
deptno
4. WAQ to display ename and commission,if commission is null then replace with salary
and if salary is also null then replace with 1000.
select deptno, avg(sal) from emp group by deptno order by avg(sal) DESC FETCH
FIRST ROW ONLY;
Page |8
EXPERIMENT-3
1. Write a query to hike the salary of the employees below jobs using CASE Job is
CLERK hike by 15% If job is SALESMAN hike by 10% Or if job is ANALYST by 12%
select job, sal, case job when 'CLERK' then sal*1.15 when 'MANAGER' then sal*1.1
when 'ANALYST' then sal*1.12 else sal end as new_sal from emp;
2. Write a query to display the location from the department table as short Eg: NewYork
as NY, Dallas DS, Chicago CG, and BOSTON as BT.
3. Write a query to find the sum of salary by grouping according to job and deptno having
cross tabulation.
select job,
sum(case when deptno=10 then sal else 0 end) as dept_10,
sum(case when deptno=20 then sal else 0 end) as dept_20,
sum(case when deptno=30 then sal else 0 end) as dept_30,
sum(case when deptno=40 then sal else 0 end) as dept_40
from emp
group by job;
4. Write a query find the sum of the salary for job and find the grand total.
EXPERIMENT-4
1. Management wants to know the maximum salary of all the employees for each deptno,
and display only if maximum salary greater than 2800 ,sort maximum salary in
descending order.
2. WAQ to display employee name sal, comm, department name, location and calculate
total salary, annual salary for the department name RESEARCH or OPERATIONS, sort
annual salary in ascending order
select e.ename,e.empno,e.sal,d.deptno,d.location,d.dname,(e.sal*12)as
"annualsal",(e.sal+e.comm)as "totalsal" from emp e ,dept d where d.dname
in('ACCOUNTING','RESEARCH') and e.deptno = d.deptno order by e.deptno asc;
P a g e | 11
3. Write a query to display the list of employees working under which manager.
select ename, mgr from emp where mgr is not null group by ename, mgr;
4. Write a query to display ename and salary in dollar and prefix left white space of
salary by special character by * and employees belongs to deptno 30 and 40, who is
working as salesman and clerk.
select ename, '$'||sal||'*' as formatted_salary from emp where (deptno in (20,30)) and
(job in ('SALESMAN', 'CLERK'));
P a g e | 12
5. Write a query to find the sum of the salary for each department name and for each
location, display only sum of the salary should not be equal to 10000.
select d.dname, d.location, sum(e.sal) as salary from emp e, dept d group by dname,
location having sum(sal)>10000;
P a g e | 13
EXPERIMENT-5
1. WAQ to display ename , hiredate, sal and job where salary should be similar to
CLARK‟s salary.
2. WAQ to display which employee is getting minimum salary from the deptno 30.
3. WAQT to display employee name, job and there department name whose job should
be similar to JONES job and deptno similar to empno 7934.
4. WAQ to display empno,ename,job and salary where the salary should be less than
CLERK‟s salary.and job job should not be equal to SALESMAN.
EXPERIMENT-6
1. WAQ To Display empno, ename, deptno and location of employee KING and salary
between 1000$ to 2000$.
2. WAQ to find average salary for each job,deptno and loc and display only details if
average salary greater than 5000$. (Use natural join)
select e.job, e.deptno, d.location, avg(e.sal) as avgsalary from emp e join dept d on
e.deptno= d.deptno group by e.job, e.deptno, d.location having avg(e.sal)>5000;
P a g e | 16
3. Write a query to display all matching and non-matching details from emp .
4. Write a query to display all matching and non-matching records from emp as left table
and dept table as right.
5. Write a query to display all matching and non matching records from dept as right
table.
EXPERIMENT-7
1. Write a query to insert the three records to emp table at run time.
2. Write a Query to update the salary of the employee by 15%, where the employee
should work under the deptno of SMITH
update emp set sal = sal+(sal*15/100) where deptno=(select deptno from emp where
ename='Smith');
P a g e | 19
3. Write a query to delete the record from emp table where the employee should be
working as similar to JONES.
delete emp where job in (select job from emp where ename='JONES');
4. Write a query to delete deptno 10 from dept table. Mention the error if there is any
error exists.
EXPERIMENT-8
1. Create the table called product with attributes pno, pname, pprice, qty and total add the
constraint not null for the required columns and add check constraint to price >0
create table product (pno int, pname varchar(20) not null, pprice numeric(5,2) check
(pprice>0), qty int not null, total numeric(5,2)not null);
EXPERIMENT-9
1. Create a view empvu20 which has all employees details work for the deptno 20.
2. Write a query to create view on emp and dept table which has details like ename,
deptno, sal, dname and loc for deptno 10, and salary should be between 1000 to 2000 and
who are not drawing commission.
3. Write a query to create view as EMPDETAILS from the tables EMP, DEPT and
SALGRADE which contains empno, ename, job, sal, deptno, dname,loc and grade,
where employees working as ANALYST and are not belongs to deptno 10 and 20.
4. Modify the EMPDETAILS view by using required clause. Add an alias for each
column name
EXPERIMENT-10
i. Create table job_hostory By Copying the structure data from emp table.
delete job_history;
create table job_history as select*from emp where rownum<4;
select*from job_history;
P a g e | 28
3. WAQ to display unique records from both table emp and job_history
4. WAQ to Display the employees work for the company from since from beginning to
till date from both the table emp and job_history
5. WAQ to display employees joined recently leaving who has joined since beginning.
EXPERIMENT-11
1. Create the new user called JAINBCAIIISEM with the password jain.
3. Provide the permission to the user JAINBCAIIISEM for create session, creating table,
view.
5. Take back all the DML permission from the user JAINBCAIIISEM
6. Create the role called HR and provide the privileges create table, create view to HR
.
Create table,create view to HR;
EXPERIMENT-12
1. Write a PL/SQL program to create the trigger where data can jot be edited on Saturday
and Sunday on emp table.
2. Write a PL/SQL program by creating the trigger while deleting the records from dept
table; it should update the old record to the dept_history table