Oracle 9i – Query sheet

DEPT table is required with the following structure: DEPTNO DNAME LOC NUMBER(10) CHAR(30) VARCHAR2(33)

EMP table is required with the following structure: EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO NUMBER(2) VARCHAR2(15) VARCHAR2(15) UNIQUE CHAR(4) DATE NUMBER(6) NUMBER(6) NOT NULL NUMBER(2)

Reduce the size of DEPTNO column of DEPT table to 2. Change the data type of DNAME to VARCHAR2 and width to 15. Reduce the width of LOC to 15. Increase the size of EMPNO to 4. Reduce the size of JOB to 10. Change the data type of MGR to NUMBER(4). SAL should accept 5 integers and 2 decimals. COMM should accept 5 integers and 2 decimals. JOB can be duplicate. COMM can be NULL. HIREDATE should not be SUNDAY. SAL should be less than or equals to 10,000. EMPNO should be primary key. DEPTNO of DEPT table should be PRIMARY KEY. DEPTNO of EMP table should be a foreign key to DEPTNO of DEPT table. List of rows in DEPT table

.

.

.

.

.

.

.

.

0.

1.

2.

3.

4.

5.

6.

DEPTNO 10 20 30 40 50

DNAME COMPUTERS ACCOUNTS RESEARCH SALES OPERATIONS

LOC HYDERABAD MADRAS BANGLORE BOMBAY DELHI

28. 27. 30. List of employees whose names start with ‘T’ and end with ‘R’. 29. 25. 20. 19. List the names and employee numbers of managers who earn more than 2600 in the order of names. 35. 33. 1980. DAILY and HOURLY. monthly salary. Display all employee names start with ‘TH’ or ‘LL’. daily salary and hourly salary for all employees. List all the information about the Departments in the DEPT table. Rename the columns as MONTHLY. List employee details working in department 20.17. Order the result by department number. Select the name and salary of all employees who are CLERKS. List the Department name and department number for departments with numbers greater than or equal to 20. 26. that there are 22 working days in a month. 31. List all the information about employees in the EMP table. Select the name. job and hire dare of employees in department 10. number. List all the employee names that start with ‘C’.30 and 40. List all the employee names that do not end with ‘S’. 23. 24. Display the name. List the name. salary and commission of employees whose commission is greater than their salary. Assume that SAL column in the table is monthly salary. List of rows of EMP table EMPNO 7369 7499 7521 7566 7654 7698 7782 7788 7839 7844 7876 7900 7902 7934 100 ENAME SMITH SMITH WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER JOB CLERK SALESMAN SALESMAN MANAGER SALESMAN MANAGER MANAGER ANALYST PRESIDENT SALESMAN CLERK CLERK ANALYST CLERK MANAGER MGR 7902 7698 7698 7839 7698 7839 7839 7566 7698 7788 7698 7566 7782 7698 HIREDATE 12/17/1980 2/20/1981 2/22/1981 4/2/1981 9/28/1981 5/1/1981 6/9/1981 12/9/1982 11/17/1981 9/8/1981 1/12/1983 12/3/1981 12/3/1981 1/23/1982 SAL 800 1600 1250 2975 1250 2850 2450 3000 5000 1500 1100 950 3000 1300 2000 COMM 300 500 1400 0 100 DEPTNO 20 30 30 20 30 30 10 20 10 30 20 30 20 10 10 18. . job and salary of everyone hired on December 17. 34. 21. job and department of everyone whose name falls in the alphabetical range from ‘C’ to ‘F’. Display all employees who are hired during 1983. and that there are 8 working hours in a day. List the name. name. List all employees. Select the information about managers and the president from the column job in the EMP table. 22. List the names of employees where salaries are less than 2500. 32.

List all rows from EMP table by converting the NULL values in COMM column to 0. Thirteen 1983 October. 53. Write a query that will accept a given job and displays all records according to the job. Write a query to display the following output: Name Smith Jones Hired on June. Compute Average. Ex:. Translate the value stored in each job field (CLERK. Show the length of names from EMP table. Which employees earn less than 30% of the president’s salary? 55. ‘LOW’ if it is less than 1500. Calculate the total compensation expense for each department for one year. 49. MANAGER to 3. count the number of people in department 30 who can receive a salary and the number of people who receive the commission. 39. 58. Create a view consisting of all the columns from EMP table and their corresponding records from dept table consisting of department name and location. 41. Thirty First 1983 0. 44. Give SQL command to find the average annual salary per jobs in each department.SMITH HAS HELD THE POSITION OF CLERK IN DEPT 20 SINCE 13-JUN83. 45. MANAGER. 54. 51. List all the employees whose hire date anniversary is in the month of December. Who is the employee hired in all departments? 56. 2. The SAL figures in the EMP table are for each month. Name the job classification column JOB-CLASS. Produce the names and jobs of employees as ex:.. . Do a case sensitive search for a list of employees with a job that a user enters. PRESIDENT to 5 and all other jobs to 2.. The Sal and Comm figures in the EMP tables are for each month.SMITH(clerk). jobs and a job classification. etc) to a job Classification number (1. 2 etc. 47. Do not show the names themselves. Display the hire dates as ‘DD/MM/YY’.When. List all employees who do not get any commission. Display the data as Who. 43. ‘HIGH’ if it is more than 1500. In one query. their hire date and first payment date in the order of hire date.100/-. 37. 46. Print the following: salary itself if it is 1500. 3. Translate CLERK to 1. 38. Which employees are working in MADRAS? Find the number of the different employees and number of departments. Employees hired on or before the 15th of any month are paid on the last Friday of that month. List the details of the employees in department 10 and 20 in alphabetical order of names. List all managers and salesman with salaries over 1500/-. 50. List all the employee names. Eliminate duplicate lengths from the output. Those hired after 15th are paid on the last Friday of the next month.36. List the names and hire dates of employees in department 20. 40. 1. which you will supply. How many months has the president worked for the company? Round to the nearest whole number. What . Create a view consisting of employees and their total sum of salary grouped by department number wise. Determine the average salary of employees. Display the department number where more than two clerks are working. Assume that employees who don’t earn a commission receive non-monetary benefits that are worth Rs. Print a list of employees.). How many employees are working in BOMBAY? 59. 52. 4. 57. 48. 42. Minimum and Maximum salaries of those groups of employees having the job of CLERK or Manager.

List the employees whose name bigger than their manager’s name. 3. commission paid and total salary of each department. 1. 6. List the employees who are managers of clerks with salary more than 2000. 5. Find all Departments. Display in how many departments employees are working. Write a query to display information according to the expression entered by the user. B. List the employees whose salary is out of the range from 2000 to 4000. List all employees whose name does not exceed 4 characters. 2. 7. 0. Display employees who earn more than the lowest salary in department 30. C. Check whether all employees’ number are indeed unique. E. 0. 6. 2. Create A. in the reverse order of salaries. 1. Select employee number and name combined to together with a heading ‘EMPLOYEE’. and hire date for employees whose salary is more than the highest salary in SALES dept. G. Display the departments that have no employees. Find the job with highest average salary. 9. 9. 3. Display the department names in both cases. Find out the difference between highest and lowest salaries. . List lowest paid employees working for each manager. 5. Find all employees who have one of the three MGRs . List the employees who are having experience of more than 10 years. Display total information of department 10. Find all employees who have no manager. Find employees who earn more than every employee in department 30. Find all the managers in any department and all clerks in department 10 only. Assuming the salary of EMP table as for a month. 1. Display the average monthly salary bill for each job type with in a department. 4. 9. H synonyms for EMP tables. F. Display all employee names. 3. 9. 7. Create a unique index for employee names of EMP table. 8.5. 7. 0. Find the employees who earn more than the lowest salary in each department. 8. 8. Display the employee names in mixed cases. 6. Display those jobs where the minimum salary is greater than or equal to 3000. 4. List the employees who have ‘I’ or ‘LL’ as the exact middle character(s) of their names. Display the name. which have more that 3 employees. department name. 6. Find all employees who joined the company before their managers. exclude any group where the minimum salary is less than 1000. D synonyms for DEPT. Find the average salary and average total remuneration for each job. Display all employee names and their department names in the order of department names. job. 4. 7. 8. accepted from the user. List department number. location. 5. 2. produce annual salary with heading ‘ANNUAL SALARY’. department numbers and department names.

SAL. List all the employees whose job does not start with ‘M’. List the Department names from EMP table by removing ‘S’ from right side. 114. Display employee name. 130. List the employees who have more than one Manager. 121. 111. 117. 122. List the Department names from DEPT table with the letters ‘A’ and ‘S’ removed from the left. hire dare and salary combined together without using the ‘||’ operator. Display different jobs and the number of employees working from EMP table. List all employees who are earning more than the average salary of all employees. 102. 103. List all employee names from EMP table if the name contains second and last-but-one characters as ‘A’. Is it possible to manipulate the view directly? 120. job. 109. Create a view with EMPNO. List all the Department numbers from EMP table which do not exist in the DEPT table. Produce this format: EMPLOYEE------------------------JOB --------------------------------------------SMITH--------------------------CLERK ALLEN----------------------SALESMAN List employee names and hire dates by adding one year to the hire date. 110. If the name contains ‘A’. 118. List all columns from both the DEPT and EMP tables. 123. 126. Delete all duplicate records if any in your employee table. List all ROWIDs from EMP table. Count how many duplicate records are there in the EMP table. List the ROW part of all the ROWIDs from EMP table. 108. . 107. JOB and SAL. List the employee names who have minimum and maximum experience. 116. List all Managers from all departments and all clerks from department 10 only. List the employee names which contain more than 6 letters. Display the difference between total salary of department 10 and department 20. 129. List the employees who are not working in ‘SALES’ and ‘COMPUTERS’. 128. 105. If the name contains ‘A’. Select job from EMP. List the employee names by adding ‘-‘on left side. 106. it should be shown as ‘SALESPERSON’. Is manipulation possible in the view directly? Create a view with different job and sum of salary from EMP table. 124. 101. Is manipulation possible in the view? Create a view with DNAME. 132. Display four characters from the literal ‘ORACLE’ starting from the second character and contents of Dname starting from the second character together. 125. List the employee names where the second occurrence from second position is ‘A’. Minimum and Average salaries from EMP table. List all the employee names. ENAME.100. List all the employees who are having experience more than their managers. Count how many employees have ‘S’ in their names. ENAME. to the double of the actual size of the name. 112. 131. 127. Find Maximum. 115. Display the Cartesian product of EMP and DEPT tables. it should be shown as ‘E’. 113. 119. 104.

161. 155. Display the employees who are highly experienced in each department. Who are the top three earners of the company? In the employee table if the job is ‘CLERK’ change it to ‘WORKER’. 153. 146. otherwise ‘HYDERABAD’ should be inserted as default. Write a query to display a character in Pyramid format. Write an SQL statement to accept a name from the user and display each character repeated for ‘n’ number of times. from EMP table. Create a sequence and change the Employees’ number of EMP table into serial numbers. 160. days. Write an SQL statement to accept age in years and display the year of birth.133. Write a query to accept four digit numbers and display it in spelled format. weeks. 135. Change the commissions of employees as a percentage on salary. Find whether a given number is positive or negative. 158. otherwise change it to ‘EMPLOYEE’. according to experience of the employees. 156. Get all department numbers. Find all employees who have the job equal to that of SMITH. 149. 151. 159. In which location maximum number of employees is working? Which department is drawing maximum salary portion? Who is the top third earner? Write an SQL statement to refresh the salaries. months. Write an SQL statement to insert a record into DEPT table. It should be inserted. 148. where ‘n’ is the character position. Display EMPNO. which are present in DEPT table but not in EMP table. if job is ‘MANAGER’ change it to ‘BOSS’ . . ENAME. 145. 154. If the user provides a value for LOC. 141. List all employees who are hired in the last week of a month. months. weeks and days. Display the experience of employees in years. 144. Write a query to accept a name and display it by prefixing itself with its first character for 5 times. 162. Write an SQL statement to accept a four-digit year and display whether it is a leap year or not. 137. Write an SQL statement to store the MGRs of employees in EMP table as their Managers’ EMPNO. Display the mathematical table for a number given by the user. 136. Display the department in which more than one CLERk is working. Display the employee names by interchanging the first and last letters. 138. 134. Display whether a given number is odd or even. 152. The percentage is their department number itself. 150. Display the difference between the maximum and minimum salaries. ‘*’ should be displayed. Display the department in which maximum number of employees is working. Against the employee who is most recently hired. Display the difference between Maximum salary and Minimum salary from EMP table. 142. 143. the salary will be 1000. 139. HIREDATE. 140. For one year of experience. 147. Write an SQL statement to accept date of birth and display the age in years. 163. 157. hours. minutes and seconds separately.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.