You are on page 1of 8

1)

1* select empno,ename,sal, round(sal+(sal*0.15)) as "newsal" from emp
sql>/
Tue Dec 05
Hi!!!!!!
EMPNO
---------7499
7521
7654
7698
7782
7839
7844
7900
7934
7679
7869
7474
7499
7489
7660
8888
7042
9687

ENAME
SAL
newsal
---------- ---------- ---------ALLEN
5000
5750
WARD
7500
8625
MARTIN
7500
8625
BLAKE
8000
9200
CLARK
4500
5175
KING
4000
4600
TURNER
7500
8625
JAMES
7500
8625
MILLER
8000
9200
NAKEN
8000
9200
JOSEPH
4938
5679
LIBIN
1789
2057
ja
5000
5750
JAMES
2000
2300
suresh
5000
5750
HARRIS
6000
6900
SEN
12000
13800
rose
1500
1725

18 rows selected.
2.
1* select ename,months_between(sysdate,hiredate) from emp order by 2 desc
sql>/
Tue Dec 05
Hi!!!!!!
ENAME
MONTHS_BETWEEN(SYSDATE,HIREDATE)
---------- -------------------------------ALLEN
309.542061
JAMES
309.542061
WARD
309.477545
BLAKE
307.154965
CLARK
305.8969
TURNER
302.929158
MARTIN
302.283997
KING
300.638835
JAMES
300.090448
MILLER
298.445287
LIBIN
276.380771
HARRIS
259.929158
NAKEN
253.703352
JOSEPH
97.5420613
rose
21.864642
ja
9.54206131
SEN
1.86464195
suresh
1.67109356

---------.---------------------------------------.hiredate.6).'no commmision'). 1* select ename.sal+comm from emp sql>/ Tue Dec 05 Hi!!!!!! ENAME SAL NVL(TO_CHAR(COMM).next_day(add_months(hiredate.nvl(to_char(comm).---------ALLEN 5000 396.75 5396. 3.18 rows selected.75 WARD 7500 345 7845 MARTIN 7500 345 7845 BLAKE 8000 345 8345 CLARK 4500 345 4845 KING 4000 345 4345 TURNER 7500 345 7845 JAMES 7500 345 7845 MILLER 8000 345 8345 NAKEN 8000 455 8455 JOSEPH 4938 no commmision LIBIN 1789 526 2315 ja 5000 45 5045 . 1* select ename.'Monday') as "Review Date" from emp sql>/ Wed Dec 06 page Hi!!!!!! ENAME ---------ALLEN WARD MARTIN BLAKE CLARK KING TURNER JAMES MILLER NAKEN JOSEPH LIBIN ja JAMES suresh HARRIS SEN rose HIREDATE --------20-FEB-81 22-FEB-81 28-SEP-81 01-MAY-81 09-JUN-81 17-NOV-81 08-SEP-81 03-DEC-81 23-JAN-82 15-OCT-85 20-OCT-98 25-NOV-83 20-FEB-06 20-FEB-81 16-OCT-06 08-APR-85 10-OCT-06 10-FEB-05 Review Da --------24-AUG-81 24-AUG-81 29-MAR-82 02-NOV-81 14-DEC-81 24-MAY-82 15-MAR-82 07-JUN-82 26-JUL-82 21-APR-86 26-APR-99 28-MAY-84 21-AUG-06 24-AUG-81 23-APR-07 14-OCT-85 16-APR-07 15-AUG-05 18 rows selected. 4.'NOCOMMMISION') SAL+COMM ---------.sal.

e1.ename dname.deptno sql>/ Wed Dec 06 page 1 Hi!!!!!! EMPNO ---------9687 9687 7499 7654 7844 7521 7499 7900 7489 7679 7934 7782 7698 7869 ENAME ---------rose rose ALLEN MARTIN TURNER WARD ja JAMES JAMES NAKEN MILLER CLARK BLAKE JOSEPH DNAME ---------ALLEN ja BLAKE BLAKE BLAKE BLAKE BLAKE BLAKE BLAKE CLARK CLARK KING KING JAMES LOC ------------BANGALORE BANGALORE BANGALORE BANGALORE BANGALORE BANGALORE BANGALORE BANGALORE BANGALORE CHENNAI CHENNAI CHENNAI BANGALORE BANGALORE 14 rows selected. 1* select ename.hiredate from emp where hiredate in (select max(hireda te) from emp group by deptno) sql>/ Wed Dec 06 .JAMES suresh HARRIS SEN rose 2000 5000 6000 12000 1500 456 500 300 500 111 2456 5500 6300 12500 1611 18 rows selected.dept d whe re e1.'d')='2' sql>/ Wed Dec 06 Hi!!!!!! ENAME ---------MARTIN ja suresh HARRIS 7.deptno.ename.empno. 1* SELECT e1.deptno=d. loc from emp e1.emp e2 . 6.mgr=e2.empno and e1.e2. 1* select ename from emp where to_char(hiredate. 5.

d.deptno.m.ename.deptno=d.deptno=d.page 1 Hi!!!!!! ENAME DEPTNO HIREDATE ---------.deptno.deptno =(select deptno from emp where ename='&name') sql>/ Enter value for name: MILLER old 1: select ename.deptno =(select deptno from emp where ename='MILLER') Wed Dec 06 page 1 Hi!!!!!! ENAME DEPTNO DNAME ---------. emp m where e.---------.hiredate from emp where hiredate> (select hiredate from emp whe re ename='&name').dname from emp e. 1* select ename.dname from emp e.dept d where e.dept d where e.hiredate <m.hiredate from emp where hiredate> (select hiredate from em p where ename='&name') new 1: select ename.ename from emp e. 9.deptno and e. sql>select ename.deptno =(select deptno from emp where ename='&name') new 1: select ename.deptno.empno and e.mgr=m.deptno=d.---------.hiredate . d.-------------CLARK 10 ACCOUNTING KING 10 ACCOUNTING MILLER 10 ACCOUNTING sql>select * from emp.dname from emp e.hiredate from emp where hiredate> (select hiredate from em p where ename='NAKEN') Wed Dec 06 page 1 Hi!!!!!! ENAME ---------JOSEPH ja suresh SEN rose HIREDATE --------20-OCT-98 20-FEB-06 16-OCT-06 10-OCT-06 10-FEB-05 10. d.--------MILLER 10 23-JAN-82 LIBIN 75 25-NOV-83 NAKEN 40 15-OCT-85 rose 30 10-FEB-05 suresh 20 16-OCT-06 8.deptno and e.deptno and e. Enter value for name: NAKEN old 1: select ename. 1* select e.dept d where e.

ename sql>/ Wed Dec 06 page 1 Hi!!!!!! ENAME MAX(E.empno group by m.sql>/ Wed Dec 06 page Hi!!!!!! ENAME ---------rose ALLEN WARD JAMES BLAKE CLARK ENAME ---------ja BLAKE BLAKE BLAKE KING KING 6 rows selected.---------1500 1500 1500 1500 1789 1789 1789 1789 2000 2000 2000 2000 4000 4000 4000 4000 4500 4500 4500 4500 4938 4938 4938 4938 5000 5000 5000 15000 6000 6000 6000 6000 7500 7500 7500 30000 8000 8000 8000 24000 12000 12000 12000 12000 11 rows selected.sum(sal) from emp group by sal sql>/ Wed Dec 06 Hi!!!!!! MAX(SAL) MIN(SAL) AVG(SAL) SUM(SAL) ---------.max(e. 11. min(sal) .ename.SAL) MIN(E.---------ALLEN 1500 1500 BLAKE 7500 2000 CLARK 8000 1789 JAMES 4938 4938 KING 8000 4500 . 1* SELECT MAX(sal). emp m where e. 12) 1* select m.min(e.sal) from emp e. avg(sal).SAL) ---------.mgr=m.---------.---------.---------.sal).

---------1981 9 1982 1 1983 1 1985 2 1998 1 2005 1 2006 total 3 18 8 rows selected. 15. 13.ja 1500 1500 6 rows selected.'YYYY') 3* union select to_char('total').deptno from emp where deptno= 2 (select deptno from emp group by deptno having count(ename)= 3* (select max(count(*)) from emp group by deptno)) sql>/ Wed Dec 06 ENAME DEPTNO ---------. 2 count(*) from emp group by to_char(hiredate. count(*) from emp sql>/ Wed Dec 06 YEAR COUNT(*) ----.---------WARD 30 MARTIN 30 BLAKE 30 TURNER 30 JAMES 30 JOSEPH 30 JAMES 30 rose 30 8 rows selected. sql>select ename from emp where sal> any (select sal from emp where job='CLERK') .'YYYY') as year . Wed Dec 06 Hi!!!!!! . 1 select ename . 1 select to_char(hiredate. 17.

DEPTNO FROM EMP WHERE SAL< ANY (SELECT AVG(SAL) FROM EMP GROUP BY DEPTNO).DEPTNO AND D. 1 SELECT ENAME. 18.HIREDATE. Wed Dec 06 Hi!!!!!! ENAME DEPTNO ---------.DEPTNO AND D.---------15-OCT-85 96000 09-JUN-81 54000 17-NOV-81 48000 23-JAN-82 96000 19.---------ALLEN 20 WARD 30 MARTIN 30 CLARK 10 .ENAME ---------ALLEN WARD MARTIN BLAKE CLARK KING TURNER JAMES MILLER NAKEN JOSEPH ja JAMES suresh HARRIS SEN 16 rows selected. DEPT D 2* WHERE E.LOC IN (SELECT LOC FROM DEPT WHERE LOC='&LOCA T') sql>/ Enter value for locat: CHENNAI old 2: WHERE E.LOC IN (SELECT LOC FROM DEPT WHERE LOC='C HENNAI') Wed Dec 06 Hi!!!!!! ENAME ---------NAKEN CLARK KING MILLER DNAME -------------QUALITY ACCOUNTING ACCOUNTING ACCOUNTING HIREDATE ANSAL --------.DEPTNO=D.SAL*12 AS "ANSAL" FROM EMP E.DEPTNO AND D.LOC IN (SELECT LOC FROM DEPT WHERE LOC='& LOCAT') new 2: WHERE E. 1* SELECT * FROM EMP sql> SELECT ENAME. DNAME.DEPTNO=D.DEPTNO=D.

1 SELECT ENAME FROM EMP E . 20.DEPTNO=D.'YYYY')='2006' AND D.KING TURNER JAMES JOSEPH LIBIN ja JAMES suresh HARRIS rose 10 30 30 30 75 20 30 20 20 30 14 rows selected.DEPT D WHERE (E.LOC IN (SELECT LOC 2* FROM EMP WHERE LOC='&LOC')) sql>/ Enter value for loc: BANGALORE old 2: FROM EMP WHERE LOC='&LOC')) new 2: FROM EMP WHERE LOC='BANGALORE')) Wed Dec 06 Hi!!!!!! ENAME ---------ja suresh SEN .DEPTNO)AND (TO_CHAR(HIRE DATE.