1)Select those employees who comm is null : select * from emp where comm is null; 2)Select list of managers

and corresponding Clerks : select a.ename "Manager" , b.ename "Clerk" from emp a, emp b where b.mgr=a.empno ; 3)Select list of employee name with their deptno,dname and loc : select empno,emp.deptno,dname,loc from emp,dept where emp.deptno=dept.deptno 4)Select 2nd maximum salary from emp table : select max(sal) from emp where sal<(select max(sal) from emp); Select 5th maximum salary : select max(sal) from emp a where 5 =(select count(*) from emp b where a.sal<b.sa l);

5)Select Alternate Rows from a table : For Odd Rows : select * from emp where mod(ascii(substr(rowid,18)),2)=0 For Even Rows : select * from emp where mod(ascii(substr(rowid,18)),2)=1

6) How do I get a random number in Oracle query : select dbms_random.random from dual; a Java SDK provides API for generation of Random numbers. Please refer jav documentation of java.util.Random class.

7) To Select Least ,Greatest Numbers : select select select select least(1,2) from dual greatest(1,2) from dual greatest(1.2,2.3) from dual least(1.2,2.3) from dual

8) To Round a number : select ceil(1208917.97802706) from dual; 9) To Truncate a number : select floor(1208917.97802706) from dual; 10) Select employees who joined before their manager : select a.empno,a.ename from emp a, emp b where a.mgr=b.empno and a.hired ate<b.hiredate;

sal 20) Select all employees where ENAME should not begin with A : .a.'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'. 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 . who is drawing histet salary : select * from emp where sal=(select max(sal) from emp). 13) To select those .ename. To Select Only Numbers from a combination of numbers and characters : //26 Empty Spaces select translate('RAGHU40020'. 12) To get those employee whose name ends with 'RD' : select * from emp where ename like '%RD'. deptno=dept.deptno and dname='SALES'). 17) TO list the employees in deptno =10 with common jobs in depnto=20 : select a.empno from emp a .ename. 16) Display the employee name . emp b where a.ename from emp a. dept where emp. whose job is phonetic representation of 'SALESMEN' : select * from emp where soundex(job)=soundex('SALESMEN').empno and a.b.empno.hiredate<b.job and a.11) To Select Only Characters from a combination of numbers and characters : select translate('RAGHU40020'. emp b where a.' 0123456789') FROM dual. whose last names are a phonetic representation of 'SMYTHE' : select * from emp where soundex(ename)=soundex('SMYTHE') To select those .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.mgr=b.hi redate.deptno=20. 14) To display employee details of workers who joined before their managers : select a.b.job=b.deptno=10 and b. 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.'ABCDEFGHIJ KLMNOPQRSTUVWXYZ') FROM dual.'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.

deptno from emp group by deptno. Average Salaries Department wise : select min(sal). 25) Display the number of employees in each department : select count(*). 31) Display the names of employees whose name have only four letters : select * from emp where ename like '____'. substr(ename. display first two characters : select ename.-3) from emp.-3. 30) List names of all employees whose name have more than FIVE letters : select * from emp where ename like '%_____%'. 24) Select Minium. 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%'.max(sal). 28) Display all employees whose sal lie between 2000 and 5000 : select * from emp where deptno=10.'dd') from emp. Maxium.deptno from emp group by deptno.'day') from emp. For Week : select to_char(hiredate. 23) List the details of employees whose sal is greater than average sal : select * from emp where sal >(select avg(sal) from emp). 26) List the average sal for all employees : select avg(sal) from emp. 29) Display names of all employees whose name starts with letter 'S' : select * from emp where ename like 'S%'.select * from emp where ename not like 'A%'. substr(ename. 33) To select Month from a date : . 27) Display all employees whose department is 10 : select * from emp where deptno=10.avg(sal). 21) Display last three characters of each employee : select ename. From last three characters of name .2) from emp. 32) To select Day from a date : For day : select to_char(hiredate.

dept b where a.3) from emp. employee name and their salaries Prefix with Dolla r sign in .comm. (Assume .100) from emp.sal+nvl(comm.comm.'dd') < 20 and to_char(hiredate .'mon') from emp 34) To select Year from a date : select to_char(hiredate.deptno.sal+nvl(comm.deptno and a. 41) List the department name and location for emplyoees who earn more than 1500 : select a.sal >1500 42) Select Last three characters of each employee : select ename. 36) List the details of employees who joined after 1st December 1980 and before 1st December 1981 : select * from emp where hiredate between to_date('01-12-1980'. then comm = 0 ) : select sal.For Month in Number : select to_char(hiredate. then comm = 100 ) : select sal. 38) List the details of employees who joined before 20th of any month and year e xcept 1981 : select * from emp where to_char(hiredate.'dd-mm-yyy y') and to_date('01-12-1981'.'yy') from emp select to_char(hiredate.0) from emp.ename.substr(ename.loc.'mm')=2. if comm is null . if comm is null . select * from emp where hiredate like '%FEB%'.dname.'yyyy') != 1981 39) List the deatils of employees who enjoy comm more than 250 : select * from emp where comm >250.-3. 40) List the sum of Sal and Comm (Assume .deptno=b.'dd-mm-yyyy') 37) List the details of employees who earn more than 2000 and doesnot enjoy any comm : select * from emp where sal > 2000 and comm is null.'yyyy') from emp 35) Display details of employees who joined in February : select * from emp where to_char(hiredate. 43) Display the employee id .b.'mm') from emp For Month in Characters : select to_char(hiredate.sal from emp a.

'Equal') from emp. 54) Display number of employees joined in year 81 : select count(*) from emp where to_char(hiredate. 49) List most experienced employee : select * from emp where hiredate=(select min(hiredate) from emp).'yy') = 81. in which no employee has been recruited : select deptno. if sal > 1500 . 53) Display sal Greater Lesser Equal of employees with information : .'mm')=to_char(sysdate. 240 months means 20 years 52) Display the details of employees who have joined before BLAKE : select * from emp where hiredate < ( select hiredate from emp where enam e='BLAKE').'SALESMAN'. . if sal < 1500 .'Greater'.decode(job.'yy')) group by to_cha r(hiredate.hiredate) > 240. decode(sign(sal-1500).decending order : column sal format $99.1. job from emp where job='CLERK' or job='MANAGER' group b y job.'yy') from emp having count(*) =(select max(count(*)) from emp group by to_char(hiredate.'yy') 47) Display departments which has more than 3 employees : select deptno from emp having count(*) >3 group by deptno. Here .-1. 50) List employees who celebrate their birthday in current month : select * from emp where to_char(hiredate.job) FROM emp 45) Display deptname .'Lesser'.990 select sal from emp. 51) Display the details of employees completing 20 years of service : select * from emp where months_between(sysdate. 46) In which year maximum employee were recruited : select to_char(hiredate.'SALESPERSON'. 44) Display Job ( Replacing 'SALESMAN' with 'SALESPERSON' ) of employees : select job.loc from dept where deptno=(select deptno from dept minus select distinct deptno from emp).'mm'). if sal = 1500 select sal.dname. 48) List out number of clerks and number of managers : select count(*).

sal=b.empno.'dd-mon-yy'). 63) Display the first five rows : select * from emp where rownum<6. 60) Select number of managers : select count(*) from emp where job='MANAGER'.55) Display all employees who joined before 28-sep-81 : select * from emp where to_date(hiredate.ename from emp a .'dd-mon-yy') < to_date('28-sep81'.'dd-mon-yy') between to_date( '20-feb-81'.'dd-mon-yy').sal and a. 56) Display all employees who joined after 09-jun-81 : select * from emp where to_date(hiredate. 62) List the employees . who are earning same salary : select a. 67) Write a query to increment basic salary (salary + comm) by 10% for those emp loyees whose basic salary is less than 1000 and 20% : . 65) List out the details of those employees whose salary is greter than the aver age salary of their dept : 66) List the last five employees from emp : select * from emp minus select * from emp where rownum < 10.deptno from emp group by deptno. 58) To get a ASCII value for a character : select ascii('C') from dual. 61) List the number of employees in each dept : select count(*). 59) Display the list who joined between 20-feb-81 and 03-dec-81 : select * from emp where to_date(hiredate.'dd-mon-yy').'dd-mon-yy') > to_date('09-jun81'.deptno and a.ename. emp b where a. 64) Display details about 5th employee : select * from emp where rownum < 6 minus select * from emp where rownum < 5.b. 57) To get a equalent Character for a ASCII value : select chr(67) from dual.empno!=b.deptno=b.'dd-mon-yy') and to_date('03-dec-81'.

-2) from dual. 72) Dislpaly the year in which . trunc(15.1) from dual. trunc(115.1*sal+nvl(comm. trunc(15.4) from dual. round(15. round(115.0))) from emp where sal <=1000 union select sal.5 output --> 15 output --> 8 output --> 3 round(15. 70) Display most expereiced employee : 71) Display the list of employees .'yy') .6 10 0 100 0 .'yy') ) group by to_char(hiredate. trunc(15. to_char(hiredate.0))) from emp where sal >=1000 68) Display the top 3 salaries from emp table : 69) Display experience of each employee : select months_between(sysdate.7) from dual.4) from dual.2*sal+nvl(comm.hiredate) from emp. trunc(115.-3) from dual.678.'yyyy'). trunc(15.'yyyy') from emp group by to_char(hire date.decode(sal. output --> 2.(sal+0.decode(sal.-2) from dual.678. select 5+3 from dual. maximum employees recruited : select to_char(hiredate. output output output output output output output output --> --> --> --> --> --> --> --> 15 15 15. round(115.-1) from dual.678.'yy') from emp having count(*)=(select max(count (*)) from emp group by to_char(hiredate.7) from dual.-2) from dual. 73) TRUNC : select select select select select select select select 74) ROUND : select select select select 75) MOD : select mod(99.2) from dual.sal.4) from dual. select 5*3 from dual.5.678.67 15. 76) Operators : select 5/2 from dual.(sal+0.678. trunc(15.678. number of employees joined in each year : select count(*).select sal.5. output output output output --> --> --> --> 16 15 120 100 trunc(15.sal.-1) from dual.

78) CEIL : select ceil(3. power(2.3) from emp.125 -0.3) from dual.-3.substr(ename.-3) from dual.cosh. power(-2. ' select translate('RAGHU40020'.substr(ename.-3) from dual.'GH'. select sin(30) from dual.3) from dual. select exp(2) from dual.sinh. In this the first argument is raised to the power of second argu select select select select power(2. select ln(10) from dual. select floor(3. select instr('RAGHU'. output output output output --> --> --> --> 8 -8 0. To raise one number to the power of another . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') from dual. 0123456789') from dual 81) INSTR : It used to search the place of a substring in a string. 79) SUBSTR : output --> 2 output --> 3 output --> 3 output -->4 output -->4 select ename.cos.'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345789'.'GU'.'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345789'.4) from dual. 82) Arthmatic Fuction : sin. 77) FLOOR : select floor(3.7) from dual.4) from dual.5 LOG takes two arguments.125 output --> 2.1) from dual. POWER : function ment.tan.10) from dual. select ename.30258509 .7) from dual. power(-2.3890561 output --> 3 output --> 3 output --> 0 select log(100. select instr('RAGHU'. output --> 0.tanh etc.1) from dual. select instr('RAGHU'. select sin(A) from dual.'G'.1) from dual. NOTE : A should be in Radians output --> -. select ceil(3. 80 ) TRANSLATE : select translate('RAGHU40020'.select 5-3 from dual.98803162 output --> 7..3) from emp.1. use power.

-1 if its argument is lesser than zero .RPAD : select lpad('Raghu'. select rpad('Raghu'.2) from dual.1) from dual. 0 if its argument is equal to zero. 85) LPAD. select sign(3-3) from dual.4) from dual. 84) SQRT : select sqrt(16) from dual. select rpad('Raghu'. select sign(2-10) from dual. select lpad('Raghu'. output --> Ragh output --> Ra output --> R output --> Ra output --> Ragh output --> 4 output --> 1 output --> -1 output --> 0 .2) from dual.4) from dual.83) SIGN : Sign returns 1 if its argument is greater than zero. select sign(10-2) from dual. select lpad('Raghu'.

Sign up to vote on this title
UsefulNot useful