Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q 2 . ( 2 0 points ) . Refer to page 3 in note 6 b _ Records. Define a user - defined record

Q2.(20 points). Refer to page 3 in note6b_Records.
Define a user-defined record type called DEPT_INFO that has four fields as:
dept_id (correspondent to department_id in departments table), dept_name (department_name in departments table), Max_sal as number (8,2), the maximal salary in this department: function MAX (salary),
Average_sal as number (8,2), the average salary in this department: function AVG (salary).
After having defined this record type, your program will declare a variable of this type.
The program will retrieve the needed info for department_id 60, populate each field of this record type variable, and print out the result.
Hint, as we are going to re-use the codes again in question 3, better to define variable, such as dept_no number (4) :=60.
Note, sometimes, it is easier to use two simple SQL statements to get the data needed.
Q3.(20 points)
In question 2, we build a record type, and declare a variable of that type, it is good to store one record. In this question #3, we will create a collection using this record type as its elements, thus it can store a set of records.
Write a PL/SQL block, define a user-defined record type called Dept_Info as in question 2 that has four fields.
Define a nested table type named as Dept_Info_NT, that uses record type defined in Q2 Dept_Info as its element; then declare a nested table variable called LIST.
Retrieve the data from Departments and Employees table for all the departments that have a manager assigned for that department (departments.manager_id is not null). Populate this LIST with the retrieved data, print out the contents of the LIST.
Note, we use NT_variable_name (index) to reference the NT element; in this question, we need to use NT_variable_name (index).record_field to reference the element's field. Such as
LIST (i).dept_id for department_id column in the departments table.
In this question 3, it will be convenient to declare two separate cursors, one to retrieve the department id and department name, the second cursor to retrieve maximal and average salary from employees table via group by. In the executable section, you may run three loops, two for each cursor, and one for print out. If you have difficulties, please refer to the samples in the class notes.
Please try to solve both question 2 and 3.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

Cite ways to overcome fear of success.

Answered: 1 week ago