SQL Pracitcal
SQL Pracitcal
SQL Pracitcal
Select Clause
1. Display the employees who were hired in the year 1982.
Select * from emp where hiredate like ‘%82’;
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;
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;
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;
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.
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.