Anda di halaman 1dari 6

Test: Quiz: Creating Functions 1. Which of the following is found in a function and not a procedure?

Mark for Review (1) Points An exception section. IN parameters. Local variables in the IS/AS section. Return statement in the header. (*)

Correct 2. You have created a function called GET_COUNTRY_NAME which accepts a cou ntry_id as an IN parameter and returns the name of the country. Which one of the following calls to the function will NOT work? Mark for Review (1) Points v_name := get_country_name(100); DBMS_OUTPUT.PUT_LINE(get_country_name(100)); SELECT get_country_name(100) FROM dual; BEGIN get_country_name(100, v_name); END; (*)

Correct 3. Function MYFUNC1 has been created, but has failed to compile because it contains syntax errors. We now try to create procedure MYPROC1 which invokes th is function. Which of the following statements is true? Mark for Review (1) Points MYPROC1 will compile correctly, but will fail when it is executed. MYPROC1 will compile and execute succesfully. MYPROC1 will fail to compile because the function is invalid. (*) MYPROC1 will compile and execute successfully, except that the call to M YFUNC1 will be treated as a comment and ignored.

Correct 4. The following function has been created: CREATE OR REPLACE FUNCTION find_sal (p_emp_id IN employees.employee_id%TYPE) RETURN NUMBER IS ... We want to invoke this function from the following anonymous block: DECLARE v_mynum NUMBER(6,2); v_mydate DATE; BEGIN ... Line A END; Which of the following would you include at Line A? Mark for Review (1) Points find_sal(100,v_mynum); v_mynum := find_sal(100); (*) v_mydate := find_sal(100); find_sal(v_mynum,100);

Correct 5. Function GET_JOB accepts an employee id as input and returns that emplo yee's job id. Which of the following calls to the function will NOT work? Mark for Review (1) Points DBMS_OUTPUT.PUT_LINE(get_job(100)); IF get_job(100) = 'IT_PROG' THEN ... get_job(100,v_job_id); (*) v_job_id := get_job(100);

Correct

6. Procedure p1 has a single OUT parameter of type DATE. Function f1 retur ns a DATE. What is the difference between p1 and f1? Mark for Review (1) Points p1 can be invoked from an anonymous block but f1 cannot f1 can be used within a SQL statement but p1 cannot (*) p1 can have as many IN parameters as needed but f1 cannot have more than two IN parameters There is no difference because they both return a single value of the sa me datatype

Correct 7. Based on the following function definition: Create function annual_comp (sal employees.salary%type, comm_pct In employees.commission%type) ... Which on e of the following is an incorrect call for annual_comp? Mark for Review (1) Points Execute dbms_output.put_line(annual_comp (1000,.2)) Select employee_id, annual_comp(salary, commission_pct) from employees; Declare Ann_comp number (6,2); Begin ... Ann_comp := annual_comp(1000,.2 ); ... End; Select employee_id, annual_comp(salary) from employees; (*)

Correct 8. To create a function successfully, the following steps should be perform ed: Re-execute the code until it compiles correctly Write the code containing the CREATE or REPLACE+B20 FUNCTION followed by the fun ction code Test the function from a SQL statement or an anonymous block If the function fails to compile, correct the errors Load the code into Application Express Execute the code in Application Express What is the correct order to perform these steps? Mark for Review (1) Points B,E,F,D,A,C (*)

D,B,E,F,A,C B,C,E,F,D,A A,B,E,F,D,C

Correct 9. CREATE FUNCTION get_sal (p_id employees.employee_id%TYPE)) RETURN number IS v_sal employees.salary%TYPE := 0; BEGIN SELECT salary INTO v_sal FROM employees WHERE employee_id = p_id; RETURN v_sal; END get_sal; Which variable is passed to the function and which variable is returned from the function? Mark for Review (1) Points GET_SAL is passed and V_SAL is returned. SALARY is passed and P_ID is returned. EMPLOYEE_ID is passed and SALARY is returned. P_ID is passed and V_SAL is returned. (*)

Correct 10. What is wrong with the following code? CREATE FUNCTION annual_comp (sal employees.salary%TYPE, comm_pct IN employees.commission%TYPE) RETURN NUMBER(5,2 ) IS RETURN (sal*12) + NVL(comm_pct,0)*12*sal; END annual_comp; Mark for Review (1) Points The sal parameter should specify the IN keyword. The RETURN NUMBER has a scale and precision. (*) There should be parentheses (brackets) around NVL(comm_pct,0)*12*sal

The END; statement should not include the function name.

Correct 11. A PL/SQL function can have IN OUT parameters. True or False? Review (1) Points True False (*) Mark for

Correct 12. An autonomous transaction subprogram may be in the same package as the c alling subprogram or may be in a separate subprogram. True or False? Mark for Review (1) Points True False (*)

Incorrect. Refer to Section 9 Lesson 1. 13. When using Invoker's rights, the invoker needs privileges on the databas e objects referenced within the subprogram, as well as GRANT privilege on the pr ocedure. True or False? Mark for Review (1) Points True False (*)

Correct 14. A stored function: (1) Points Mark for Review

must have at least one IN parameter. cannot be called in a SQL statement.

must return one and only one value. (*) is called as a standalone executable statement.

Correct 15. What will happen when the following subprogram is compiled? PROCEDURE at_proc IS PRAGMA AUTONOMOUS_TRANSACTION; dept_id NUMBER := 90; BEGIN UPDATE INSERT END at_proc; Mark for Review (1) Points The subprogram will fail because it is missing AUTHID CURRENT_USER befor e IS. The autonomous transaction subprogram will fail because it must include COMMIT or ROLLBACK. (*) The compilation will fail because a semicolon after AUTONOMOUS_TRANSACTI ON is not needed. The program will compile successfully.

Incorrect. Refer to Section 9 Lesson 1.

Anda mungkin juga menyukai