Akashh 2
Akashh 2
Enter user-name:system
Enter password:
Connected.
set autocommit on;
COM ENAME
---------- ----------
300 allen
500 ward
1400 martin
JOB
----------
salesman
clerk
manager
4. Find out the length of the empno for the workers
who work as a salesman.
JOB EMPNLENGTH
---------- ----------
salesman 4
salesman 4
salesman 4
5. Show employee name, grade and salary, in the order
of their salary.
SQL> select ename,sal from akash_emp order by sal asc;
ENAME SAL
---------- ----------
smith 800
ward 1250
martin 1250
allen 1600
clark 2450
blake 2850
jones 2975
6. How many employees are getting salary more than
1000?
SQL> select ename,sal from akash_emp where sal>1000;
ENAME SAL
---------- ----------
allen 1600
ward 1250
jones 2975
martin 1250
blake 2850
clark 2450
7. Select only those employees who are a clerk and a
manager.
SQL> select ename,job from akash_emp where job in ('clerk','manager');
ENAME JOB
---------- ----------
smith clerk
jones manager
blake manager
clark manager
8. How many employees are there whose names start
with „A‟?
SQL> select ename from akash_emp where ename like 'a%';
ENAME
----------
allen
9. Find the location of the letter „K‟ in the name
Blake.
SQL> select ename,instr(ename, 'k') from akash_emp where ename='blake';
ENAME INSTR(ENAME,'K')
---------- ----------------
blake 4
10. Select those employees, who have joined on or
before 31st December 1982 and is a clerk.
SQL> select ename,job,hiredate from akash_emp where hiredate<='31-dec-82';
ENAME JOB HIREDATE
---------- ---------- ---------
smith clerk 17-DEC-80
allen salesman 20-FEB-81
ward salesman 22-FEB-81
jones manager 02-APR-81
martin salesman 28-SEP-81
blake manager 01-MAY-81
clark manager 09-JUN-81
11. In which location the letter R is present in
MARTIN?
SQL> select instr('martin', 'r') from dual;
INSTR('MARTIN','R')
-------------------
3
12. Replace the name KING with KONG (use replace
function).
SQL> select replace('kingdom','king','kong') from dual;
REPLACE
-------
kongdom
13. Display the name of the employees in a manner, so
that they are right aligned and the
title, ‘Mr.’ is added at the beginning of their names.
'MR.'||ENAME
--------------
Mr. smith
Mr. allen
Mr. ward
Mr. jones
Mr. martin
Mr. blake
Mr. clark
14. Find the first letter of the name of the employee
who is getting salary 800
SQL> select substr(ename,1,1) from akash_emp where sal=800;S-
s
MONTHS_BETWEEN(SYSDATE,HIREDATE)
--------------------------------
514.505855
17. What is the experience of the employee whose
empno is 7788?
SQL> select floor(months_between(sysdate,hiredate)/12) from akash_emp where
ename='martin';
FLOOR(MONTHS_BETWEEN(SYSDATE,HIREDATE)/12)
------------------------------------------
42
18. Find out in which year Adams has joined the
company.
SQL> select floor(months_between(sysdate,hiredate)/12)||'years' from akash_emp
where empno=7782;
FLOOR(MONTHS_BETWEEN(SYSDATE,HIREDATE)/12)||'
---------------------------------------------
43years
SQL> select extract(year from hiredate) from akash_emp where ename='allen';
EXTRACT(YEARFROMHIREDATE)
-------------------------
1981