You are on page 1of 10

1.1.

Data Retrieval Part I 1.

Exercise

See table structure of Designation_Master, Department_Master, Student_Master, Student_Marks, Staff_Master, Book_Master and Book_Transaction table. Query Student_Code, Student_Name and Department_Code of every Student. Retrieve detail of every Student and Staff. Display Student_Code, Subjects and Total_Marks for every student. Total_Marks will calculate as Subject1 + Subject2 + Subject3 from Student_Marks. . Display Student_Code, Student_Year, Subjects and Percentage of all student and heading for the columns would be Student#, Join_Year, Subject1, Subject2, Subject3, Total, and Percentage from Student_Marks. Create a query to display unique Department_Code from Student_Master table. . Create a query which will display all students’ data those who are passing (getting pass Subject1 + Subject2 + Subject3 > 180. And save the query . Create a query which displays Student_Code, Join_Year and Subject 1 of all students who scored more than 75 in Subject1. And save the query Modify the query to display student detail of those who getting marks in Subject1 between 50 and 75. And save the query . Write a query which will display Student_Name, Departmnet_Code and DOB of all students who born between January 1, 1981 and March 31, 1983. Order the query in ascending order of DOB.

2.
3.

4.
5.

6. 7. 8.
9.

10. . Write a query which will display Student_Name, Department_Code of all students’ studies in departments 10 and 30, in alphabetical order by name. 11. Select Student_Name and Department_Code of all students those who have born in 1982. 12. . Display Book_Details for all books which have not being returned. 13. . Display Book_Details for all books which have not being returned and expected returned was last Monday. 14. . Select all students who have completed 25 years of age and their name starts with ‘S’; 15. . Display Student_Code & Year, of all students who is getting more than 60 in each subject and aggregate of marks is greater then 190 for year 2006 or 2007.

27. 99. . Grade depends on the following table. 31. Format the dream salary as Rs. . Each X represents a 1000 in Salary. Display Student_Code. 30. Create a Query which displays the Student_Name and Department_Code. Order the result by the day of the week staring with Monday. Label the column as “Department”. Hiredate and day of the week on which staff was hired. KING FORD 12000 10000 XXXXXXXXXX XXXXXXXXXXXX 24. 12 1981” for those who born on Saturday or Sunday. . 25. . and Grade of all staff. 17. 19. List the Book details issued to Students for current month and last month. Label the column as “Diff_Marks”. Format the salary to be 15 character long and left padded with ‘$’. Total_Marks. Write a query that displays Staff_Name. Label the Column REVIEW 26. Display the Staff_Name. <Staff_Name> earns <Salary> monthly but wants <2 times salary. Subject1. Display each Staff_Name and number of months he worked for the organization.999. 21. Write a query that produces the following for each staff : 28. 22. Sample Output. Write a query which displays Student_Name in upper case. Create a query which will display Staff_Name. Hiredate and review date of all staff.00. List all Table Name contains ‘MASTER’ in their names. Salary of each staff. Modify the query to add a column that will find the difference between Total_Marks and Maximum_Marks. Subject2. Student_Name first letter capitalized and all other letters lower case and length of the Student_Name for all students whose name starts with ‘S’ or ‘J’. 29. Salary Salary >=50000 Grade A . If student does not belong to any department. Label the column as ‘MONTHS WORKED’. Display Student_Name and Date of birth where DOB must be displayed in the format similar to “January. Label the column as DAY. Display Staff_Name. 18. 20. .16. 23. Salary. put “No Department”. Review date is first Monday after six months of Service. . Subject3. Label the column as DREAM SALARY. Display the Staff_Name Staff_Salary and the Salary in X. Order your result by number of months employed. Create a Query which display the Student_Name and Department_Code and Total_Marks and order it on Total_Marks descending and Student_Name ascending. and Percentage as whole number for current year and percentage should be greater that 75. Round the number of months to closest whole number.

43. 41.Salary >= 25000 < 50000 Salary>=10000 < 25000 OTHERS B C D 32. 2002”. Display the Highest. 44. Write a query which displays Staff_Name. Manager. 38. Order you result on descending order of salary. 36. 35. Output should display Department_Code. 33. Sudent_Name. Pay date is the last Friday of the month. and Number of People. Write a query to display number of people in each Department. Total and Average respectively. Display Manager_Code. Label the column as ‘Total Number of Managers’. Create a query which will give the following output ignore the lines. Write a query to find the pay date for the month. Display the date in the format “Twenty Eighth of January. 42. Department_Code. and Subject3 for all students who are getting more than 60 in each subject from department 10 and 20. Label the columns Maximum. Manager Hiredate of all staff hired before their manager. Staff_Name. Total & Average salary of all staff. and Department_Name for all staff who do not works in Department code 10 and have ‘A’ in their name. Display the Manager_Name and the total strength of his/her team. and his manager’s number and name. Display Staff_Code. Staff Hiredate. Dept_Code 10 20 30 1980 1 1981 2 2 6 1982 1 1 1983 1 Total 3 5 6 Part II 40. Subject2. Exclude any group where minimum salary is less than 10000. Determine the number of managers without listing them. Create a query that will display Student_Code. Staff_Name Department_Name. Lowest. Label the columns Staff#. Label the heading as PAY DATE. Save the query as E2Q20. 34. Write a query to display Staff_Name. . Department_Name. 39. Mgr#. Manager_Name and salary of lowest paid staff in that manager’s team. Edit the above query and display the same for each Department Name. Staff_Name. 37. Create a query which will display Manager_Name. Department_Name and Department_Code Salary for all staff who earns more than 20000. Subjec1. Salary. Department_Name. Minimum. Round the result to nearest whole number.

51. 5 per day. Book_Code. List the Student_Code. Give the column as appropriate label. Staff Code. and Salary for those staff who are getting less then average salary in their own department 56. Student_Name for that student who got highest marks in all three subjects in Computer Science department for current year. Staff Code Staff Name Designation Department Name Department Head For all staff excluding HOD (List should not contain the details of Department head). List Staff_Code. Department_Name. Staff_Name. Book_Name. Fine For the staff who have not return the book. Department. 52. Total. Department_Name. 50. Staff_Name who are not Manager. List the Staff_Code. Sudent_Name. Subject1. Staff_Name. Department_Name. Subject3. 57. Subject2. Student_Name. Book Code. Staff Name. Generate a report which contains the following information Student Code Student Name Department Name Total Marks HOD Name Sort the output on Department Name and Total Marks. and Designation for those who have joined most recently. of days = Current Date – Expected return date). 53. and all the staff that work in the same department as a given staff. Display the Student_Code. Display Author_Name. Generate a report which contains the following information. 48. Book Name. 58. Create a query that will display Staff_Code. Display top ten students for a specified department. Department Name for those who have taken more than one book. Designation. 60. and Salary for those who are getting less than the average salary of organization. 47. Display Staff_Code. List the total staff and the number of staff hired in each Department Department No No. Book_Name for all students whose expected book return date is today. Department_Name. 54. Author. Display the Staff_Name. Department_Name. Book_Name for those authors who wrote more than one book. Staff_Name. and Department_Name for that department in which there are maximum number of student are studying. Display Staff_Code. Issue_Date. Create a query that will display Student_Code. Designation. Student_Name. Create a query that will display the Staff_Name. of Staff 10 20 30 Total 30 40 25 95 . Fine = 5 * (No.45. For only those staff who have taken any book in last 30 days. 49. Staff_Name. Department_Name. 59. Details are: Student_Code. Book_Code. Fine will be calculated as Rs. Generate a report which contains the following information. 55. 46.

63. Accept the student code and display only faculty details of that department. List the details of the book which has not been borrowed so far. 67. Total No: of students yet to return the book 70. before expected date and after expected date. List the department Name which has borrowed maximum number of time (Any book). Output should be in following format.61. . Output should be in following format. Designation of all staff. For current year in which month maximum numbers of books are borrowed by which department? 69. List the student detail. Generate the report that displays details for all books. Write a query which will display Staff_Name. Display”NO STAFF” where there is no staff in the department. Staff_Name. List the books that are returned on expected date. 5 per day. . and Department_Name. Faculty Code Faculty Name Name Designation Department 66. Display the Manager_Name. Calculate the fine for books returned after due date as Rs. Accept a specific book code from user and find the details of the students/staff who have borrowed that book and has not returned the same. Also display the department name where there is no staff. who has borrowed maximum number of books. Salary (The highest and the lowest paid staff in his team). Manager Name Staff_Name Allen Allen Ravi Raj Ajay Amit Raju Arvind 30000 Salary 10000 20000 15000 62. The following details should be displayed Student/Staff Code Return Date Student/Staff Name Issue Date Expected 65. 72.List the faculties of the department in which the student obtaining the maximum total marks for current year 68.Use Department Master & Designation Master. Display Details for only (HOD/Professor/Reader/Lecturer). 71. Send a report to every department in the following format: Dept Name. Book Code 100001 100002 100001 Total Book Name Author Status Java Complete Reference Schield Expected date C++ Complete Reference Schield Before date Oracle Complete Reference Scott After date Fine 0 0 15 15 64.

Generate a report which contains the following information. Staff Name Designation Department . Book CodeBook Name Staff Code Name Number of Times Issued For current year only.Book CodeBook Name Author Number of Times Issues 73.

OTHER OBJECTS Q1. designation. Q2. Q10. What happened? Create a view called SALARY_VU based on the Staff_Name. Q8. Department_Name. Q5. Create a view FINANCE with data from the Staff_Master which gives their total salary and average salary. Q9. Q12. Insert the values. Create a view consisting of names. Create a table Dept_Master with the following columns DeptNo – Primary Key DeptName -. Q4. Select view name and text from USER_VIEWS. HireDate –Default should be current date Q9. Label the view column Staff_Code. Label the columns staff. Designation_Master & Dept_Master to make it possible to see where some one works. Q13. Q2. Q6. Add a new staff with Staff_Code: 8888. Q3. Change the Miller’s department from 10 to 20. Staff_Name and Dept_Code. Do not allow a staff to be reassigned to another department through this view. Department. . Delete all staff from department 20. Q7.It should not be null Q6. Q14. Create a view name DEPT20 that contains the staff code. staff name and department number for all staff in department 20. Q4. Salary – Should be always >7000 Q8. Dept_Code: 20. Display the structure of the DEPT20 view. Create a table Staff_Master_Dup which contains the following columns: Staff_Code -. Sal: 25000. Dept_Code – Should refer to the DEPT_Code in Dept_Master Q10. Q5. Create a table called TEST with one column as Primary key. Salary and salary grade for all staff. Give all the staff in department 30 a salary hike of 10%. Q11. Hiredate: 08-APR1985. Salary and Grade respectively. code.DML & DDL Statements Q1. Display the contents of the STAFF_VU.Primary key should generate numbers automatically Staff_Name – Should not be null Designation –Should always be one of them HOD / Reader/ Professor/ Lecturer. Q3. Name: HARRIS. Assign SMITH to department 30. From the above view list the average annual salary for all the people in department 10 who makes less than 5000. salaries and departments of all staff in department 10. Display the structure of the view Staff_VU. Q7. Confirm the same from data dictionary that the index is created. Create a view Staff_VU from Staff_Master. Create an index on salary column of Staff_Master table. Mgr_Code: 7566.

Special Allowance will be decided based on the service in the company.Write a sql script block to increase the salary by 30 % or 5000 whichever minimum for a given Department_Code. Display the error message if the wrong department code has entered. [Formula: PI * Radius**2]. Function. Q5. Percent >= 80 then grade= A Percent >= 70 and < 80 then grade= B Percent >= 60 and < 70 then grade= C Else D Q1. DA = 15% Salary. Create an index on salary of Staff_Master table. Write a procedure to find the manager of a staff. (Note: The Department_Code will be accepted from user. Dept_Code and Manager Name. Display the error message if wrong department code has entered. Screen should display the following data – Staff_Code. Function should take Staff_Code and return the cost to company. TA= 8% of Salary. Confirm that an index is created implicitly. Q17. Write a procedure that accept staff code and update staff name to Upper case. < 1 Year Nil >=1 Year< 2 Year 10% of Salary . Q3. Create an index on Department_Code and Designation_Code of Staff_Master Q18. Write a sql script that generated the following report for a given Department code Subject1 Subject2 Subject3 Total Percentage Student_Code Sudent_Name Grade Note: Display suitable error massage if wrong department code has entered and if there is no student in the given department. Q16. If the staff name is null raise a user defined exception. Bonus is twice of salary. The function should accept a date and return age in years. Q2. Procedures . For Grade: Student should pass in each subject individually (pass marks 60).Q15. HRA= 20% of Salary.) Q3. Drop the table TEST and check that the corresponding index is also dropped. Write a function to compute the following. triggers Q1. Q2. Write a function to compute age. Q4. table. Handle exception if Staff_Code is not present or if it returns for more than one staff information.Write a function to compute area of circle.Write a sql script to calculate bonus of staff for a given Staff_Code.Write a sql script to retrieve all staff under specific department number and display the result. Staff_Name. Q4.

Write a procedure that displays the following information of all staff Staff_Name Department Name Designation Salary Note: . Date of Joining. Q7. Display the details of the students/staff that have borrowed that book and has not returned the same. Procedure: Capture the value returned by the above function to calculate the additional allowance for the staff based on the experience. Issue Date 11-Jan-07 15-Jan-07 18-Jan-07 (Stu/Staff) 1001 10011 1005 Code (Stu/Staff) Allan Ravi Arvind Name HOD Student Book Code Book Name Designation 10001 C++ 10005 Java 10009 Oracle Lecturer Q12. Q10.Write the following Function: This function will return years of experience for a staff. Generate a report Using which displays the following information. Department Name: Computer Science Book Code Book Name Issue Date Student_Code Student Name 10001 C++ 11-Jan-07 10012 Raju 10005 Java 15-Jan-07 10011 Ravi . This function will take the hiredate of the staff as an input parameter. Write a procedure that accept Staff_Code and update the salary and store the old salary details in Staff_Master_Back (Staff_Master_Back has the same structure without any constraint) table. Total Marks HOD Q11. Display an error message Staff_Master table is empty of if there is no matching record.Status will be (Greater. Generate a report which displays the following information. The output will be rounded to the nearest year (1. Generate a report which displays the following information. Student Code Student Name Department Name Name For only top three students from each department and for current year. Exp < 2 then no Update Exp > 2 and < 5 then 20% of salary Exp > 5 then 25% of salary Q8. Lesser or Equal) respective to average salary of their own department.5 year will be considered as 2 year). and Experience in years and additional allowance in Staff_Allowance table. Create a procedure that accepts the book code as parameter from the user. Additional Allowance = Year of experience x 3000 Calculate the additional allowance and store Staff_Code.>=2 Year< 4 Year >4 Year 20% of Salary 30% of Salary Status Q6.4 year will be considered as 1 year and 1. The following details should be displayed Student/Staff Code Ret_Date Student/Staff Name Issue Date Designation Expected Q9.

Department Name: Robotics Book Code Book Name Issue Date 10009 Oracle 18-Jan-07 Student_Code 10015 Student Name Arvind .