Вы находитесь на странице: 1из 14

Test: Quiz: Creating Functions Review your answers, feedback, and question scores below.

An asterisk (*) indicates a correct answer. Section 1 (Answer all questions in this section) 1. A PL/SQL function can have IN OUT parameters. True or False? Mark for Review (1) Points

True False (*) Correct 2. When using Invoker's rights, the invoker needs privileges on the database objects referenced within the subprogram, as well as GRANT privilege on the procedure. True or False? True False (*) Correct 3. You have created a function called GET_COUNTRY_NAME which accepts a country_id as an IN parameter and returns the name of the country. Which one of the following calls to the function will NOT work? 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 4. Based on the following function definition: Create function annual_comp (sal employees.salary%type, comm_pct In employees.commission%type) ... Which one of the following is an incorrect call for annual_comp? 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; (*) Incorrect. Refer to Section 9 Lesson 1. 5. A function may execute more than one RETURN statement found in the body of that function. True or False? True False (*) Correct Mark for Review (1) Points Mark for Review (1) Points Mark for Review (1) Points Mark for Review (1) Points

6. A stored function:

Mark for Review (1) Points

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 7. Procedure p1 has a single OUT parameter of type DATE. Function f1 returns a DATE. What is the difference between p1 and f1? 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 same datatype Incorrect. Refer to Section 9 Lesson 1. 8. To create a function successfully, the following steps should be performed: Mark for Review (1) Points Mark for Review (1) Points

A.
B. C. D. E. F. G.

Re-execute the code until it compiles correctly Write the code containing the CREATE or REPLACE FUNCTION followed by the function 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?

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. Function MYFUNC1 has been created, but has failed to compile because it contains syntax errors. We now try to create procedure MYPROC1 which invokes this function. Which of the following statements is true? 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 MYFUNC1 will be treated as a comment and ignored. Mark for Review (1) Points

Correct 10. Function GET_JOB accepts an employee id as input and returns that employee's job id. Which of the following calls to the function will NOT work? 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 11. Which of the following is found in a function and not a procedure? Mark for Review (1) Points Mark for Review (1) Points

An exception section. IN parameters. Local variables in the IS/AS section. Return statement in the header. (*) Correct 12. 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? find_sal(100,v_mynum); v_mynum := find_sal(100); (*) v_mydate := find_sal(100); find_sal(v_mynum,100); Correct 13. CREATE FUNCTION get_sal (p_id employees.employee_id%TYPE)) RETURN number IS v_sal employees.salary%TYPE := 0; BEGIN Mark for Review (1) Points Mark for Review (1) Points

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? 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 14. What will happen when the following subprogram is compiled? CREATE OR REPLACE FUNCTION get_job (p_job jobs.job_id%TYPE) RETURN jobs.job_title%TYPE IS; v_title jobs.job_title%TYPE; BEGIN SELECT job_title INTO v_title FROM jobs WHERE job_id = p_jobid; RETURN v_title; END get_job; The subprogram will work without errors. The subprogram will fail because of an error in the SELECT statement. (*) The subprogram will fail because the RETURN is declared with %TYPE. The program will compile successfully. Incorrect. Refer to Section 9 Lesson 1. 15. 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 BEGIN RETURN (sal*12) + NVL(comm_pct,0)*12*sal; END annual_comp; 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. Incorrect. Refer to Section 9 Lesson 1. Mark for Review (1) Points Mark for Review (1) Points

Test: Quiz: Using Functions in SQL Statements Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 1 (Answer all questions in this section) 1. User-defined functions can extend the power of SQL statements where Oracle does not provide ready-made functions such as UPPER and LOWER. True or False? True (*) False Correct 2. Which of the following is NOT a legal location for a function call in a SQL statement? Mark for Review (1) Points Mark for Review (1) Points

FROM clause of a SELECT statement (*) WHERE clause in a DELETE statement SET clause of an UPDATE statement VALUES clause of an INSERT statement Correct 3. You want to create a function which can be used in a SQL statement. Which one of the following can be coded within your function? RETURN BOOLEAN One or more IN parameters (*) An OUT parameter COMMIT; Correct 4. Function DOUBLE_SAL has been created as follows: CREATE OR REPLACE FUNCTION double_sal (p_salary IN employees.salary%TYPE) RETURN NUMBER IS BEGIN RETURN(p_salary * 2); END; Which of the following calls to DOUBLE_SAL will NOT work? SELECT * FROM employees WHERE double_sal(salary) > 20000; SELECT * FROM employees ORDER BY double_sal(salary) DESC; UPDATE employees SET salary = double_sal(salary); SELECT last_name, double_sal(salary) FROM employees; None of the above; they will all work (*) Mark for Review (1) Points Mark for Review (1) Points

Correct 5. The following function has been created: CREATE OR REPLACE FUNCTION upd_dept (p_dept_id IN departments.department_id%TYPE) RETURN NUMBER IS BEGIN UPDATE departments SET department_name = 'Accounting' WHERE department_id = p_dept_id; RETURN p_dept_id; END; Which of the following will execute successfully? DELETE FROM departments WHERE department_id = upd_dept(department_id); SELECT upd_dept(department_id) FROM employees; DELETE FROM employees WHERE department_id = upd_dept(80); (*) SELECT upd_dept(80) FROM dual; Correct 6. Which of the following is NOT a benefit of user-defined functions? Mark for Review (1) Points Mark for Review (1) Points

They can add business rules to the database and can be reused many times. They can be used in a WHERE clause to filter data. They can do the same job as built-in system functions such as UPPER and ROUND. (*) They can often be used inside SQL statements. Correct

Test: Quiz: Review of Data Dictionary Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 (Answer all questions in this section) 1. User BOB is not a database administrator. BOB wants to see the names of all the tables in his schema, as well as all the tables in other users' schemas which he has privileges to use. Which Data Dictionary view would BOB query to do this? USER_TABLES ALL_TABLES (*) DBA_TABLES USER_TAB_COLUMNS Mark for Review (1) Points

None of the above. Correct 2. Which of the following will display how many objects of each type are in a user's schema? SELECT COUNT(*) FROM user_objects; SELECT object_type, COUNT(*) FROM user_objects GROUP BY object_type; (*) SELECT object_type, COUNT(*) FROM all_objects GROUP BY object_type; DESCRIBE user_objects GROUP BY object_type; Correct 3. Which of the following is NOT a benefit of the Data Dictionary? Mark for Review (1) Points Mark for Review (1) Points

It allows us to remind ourselves of the names of our tables, in case we have fogotten them. It allows us to check which system privileges have been granted to us. It will speed up the execution of SELECT statements in which the WHERE clause column is not indexed. (*) It allows the PL/SQL compiler to check for object existence; for example, when creating a procedure which references a table, the PL/SQL compiler can check that the table exists. Correct 4. Which of the following statements about the "super-view" DICTIONARY is true? Mark for Review (1) Points

It lists all the dictionary views. It can be thought of as a "catalog of the master catalog". We can use it like a Web search engine to remind ourselves of the names of dictionary views. All of the above. (*) None of the above. Correct 5. A user executes the following statement: CREATE INDEX fn_index ON employees(first_name); What output will the following statement now display: SELECT index_name Mark for Review (1) Points

FROM user_indexes WHERE index_name LIKE 'fn%'; fn_index FN_INDEX fn_index FN_INDEX No output will be displayed (*) Correct 6. User MARY executes the SQL statement: SELECT COUNT(*) FROM USER_VIEWS; A value of 15 is returned. Which of the following statements is true? There are 15 views in Mary's schema. (*) Mary has created views on 15 of her tables. There are 15 views in the database. Other users have granted Mary SELECT privilege on 15 of their views. Correct 7. Which of the following best describes the Data Dictionary? Mark for Review (1) Points Mark for Review (1) Points

It is a set of tables which can be updated by any user who has the necessary privileges. It is an automatically managed master catalog of all the objects stored in the database. (*) It contains a backup copy of all the data in the database. It contains a list of all database tables which are not in any schema. Correct 8. You have forgotten the name of the Dictionary view USER_TABLES. Which of the following statements is the best and quickest way to remind yourself? SELECT * FROM dictionary WHERE table_name LIKE USER%; Read the online Oracle documentation at http://technet.oracle.com. SELECT * FROM dict WHERE table_name LIKE 'USER%TAB%'; (*) SELECT * FROM dictionary WHERE table_name = 'USER_TABLES'; Phone the database administrator. Correct Mark for Review (1) Points

Test: Quiz: Managing Procedures and Functions Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 (Answer all questions in this section) 1. Procedure ins_emp accepts an employee_id as an IN parameter and attempts to insert a row with that employee_id into the EMPLOYEES table. Ins_emp does not contain an exception section. A second procedure is created as follows: CREATE OR REPLACE PROCEDURE call_ins_emp IS BEGIN ins_emp(99); -- this employee does not exist ins_emp(100); -- this employee already exists ins_emp(999); -- this employee does not exist EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('An exception occurred'); END; When call_ins_emp is executed, which rows will be inserted into the EMPLOYEES table? 99 only (*) 99 and 999 All three rows will be inserted 999 only No rows will be inserted Correct 2. You need to remove procedure BADPROC from your schema. What is the correct syntax to do this? DELETE PROCEDURE badproc; DROP PROGRAM badproc; ALTER PROCEDURE badproc DISABLE; DROP PROCEDURE badproc; (*) Correct 3. The database administrator has granted the DROP ANY PROCEDURE privilege to user KIM. This allows Kim to remove other users' procedures and functions from the database. How would Kim now drop function GET_EMP, which is owned by user MEHMET? DROP FUNCTION get_emp FROM mehmet DROP FUNCTION mehmet.get_emp (*) DROP PROCEDURE mehmet.get_emp DROP PROGRAM mehmet.get_emp None of the above Mark for Review (1) Points Mark for Review (1) Points Mark for Review (1) Points

Correct 4. proc_a has been created as follows: CREATE OR REPLACE PROCEDURE proc_a IS v_last_name employees.last_name%TYPE; BEGIN SELECT last_name INTO v_last_name FROM employees WHERE employee_id = 999; /* This SELECT will raise an exception because employee_id 999 does not exist */ DBMS_OUTPUT.PUT_LINE('This SELECT failed'); END; proc_b is now created as follows: CREATE OR REPLACE PROCEDURE proc_b IS BEGIN proc_a; DBMS_OUTPUT.PUT_LINE('proc_a was invoked'); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('An exception occurred'); END; What will be displayed when proc_b is executed? An exception occurred (*) This SELECT failed proc_a was invoked An exception occurred This SELECT failed This SELECT failed proc_a was invoked Nothing will be displayed Correct 5. Which dictionary view will list all the PL/SQL subprograms in your schema? Mark for Review (1) Points Mark for Review (1) Points

user_source user_procedures user_objects (*) user_dependencies user_subprograms Correct 6. Which view would you query to see the detailed code of a procedure? Mark for Review (1) Points

user_source (*) user_procedures user_objects user_dependencies user_errors Correct

Test: Quiz: Review of Object Privileges Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 (Answer all questions in this section) 1. User FRED creates a procedure called DEL_DEPT using Definer's Rights, which deletes a row from Fred's DEPARTMENTS table. What privilege(s) will user BOB need to be able to execute Fred's procedure? EXECUTE on DEL_DEPT (*) EXECUTE on DEL_DEPT and DELETE on DEPARTMENTS EXECUTE on DEL_DEPT and DELETE on FRED.DEPARTMENTS DELETE on FRED.DEPARTMENTS Correct 2. User SVETLANA creates a view called EMP_VIEW that is based on a SELECT from her EMPLOYEES table. Svetlana now wants user PHIL to be able to query the view. What is the smallest set of object privileges that Svetlana must grant to Phil? SELECT on EMP_VIEW and SELECT on EMPLOYEES SELECT and EXECUTE on EMP_VIEW SELECT on EMP_VIEW (*) SELECT on EMP_VIEW and REFERENCES on EMPLOYEES Correct 3. User DIANE owns a DEPARTMENTS table. User JOEL needs to update the location_id column of Diane's table, but no other columns. Which SQL statement should Diane execute to allow this? GRANT UPDATE ON departments TO joel; GRANT UPDATE ON departments(location_id) TO joel; GRANT UPDATE ON departments.location_id TO joel; GRANT UPDATE(location_id) ON departments TO joel; (*) GRANT UPDATE ON location_id OF departments TO joel; Correct Mark for Review (1) Points Mark for Review (1) Points Mark for Review (1) Points

4. User TOM needs to grant both SELECT and INSERT privileges on both his EMPLOYEES and DEPARTMENTS tables to both DICK and HARRY. What is the smallest number of GRANT statements needed to do this? 1 2 (*) 3 4 8 Correct 5. USERB creates a function called SEL_PROC (using Definer's Rights) which includes the statement: SELECT ... FROM usera.employees ...; USERC needs to execute UserB's procedure. What privileges are needed for this to work correctly? (Choose two.) (Choose all correct answers) UserB needs SELECT on userA.employees (*) UserC needs SELECT on userA.employees UserC needs EXECUTE on userB.sel_proc (*) UserA needs EXECUTE on userB.sel_proc UserC needs EXECUTE on Userb Correct 6. User COLLEEN owns an EMPLOYEES table and wants to allow user AYSE to create indexes on the table. Which object privilege must Colleen grant to Ayse? SELECT on EMPLOYEES INDEX on EMPLOYEES (*) ALTER on EMPLOYEES CREATE on EMPLOYEES None of the above Correct

Mark for Review (1) Points

Mark for Review (1) Points

Mark for Review (1) Points

Test: Quiz: Using Invokers Rights and Autonomous Transactions Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 (Answer all questions in this section)

1. Procedure GET_EMPS includes a SELECT ... FROM EMPLOYEES. The procedure was created using Invoker's Rights. Which of the following statements are true? (Choose three.) (Choose all correct answers) The user who executes the procedure needs EXECUTE privilege on the procedure. (*) The creator of the procedure needs SELECT privilege on EMPLOYEES. (*) The user who executes the procedure does not need any privileges. The user who executes the procedure needs SELECT privilege on EMPLOYEES. (*) Correct 2. User SALLY's schema contains a NEWEMP table. Sally uses Invoker's rights to create procedure GET_NEWEMP which includes the line: SELECT ... FROM NEWEMP ... ; Sally also grants EXECUTE privilege on the procedure to CURLY, but no other privileges. What will happen when Curly executes the procedure? The procedure will execute successfully. The procedure will fail because Curly does not have SELECT privilege on NEWEMP. The procedure will fail because there is no NEWEMP table in Curly's schema. (*) The procedure will fail because Curly does not have the EXECUTE ANY PROCEDURE system privilege. Correct 3. 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; The subprogram will fail because it is missing AUTHID CURRENT_USER before IS. The autonomous transaction subprogram will fail because it must include COMMIT or ROLLBACK. (*) The compilation will fail because a semicolon after AUTONOMOUS_TRANSACTION is not needed. The program will compile successfully. Correct 4. Users SYS (the DBA), TOM, DICK and HARRY each have an EMPLOYEES table in their schemas. SYS creates a procedure DICK.SEL_EMP using Invoker's Rights which contains the following code: SELECT ... FROM EMPLOYEES ... ; HARRY now executes the procedure. Which employees table will be queried?

Mark for Review (1) Points

Mark for Review (1) Points

Mark for Review (1) Points

Mark for Review (1) Points

SYS.EMPLOYEES DICK.EMPLOYEES HARRY.EMPLOYEES (*) None of the above Correct 5. When using Invoker's rights, the invoker needs privileges on the database objects referenced within the subprogram, as well as GRANT privilege on the procedure. True or False? True False (*) Correct 6. Which of the following is the correct syntax to create a procedure using Invoker's Rights? CREATE PROCEDURE myproc IS AUTHID CURRENT_USER BEGIN ... CREATE PROCEDURE myproc AUTHID CURRENT_USER IS BEGIN ... (*) CREATE PROCEDURE AUTHID CURRENT_USER myproc IS BEGIN ... CREATE PROCEDURE myproc IS BEGIN AUTHID CURRENT_USER ... Correct 7. An autonomous transaction subprogram may be in a the same package as the calling subprogram or may be in a separate subprogram. True or False? True False (*) Correct Mark for Review (1) Points Mark for Review (1) Points Mark for Review (1) Points

Вам также может понравиться