Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SQL Pracitcal

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

A.

Select Clause
1. Display the employees who were hired in the year 1982.
 Select * from emp where hiredate like ‘%82’;

2. Display the name and salary of employee with highest salary.


 Select ename,sal from emp where sal=(select max(sal) from emp);

3. Display the second highest salary


 Select * from emp where sal=(select max(sal) from emp where sal != (select max(sal) from emp));

4. Display the details of employees who were employed 1981-82.


 Select * from emp where hiredate like ‘%81’ or hiredate like ‘%82’;
5. Display all the salesman and those manager where salary is more than 1600.
 Select * from emp where job=’SALESMAN’ or job = ‘MANAGER’ and sal>1600;

6. Display the name of the employees where in the name letter ‘S’ comes.
 Select * from emp where ename like ‘%S%’;

B. Operators
1. Display the avg salary of all employees
 Select avg(sal) from emp;

2. Find the avg salary of each job type.


 Select avg(sal) from emp group by job;
3. Display the total salary of all the employees who work in dept 10 as well as those employees who work in dept
20.
 Select sum(sal) from emp where deptno in (10,20);

4. Find the name of the employee who was hired first.


 Select * from emp where hiredate=(select min(hiredate) from emp);

5. Find the name of the employee who was hired second.


 Select * from emp where hiredate=(select min(hiredate) from emp where hiredate !=(select min(hiredate) from
emp));

6. Find the number of employees working in each department.


 Select deptno,count(ename) from emp groub by deptno ;

7. Count each job type available in each dept.


 Select deptno,count(job) from emp group by deptno;

8. Find the avg salary of each job types excluding the employees whose commission are null and display those job
types where avg salary is greater than 1200.
 Select avg(sal), job from emp where comm is not noll group by job having avg(sal) > 1200;

C. Update & Alter Clause


1. Increase the salary by 10% for those who work in department number 10 & 20.
 Update emp set sal=1.1*sal where deptno=10 or deptno = 20;

2. Decrease the salary by 5% for the employee in department number 30.


 Update emp set sal = 0.05%*sal where deptno=30;

3. Increase the salary by 10% for employees where empno=7934 and 7365 and transfer them to deptno 30.
 Update emp set sal=1.1*sal , deptno=30 where empno=7934 or empno=7365;

4. Add an address column for empno 7934 & 7965.


 Update emp set address where empno=7934;
5. Add a constraint unique on the address column.
 Alter table emp add constraint uni unique (address);

6. Change the width of the address column.


 Alter table emp modify (addresss varchar2(35));

7. Drop a constraint unique on address column.


 Alter table emp drop constraint uni;

8. Drop the column address from the emp table.


 Alter table emp drop (address);

9. Add foreign key constraint on deptno of emp table.


 Alter table emp add constraint fk foreign key(deptno) references dept(deptno);

D. Join Clause
1. Display empno, ename and dname for all employees who were hired in the year 1981&1982.
 Select empno,ename,dname from emp,dept where emp.deptno=dept.deptno and (hiredate like ‘%81’ or
hiredate like ‘%82’;
2. Display ename,job,sal,dname and loc for all employees who are managers & clerks.
 Select ename,job,sal,dname,loc from emp,dept where emp.deptno=dept.deptno and (job=’MANAGER’ OR
job=’CLERK’);

3. Display empno, deptno and dname for all employees who work in dept 30.
 Select empno,emp.deptno,dname from emp,dept where emp.deptno=dept.deptno and deptno=30;

4. Display empno,sal and loc for the employees who is having highest sal.
 Select empno,sal,loc from emp,dept where emp.deptno=dept.deptno and sal=(select max(sal) from emp);

5. Display ename,job,loc of the employees whose total salary is greater than 1600..
 Select ename,job,loc from emp,dept where emp.deptno=dept.deptno and sal+nvl(comm,0)>1600;

E. String

Function
1. Display all the names of empoyees whose name contain characters more than 5.
 Select ename from emp where length(ename)>5;

2. In the emp table the salesman job as executive & manager as GM and all other job as other job.
 Select ename,decode(job,’SALESMAN’,’EXECUTIVE’,’MANAGER’,’GM’,’OTHER JOB’) from emp;

F. Clause
1. Display the customers who are having account, loan or both in the bank.
 Select custid from depositor union select custid from borrower;

2. Display the customers who are having account as well as loan in the bank.
 Select custid from depositor intesect select custid from borrower;
3. Display customers who are having only account in the bank and no loan.
 Select custid from depositor minus select custid from borrower;

4. Display the customer who are having only loan from the bank & no account.
 Select custid from borrower minus select custid from depostior;

G. PL/SQL
1. Display the information of Department.
2. Find the area of a circle.

3. Find the area of a circle

4. From emp table consider sal on basic salary then find the total salary for all the employees and store result
in a table emp_total_sal(empno, tsal). Total salary will be calculated as basic sal + DA which is 40% of basic
sal + HRA of 30% of basic sal + travelling allowance @3500.

5. If there is more than 10% increase in the salary then old record should be copied to new table emp1.
6. Create a procedure to update the salary of the employee procedure will receive empid and amount as
parameters and it will increment the salary of the employee by the amount it has received as parameters. It
will also check for null salary, if salary is null then error will be received.

7.

You might also like