72466951 oracle queries sheet

7

Click here to load reader

Upload: amanblr12

Post on 27-Apr-2015

148 views

Category:

Documents


0 download

DESCRIPTION

oracle

TRANSCRIPT

Page 1: 72466951 Oracle Queries Sheet

Oracle 9i – Query sheet

DEPT table is required with the following structure:

DEPTNO NUMBER(10)DNAME CHAR(30)LOC VARCHAR2(33)

EMP table is required with the following structure:

EMPNO NUMBER(2)ENAME VARCHAR2(15)JOB VARCHAR2(15) UNIQUEMGR CHAR(4)HIREDATE DATESAL NUMBER(6)COMM NUMBER(6) NOT NULLDEPTNO NUMBER(2)

1. Reduce the size of DEPTNO column of DEPT table to 2.

2. Change the data type of DNAME to VARCHAR2 and width to 15.

3. Reduce the width of LOC to 15.

4. Increase the size of EMPNO to 4.

5. Reduce the size of JOB to 10.

6. Change the data type of MGR to NUMBER(4).

7. SAL should accept 5 integers and 2 decimals.

8. COMM should accept 5 integers and 2 decimals.

9. JOB can be duplicate.

10. COMM can be NULL.

11. HIREDATE should not be SUNDAY.

12. SAL should be less than or equals to 10,000.

13. EMPNO should be primary key.

14. DEPTNO of DEPT table should be PRIMARY KEY.

15. DEPTNO of EMP table should be a foreign key to DEPTNO of DEPT table.

16. List of rows in DEPT table

DEPTNO DNAME LOC10 COMPUTERS HYDERABAD 20 ACCOUNTS MADRAS30 RESEARCH BANGLORE 40 SALES BOMBAY 50 OPERATIONS DELHI

Page 2: 72466951 Oracle Queries Sheet

17. List of rows of EMP table

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO7369 SMITH CLERK 7902 12/17/1980 800 207499 SMITH SALESMAN 7698 2/20/1981 1600 300 307521 WARD SALESMAN 7698 2/22/1981 1250 500 307566 JONES MANAGER 7839 4/2/1981 2975 207654 MARTIN SALESMAN 7698 9/28/1981 1250 1400 307698 BLAKE MANAGER 7839 5/1/1981 2850 307782 CLARK MANAGER 7839 6/9/1981 2450 107788 SCOTT ANALYST 7566 12/9/1982 3000 207839 KING PRESIDENT 11/17/1981 5000 107844 TURNER SALESMAN 7698 9/8/1981 1500 0 307876 ADAMS CLERK 7788 1/12/1983 1100 207900 JAMES CLERK 7698 12/3/1981 950 307902 FORD ANALYST 7566 12/3/1981 3000 207934 MILLER CLERK 7782 1/23/1982 1300 10100 MANAGER 7698 2000 100 10

18. List all the information about employees in the EMP table.

19. List all the information about the Departments in the DEPT table.

20. List all employees, number, name, job and hire dare of employees in department 10.

21. Select the name and salary of all employees who are CLERKS.

22. List the name, job and salary of everyone hired on December 17, 1980.

23. List the Department name and department number for departments with numbers greater than or equal to 20.

24. Select the name, salary and commission of employees whose commission is greater than their salary.

25. List the names of employees where salaries are less than 2500.

26. Display the name, monthly salary, daily salary and hourly salary for all employees. Assume that SAL column in the table is monthly salary; that there are 22 working days in a month; and that there are 8 working hours in a day. Rename the columns as MONTHLY, DAILY and HOURLY.

27. List the names and employee numbers of managers who earn more than 2600 in the order of names.

28. Select the information about managers and the president from the column job in the EMP table. Order the result by department number.

29. List all the employee names that do not end with ‘S’.

30. List all the employee names that start with ‘C’.

31. List the name, job and department of everyone whose name falls in the alphabetical range from ‘C’ to ‘F’.

32. List employee details working in department 20,30 and 40.

33. List of employees whose names start with ‘T’ and end with ‘R’.

34. Display all employee names start with ‘TH’ or ‘LL’.

35. Display all employees who are hired during 1983.

Page 3: 72466951 Oracle Queries Sheet

36. Display the data as Who.. What ..When. Ex:- SMITH HAS HELD THE POSITION OF CLERK IN DEPT 20 SINCE 13-JUN-83.

37. List the details of the employees in department 10 and 20 in alphabetical order of names.

38. List all rows from EMP table by converting the NULL values in COMM column to 0.

39. List all managers and salesman with salaries over 1500/-.

40. Write a query that will accept a given job and displays all records according to the job.

41. List all employees who do not get any commission.

42. Show the length of names from EMP table. Eliminate duplicate lengths from the output. Do not show the names themselves.

43. List the names and hire dates of employees in department 20. Display the hire dates as ‘DD/MM/YY’.

44. How many months has the president worked for the company? Round to the nearest whole number.

45. List all the employees whose hire date anniversary is in the month of December.

46. List all the employee names, jobs and a job classification, which you will supply. Translate the value stored in each job field (CLERK, MANAGER, etc) to a job Classification number (1, 2 etc.). Translate CLERK to 1. MANAGER to 3, PRESIDENT to 5 and all other jobs to 2. Name the job classification column JOB-CLASS.

47. Give SQL command to find the average annual salary per jobs in each department. The SAL figures in the EMP table are for each month.

48. In one query, count the number of people in department 30 who can receive a salary and the number of people who receive the commission.

49. Compute Average, Minimum and Maximum salaries of those groups of employees having the job of CLERK or Manager.

50. Display the department number where more than two clerks are working.

51. Calculate the total compensation expense for each department for one year. The Sal and Comm figures in the EMP tables are for each month. Assume that employees who don’t earn a commission receive non-monetary benefits that are worth Rs.100/-.

52. Do a case sensitive search for a list of employees with a job that a user enters.

53. Produce the names and jobs of employees as ex:- SMITH(clerk).

54. Which employees earn less than 30% of the president’s salary?

55. Who is the employee hired in all departments?

56. Create a view consisting of employees and their total sum of salary grouped by department number wise.

57. Create a view consisting of all the columns from EMP table and their corresponding records from dept table consisting of department name and location.

58. How many employees are working in BOMBAY?

59. Write a query to display the following output:

Name Hired onSmith June, Thirteen 1983Jones October, Thirty First 1983

60. Print the following: salary itself if it is 1500. ‘HIGH’ if it is more than 1500. ‘LOW’ if it is less than 1500.

61. Employees hired on or before the 15th of any month are paid on the last Friday of that month. Those hired after 15th are paid on the last Friday of the next month. Print a list of employees, their hire date and first payment date in the order of hire date.

62. Which employees are working in MADRAS?

63. Find the number of the different employees and number of departments.

64. Determine the average salary of employees.

Page 4: 72466951 Oracle Queries Sheet

65. List department number, department name, location, commission paid and total salary of each department.

66. Display the average monthly salary bill for each job type with in a department.

67. Display those jobs where the minimum salary is greater than or equal to 3000.

68. Find the average salary and average total remuneration for each job.

69. Find out the difference between highest and lowest salaries.

70. Find all Departments, which have more that 3 employees.

71. Check whether all employees’ number are indeed unique.

72. List lowest paid employees working for each manager; exclude any group where the minimum salary is less than 1000. in the reverse order of salaries.

73. Display all employee names and their department names in the order of department names.

74. Display all employee names, department numbers and department names.

75. Display the departments that have no employees.

76. Find all employees who joined the company before their managers.

77. Find the employees who earn more than the lowest salary in each department.

78. Display employees who earn more than the lowest salary in department 30.

79. Find employees who earn more than every employee in department 30.

80. Find the job with highest average salary.

81. Display the name, job, and hire date for employees whose salary is more than the highest salary in SALES dept.

82. Display total information of department 10.

83. Create A, B, C, D synonyms for DEPT; E, F, G, H synonyms for EMP tables.

84. Create a unique index for employee names of EMP table.

85. Assuming the salary of EMP table as for a month, produce annual salary with heading ‘ANNUAL SALARY’.

86. Select employee number and name combined to together with a heading ‘EMPLOYEE’.

87. Display in how many departments employees are working.

88. List the employees who are having experience of more than 10 years.

89. List the employees who have ‘I’ or ‘LL’ as the exact middle character(s) of their names.

90. Find all employees who have one of the three MGRs , accepted from the user.

91. List all employees whose name does not exceed 4 characters.

92. Find all employees who have no manager.

93. List the employees whose salary is out of the range from 2000 to 4000.

94. List the employees whose name bigger than their manager’s name.

95. List the employees who are managers of clerks with salary more than 2000.

96. Find all the managers in any department and all clerks in department 10 only.

97. Write a query to display information according to the expression entered by the user.

98. Display the department names in both cases.

99. Display the employee names in mixed cases.

Page 5: 72466951 Oracle Queries Sheet

100. List the employee names by adding ‘-‘on left side, to the double of the actual size of the name.

101. List the employee names where the second occurrence from second position is ‘A’.

102. List all the employees whose job does not start with ‘M’.

103. List the employees who have more than one Manager.

104. Display employee name, job, hire dare and salary combined together without using the ‘||’ operator.

105. List the Department names from DEPT table with the letters ‘A’ and ‘S’ removed from the left.

106. List the Department names from EMP table by removing ‘S’ from right side.

107. List the employee names which contain more than 6 letters.

108. List all the employee names. If the name contains ‘A’, it should be shown as ‘E’.

109. Select job from EMP. If the name contains ‘A’, it should be shown as ‘SALESPERSON’.

110. Display four characters from the literal ‘ORACLE’ starting from the second character and contents of Dname starting from the second character together.

111. List all Managers from all departments and all clerks from department 10 only.

112. List all employee names from EMP table if the name contains second and last-but-one characters as ‘A’.

113. List all the Department numbers from EMP table which do not exist in the DEPT table.

114. List all columns from both the DEPT and EMP tables.

115. Display different jobs and the number of employees working from EMP table.

116. List all the employees who are having experience more than their managers.

117. Display the difference between total salary of department 10 and department 20.

118. Count how many employees have ‘S’ in their names.

119. Produce this format: EMPLOYEE------------------------JOB --------------------------------------------- SMITH--------------------------CLERK ALLEN----------------------SALESMAN

120. List employee names and hire dates by adding one year to the hire date.

121. Find Maximum, Minimum and Average salaries from EMP table.

122. List the employee names who have minimum and maximum experience.

123. List the employees who are not working in ‘SALES’ and ‘COMPUTERS’.

124. Display the Cartesian product of EMP and DEPT tables.

125. List all employees who are earning more than the average salary of all employees.

126. Count how many duplicate records are there in the EMP table.

127. Delete all duplicate records if any in your employee table.

128. List all ROWIDs from EMP table.

129. List the ROW part of all the ROWIDs from EMP table.

130. Create a view with EMPNO, ENAME, JOB and SAL. Is manipulation possible in the view directly?

131. Create a view with different job and sum of salary from EMP table. Is manipulation possible in the view?

132. Create a view with DNAME, ENAME, SAL. Is it possible to manipulate the view directly?

Page 6: 72466951 Oracle Queries Sheet

133. Get all department numbers, which are present in DEPT table but not in EMP table.

134. List all employees who are hired in the last week of a month.

135. Who are the top three earners of the company?

136. In the employee table if the job is ‘CLERK’ change it to ‘WORKER’, if job is ‘MANAGER’ change it to ‘BOSS’ , otherwise change it to ‘EMPLOYEE’.

137. Find all employees who have the job equal to that of SMITH.

138. Create a sequence and change the Employees’ number of EMP table into serial numbers.

139. Display EMPNO, ENAME, HIREDATE, from EMP table. Against the employee who is most recently hired, ‘*’ should be displayed.

140. Display the employee names by interchanging the first and last letters.

141. Display the experience of employees in years, months, weeks and days.

142. Display the difference between Maximum salary and Minimum salary from EMP table.

143. Write a query to accept four digit numbers and display it in spelled format.

144. Write a query to accept a name and display it by prefixing itself with its first character for 5 times.

145. Write a query to display a character in Pyramid format.

146. Write an SQL statement to store the MGRs of employees in EMP table as their Managers’ EMPNO.

147. Write an SQL statement to insert a record into DEPT table. If the user provides a value for LOC. It should be inserted; otherwise ‘HYDERABAD’ should be inserted as default.

148. Display the department in which more than one CLERk is working.

149. Display the department in which maximum number of employees is working.

150. In which location maximum number of employees is working?

151. Which department is drawing maximum salary portion?

152. Who is the top third earner?

153. Write an SQL statement to refresh the salaries, according to experience of the employees. For one year of experience, the salary will be 1000.

154. Write an SQL statement to accept date of birth and display the age in years, months, weeks, days, hours, minutes and seconds separately.

155. Write an SQL statement to accept age in years and display the year of birth.

156. Write an SQL statement to accept a four-digit year and display whether it is a leap year or not.

157. Write an SQL statement to accept a name from the user and display each character repeated for ‘n’ number of times, where ‘n’ is the character position.

158. Display the employees who are highly experienced in each department.

159. Change the commissions of employees as a percentage on salary. The percentage is their department number itself.

160. Find whether a given number is positive or negative.

161. Display the difference between the maximum and minimum salaries.

162. Display the mathematical table for a number given by the user.

163. Display whether a given number is odd or even.

Page 7: 72466951 Oracle Queries Sheet