Examine the following package specification.
SQL>CREATE OR REPLACE PACKAGE emp_pkf IS
PROCEDURE search_emp (empdet NUMBER);
PROCEDURE search_emp (empdet DATE);
PROCEDURE search_emp (empdet NUMBER); RETURN VERCHAR2
PROCEDURE search_emp (empdet NUMBER); RETURN DATE
END emp_pkg
The package is compiled successfully
Why mould it generate an error at run tune?
A.
Because function can not be overload
B.
Because function can not differ only in runtime
C.
because all the functions and procedures In the package cannot have the same number of parameters with the same parameter name
D.
Because the search EMP (EMPDET NUMBER) procedure and the SEARCH_DEPT (EMPDET NUMBER) can not have identical parameter names and data types
badly written question! I assume
PROCEDURE search_emp (empdet NUMBER); RETURN VERCHAR2
PROCEDURE search_emp (empdet NUMBER); RETURN DATE
is supposed to be function declarations???
as in
FUNCTION search_emp (empdet NUMBER) RETURN VARCHAR2;
FUNCTION search_emp (empdet NUMBER) RETURN DATE;
If so you it will compile fine but you will get PLS-00307 at runtime – too many declarations of SEARCH_EMP match this call. The reason is functions can not differ only in return type which is what answer B should say I guess.
yes! p.e. vErchar2 !
B. Because two functions which differ only in return type can not be over loaded, even if the return types are in different families.
I think the last 2 subprograms should be written as
FUNCTION search_emp (empdet NUMBER); RETURN VERCHAR2
FUNCTION search_emp (empdet NUMBER); RETURN DATE
B
I don’t think oracle can compile “PROCEDURE search_emp (empdet NUMBER); RETURN VERCHAR2” successfully.
It is supposed to be “PROCEDURE search_emp (empdet NUMBER) RETURN VERCHAR2”.
Answer is D)
A: is wrong
B: is wrong ..function can differ only in return type
create or replace package emp_pkf is
function search_emp(empdet number) return varchar2;
function search_emp(empdet number) return date;
end;
it creates successfully.
C: is wrong.. all functions and procedures can have the same name and the same number of parameter.. but if they differ in data type or return type.
D: is right.. you can’t create two procedure with the same name and the same number of parameter with the same type.. like line 2&4
B: The functions cannot differ only in return type but also in the differ datatype (the name variable can be the same). Inoltre the phrase is not correct: Because function cannot differ only runtime (correct: Because function cannot differ only in return type)