View Exhibit1 and examine the structure of the EMP table.
View Exhibit2 and examine the PIVSQL block of code.
What is the outcome?
A.
It gives an error because the return type is not valid.
B.
It gives an error because the record type is not defined within the function
C.
It gives an error because the function call in DBMS_OUTPUT. PUT__LINEis not valid
D.
It executes successfully and displays the names and salaries of all employees who earn the
highest salary.
E.
It executes successfully but does not display the names and salaries of all employees who earn
the highest salary.
E!
http://docs.oracle.com/cd/A57673_01/DOC/server/doc/PLS23/ch4.htm
Function Results
When calling a function that returns a user-defined record, you use the following syntax to reference fields in the record:
function_name(parameters).field_name
edit: D
Correct answer is E
Because of RETURN inside if the loop,
also i checked myself:
declare
TYPE EmpRecTyp is Record
(
emp_name varchar2(30) ,
salary number(8, 2)
);
FUNCTION higest_salary return EmpRecTyp is
emp_info EmpRecTyp;
i number := 1;
Cursor cur_emp_cursor is
Select
first_name, salary
From
employees
Where
salary = (select max(salary) from employees);
begin
for emp_info in cur_emp_cursor
loop
dbms_output.put_line(i);
return emp_info; — leave function!!!!!
i:=i+1; — unreachible code
end loop;
end;
Begin
dbms_output.put_line(‘ emp: ‘ || higest_salary().emp_name );
end;
What is the correct answer d or e
E
Thanks, Vladimir. I also checked this code and it does not displays the names and salaries of all employees with the highest salary, it displays just first employee with the highest salary and then exits
e
(( there’s an absourd return not scalar type in the loop BUT
—- at the first return of the function for lop doesn’t continue becpuse functions terminates. (but with only one result)
may be this is the case of a pipelined function needed inquyred wity select table()
E
E
If there are more than one employee who earn highest salary, then it will not display all the employees. It will display only one employee.
Function can return only one parameter, and it will display only one employee who earn highest salary.
RECORD types can be in declare user-defined records
in the declare part of any block, subprogram, or package.
You can specify a RECORD type in the RETURN clause of a function spec.
That allows the function to return a user-defined record of the same type.
When calling a function that returns a user-defined record,
use the following syntax: function_name(parameter_list).field_name
A record can be initialized in its declaration.
You can use the %TYPE attribute to specify the datatype of a field.
You can add the NOT NULL constraint to any field declaration to prevent the assigning of nulls to that field. Fields declared as NOT NULL must be initialized. To reference individual fields in a record, you use dot notation. For example, to reference the dname field in the dept_rec record, you would use dept_rec.dname.
B
E
E
E