Академический Документы
Профессиональный Документы
Культура Документы
13) To select those , whose last names are a phonetic representation of 'SMYTHE'
:
select * from emp where soundex(ename)=soundex('SMYTHE')
To select those , whose job is phonetic representation of 'SALESMEN' :
select * from emp where soundex(job)=soundex('SALESMEN');
14) To display employee details of workers who joined before their managers :
select a.ename from emp a, emp b where a.mgr=b.empno and a.hiredate<b.hi
redate;
15) Display the names of employees whose sal is greater than max sal of sales :
select * from emp where sal >(select max(sal) from emp , dept where emp.
deptno=dept.deptno and dname='SALES');
16) Display the employee name , who is drawing histet salary :
select * from emp where sal=(select max(sal) from emp);
17) TO list the employees in deptno =10 with common jobs in depnto=20 :
select a.ename,a.empno,b.ename,b.empno from emp a , emp b where
a.job=b.job and a.deptno=10 and b.deptno=20;
18) To list the employees who have both the same job and same salary as SCOTT :
select * from emp where job=(select job from emp where ename='SCOTT')
and sal=(select sal from emp where ename='SCOTT') and ename!='SCOTT'
19) List the employees who have the same job as SMITH or Sal < Jones in order by
job,sal :
select * from emp where job=(select job from emp where ename='SMITH') or
sal <(select sal from emp where ename='JONES')
order by job,sal
20) Select all employees where ENAME should not begin with A :
select * from emp where ename not like 'A%';
21) Display last three characters of each employee :
select ename, substr(ename,-3) from emp;
From last three characters of name , display first two characters :
select ename, substr(ename,-3,2) from emp;
22) To Display the names of employees whose name have two A's in their name :
select * from emp where ename like 'A%A' or ename like '%AA%' or ename l
ike '%A%A%';
23) List the details of employees whose sal is greater than average sal :
select * from emp where sal >(select avg(sal) from emp);
24) Select Minium, Maxium, Average Salaries Department wise :
select min(sal),max(sal),avg(sal),deptno from emp group by deptno;
25) Display the number of employees in each department :
select count(*),deptno from emp group by deptno;
26) List the average sal for all employees :
select avg(sal) from emp;
27) Display all employees whose department is 10 :
select * from emp where deptno=10;
28) Display all employees whose sal lie between 2000 and 5000 :
select * from emp where deptno=10;
29) Display names of all employees whose name starts with letter 'S' :
select * from emp where ename like 'S%';
30) List names of all employees whose name have more than FIVE letters :
select * from emp where ename like '%_____%';
31) Display the names of employees whose name have only four letters :
select * from emp where ename like '____';
32) To select Day from a date :
For day :
select to_char(hiredate,'dd') from emp;
For Week :
select to_char(hiredate,'day') from emp;
33) To select Month from a date :
For Month in Number :
select to_char(hiredate,'mm') from emp
For Month in Characters :
select to_char(hiredate,'mon') from emp
34) To select Year from a date :
select to_char(hiredate,'yy') from emp
select to_char(hiredate,'yyyy') from emp
71) Display the list of employees , number of employees joined in each year :
select count(*), to_char(hiredate,'yyyy') from emp group by to_char(hire
date,'yyyy');
72) Dislpaly the year in which , maximum employees recruited :
select to_char(hiredate,'yy') from emp having count(*)=(select max(count
(*)) from emp group by to_char(hiredate,'yy') ) group by to_char(hiredate,'yy')
;
73) TRUNC :
select trunc(15.7) from dual; output --> 15
select trunc(15.4) from dual; output --> 15
select trunc(15.678,2) from dual; output --> 15.67
select trunc(15.678,1) from dual; output --> 15.6
select trunc(15.678,-1) from dual; output --> 10
select trunc(15.678,-2) from dual; output --> 0
select trunc(115.678,-2) from dual; output --> 100
select trunc(115.678,-3) from dual; output --> 0
74) ROUND :
select round(15.7) from dual; output --> 16
select round(15.4) from dual; output --> 15
select round(115.5,-1) from dual; output --> 120
select round(115.5,-2) from dual; output --> 100
75) MOD :
select mod(99,4) from dual; output --> 3
76) Operators :
select 5/2 from dual; output --> 2.5
select 5*3 from dual; output --> 15
select 5+3 from dual; output --> 8
select 5-3 from dual; output --> 2
77) FLOOR :
select floor(3.4) from dual; output --> 3
select floor(3.7) from dual; output --> 3
78) CEIL :
select ceil(3.4) from dual; output -->4
select ceil(3.7) from dual; output -->4
79) SUBSTR :
select ename,substr(ename,1,3) from emp;
select ename,substr(ename,-3,3) from emp;
80 ) TRANSLATE :
select translate('RAGHU40020','ABCDEFGHIJKLMNOPQRSTUVWXYZ012345789',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ') from dual;
select translate('RAGHU40020','ABCDEFGHIJKLMNOPQRSTUVWXYZ012345789',
' 0123456789') from dual
81) INSTR :
It used to search the place of a substring in a string.
select instr('RAGHU','G',1) from dual; output --> 3
select instr('RAGHU','GH',1) from dual; output --> 3
select instr('RAGHU','GU',1) from dual; output --> 0
82) Arthmatic Fuction :
sin,sinh,cos,cosh,tan,tanh etc..
select sin(A) from dual; NOTE : A should be in Radians
select sin(30) from dual; output --> -.98803162
select exp(2) from dual; output --> 7.3890561
select log(100,10) from dual; output --> 0.5
LOG takes two arguments.
select ln(10) from dual; output --> 2.30258509
POWER :
To raise one number to the power of another , use power. In this
function the first argument is raised to the power of second argu
ment.
select power(2,3) from dual; output --> 8
select power(-2,3) from dual; output --> -8
select power(2,-3) from dual; output --> 0.125
select power(-2,-3) from dual; output --> -0.125
83) SIGN :
Sign returns 1 if its argument is greater than zero, -1 if its argument
is lesser than zero , 0 if its argument is equal to zero.
select sign(10-2) from dual; output --> 1
select sign(2-10) from dual; output --> -1
select sign(3-3) from dual; output --> 0
84) SQRT :
select sqrt(16) from dual; output --> 4
85) LPAD,RPAD :
select lpad('Raghu',4) from dual; output --> Ragh
select lpad('Raghu',2) from dual; output --> Ra
select lpad('Raghu',1) from dual; output --> R
select rpad('Raghu',2) from dual; output --> Ra
select rpad('Raghu',4) from dual; output --> Ragh