Question: Q 2 . ( 2 0 points ) . Refer to page 3 in note 6 b _ Records. Define a user - defined record
Q points Refer to page in notebRecords.
Define a userdefined record type called DEPTINFO that has four fields as:
deptid correspondent to departmentid in departments table deptname departmentname in departments table Maxsal as number the maximal salary in this department: function MAX salary
Averagesal as number 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 departmentid populate each field of this record type variable, and print out the result.
Hint, as we are going to reuse the codes again in question better to define variable, such as deptno number :
Note, sometimes, it is easier to use two simple SQL statements to get the data needed.
Q points
In question we build a record type, and declare a variable of that type, it is good to store one record. In this question # we will create a collection using this record type as its elements, thus it can store a set of records.
Write a PLSQL block, define a userdefined record type called DeptInfo as in question that has four fields.
Define a nested table type named as DeptInfoNT that uses record type defined in Q DeptInfo 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 departmentsmanagerid is not null Populate this LIST with the retrieved data, print out the contents of the LIST.
Note, we use NTvariablename index to reference the NT element; in this question, we need to use NTvariablename indexrecordfield to reference the element's field. Such as
LIST ideptid for departmentid column in the departments table.
In this question 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 and
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
