ORACLE PROGRAMMING 11G PL/SQL (X52.9358.001.SU10) > COURSE DOCUMENTS > REVIEW ASSESSMENT: PL/SQL MIDTERM Review Assessment: PL/SQL MIDTERM User Mustapha Bermak Submitted 8/5/10 10:08 PM Name PL/SQL MIDTERM Status Completed Score 96 out of 100 points Time Elapsed 0 hours, 45 minutes, and 6 seconds out of 1 hours and 15 minutes allowed. Instructions This test will consist of 25 questions worth 4 points each. Once you start the test you will be timed and you will have 1 1/2 hours to complete it. After the test has been submitted you will not be able to get it back to make changes so please go over your answers before you submit. GOOD LUCK! Question 1 4 out of 4 points Subprograms called "procedures" MUST return a value. Selected Answer: False Correct Answer: False Feedback: Correct! Question 2 4 out of 4 points I have started to create a function. What I have written so far is totally correct. CREATE FUNCTION give_raise IS deptno number(4); empno number(4); sal number(9,2); BEGIN ... Selected Answer: False Correct Answer: False Feedback: Correct! I left out the RETURN datatype. Question 3 4 out of 4 points The check_sal function is invoked correctly below: IF check_sal(v_avgsal) IS NULL THEN DBMS_OUTPUT.PUT_LINE('The function returned NULL due to exception'); ELSIF check_sal(v_avgsal) THEN ... END IF; Selected Answer: True Correct Answer: True Feedback: Correct! Question 4 0 out of 4 points Which of the following is not true of a host variable: Selected Answer: It is declared and exists externally to the PL/SQL subprogram. Correct Answer: Can be referenced in a stored subprogram. Feedback: Incorrect. You cannot reference a host variable from a stored procedure because you don't know which environment will call this procedure. Question 5 4 out of 4 points You are creating a procedure that will be getting data from the EMPLOYEES table (with columns called last_name and salary) and bringing it into variables in your procedure to examine. You want your variables to look like the columns in the EMPLOYEES table. The declaration section of this procedure is written correctly. CREATE OR REPLACE PROCEDURE examine_emps (empno IN NUMBER) IS v_last_name employees%TYPE; v_salary employees%TYPE; BEGIN ... END examine_emps; Selected Answer: False Correct Answer: False Feedback: Correct. When using %TYPE here you need to list table.column%TYPE; v_last_name employees.last_name%TYPE; v_salary employees.salary%TYPE; Question 6 4 out of 4 points You can give a default value for a parameter as in the example below: CREATE OR REPLACE PROCEDURE check_order (order_clerk NUMBER DEFAULT 7789) IS ... END check_order; Selected Answer: True Correct Answer: True Feedback: Yes, you can give a default value to a parameter. Question 7 4 out of 4 points Below there are two procedures, add_regions(which inserts new regions into the regions table) and create_regions (which calls the add_regions procedure). The Northeast region with a manager_id of 7899 is not inserted because of an integrity constraint violation on the manager_id. When the procedure create_regions is finished executing you can query the regions table and see that the Northeast region was not inserted, however the Southeast and Northwest regions were inserted into the regions table. ____________________________________________________________ CREATE PROCEDURE add_regions( name VARCHAR2, mgr NUMBER, loc NUMBER) IS BEGIN INSERT INTO REGIONS (region_id, region_name, manager_id, location_id) VALUES (REGIONS_SEQ.NEXTVAL, name, mgr, loc); DBMS_OUTPUT.PUT_LINE('Added Region: '||name); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Err: adding region: '||name); END; ____________________________________________________________ CREATE PROCEDURE create_regions IS BEGIN add_regions('Southeast', 7782, 1800); add_regions('Northeast', 7899, 1900); add_regions('Northwest', 7767, 1700); END; ____________________________________________________________ Selected Answer: True Correct Answer: True Feedback: Correct. The create_regions procedure calls the add_regions procedure. When the row for the Northeast region fails, the add_regions procedure's EXCEPTION section handles it using the WHEN OTHERS exception handler, and then returns to the caller, which is create_regions. The create_regions procedure then continues processing. It's next step is to call the add_regions procedure again passing it the information for the Northwest region. Question 8 4 out of 4 points A developer can see the source code for PL/SQL subprograms he/she has created by querying the data dictionary view USER_OBJECTS. Selected Answer: False Correct Answer: False Feedback: Correct! The source code is not in USER_OBJECTS, it is in USER_SOURCE. Question 9 4 out of 4 points Which of the methods below is not a method for passing parameters to a procedure. Selected Answer: Directional Correct Answer: Directional Feedback: Question 10 Correct! Directional is not one of the methods for passing parameters. 4 out of 4 points A stored function called from a SELECT statement cannot contain DML statements. Selected Answer: True Correct Answer: True Feedback: Correct! Question 11 4 out of 4 points Which parameter mode(s) below would you not use in an Oracle stored function? Selected Answers: IN OUT OUT Correct Answers: IN OUT OUT Feedback: Correct. You would only use IN for an Oracle stored function. Question 12 4 out of 4 points You have a stored function called tax. You want to call this function from within your tax_employee procedure. You create the code for the procedure and function as listed below and it will run successfully. CREATE OR REPLACE PROCEDURE tax_employee (v_empno IN NUMBER) IS v_taxed_sal emp.sal%TYPE; v_old_sal emp.sal%TYPE; BEGIN SELECT sal INTO v_old_sal FROM emp WHERE empno = v_empno; Tax(v_old_sal); v_taxed_sal := v_old_sal; UPDATE emp SET sal = v_taxed_sal WHERE empno = v_empno; END tax_employee; / Selected Answer: False Correct Answer: False Feedback: Correct! You must call a stored function from an expression. You cannot just call it as you would a procedure. Question 13 4 out of 4 points A package body can exist without a package specification. Selected Answer: False Correct Answer: False Feedback: Correct! A package body must have a package specification. Question 14 4 out of 4 points In the following code, g_comm is a private variable: CREATE OR REPLACE PACKAGE comm_package IS g_comm NUMBER := 10; Selected Answer: False Correct Answer: False Feedback: Correct! Here it is written in the package specification therefore it is a public variable. Question 15 4 out of 4 points You have a package named global_vars which contains a procedure named meter_2_yard. You want to call this procedure from within the following stand-alone procedure. This will run successfully as written. CREATE PROCEDURE meter_to_yard (v_meter IN NUMBER, v_yard OUT NUMBER) IS BEGIN v_yard := v_meter * meter_2_yard; END; / Selected Answer: False Correct Answer: False Feedback: Correct! You must call the procedure using the package name, i.e., global_vars.meter-2_yard. Question 16 4 out of 4 points A user logs in, uses a public (global) variable (puts a value in it) in a package, logs off but logs back in right away. The value that user put in that global variable still available the second time the user logs in. Selected Answer: False Correct Answer: False Feedback: Correct! Once the use logs out all of his global variables are gone! Question 17 4 out of 4 points Which of the following statements is not true of overloading: 1. Allows you to use the same name for different subprograms inside a package. 2. Requires the formal parameters of the subprograms to differ in number, order, or datatype family. 3. Requires the formal parameters of the subprograms to differ in name. Selected Answer: Requires the formal parameters of the subprograms to differ in name. Correct Answer: Requires the formal parameters of the subprograms to differ in name. Answer Feedback: Correct! Feedback: Correct! Overloading requires the formal parameters of the subprograms to differ in name. Question 18 4 out of 4 points The following package contains an overloaded procedure named add_dept. CREATE OR REPLACE PACKAGE over_pack IS PROCEDURE add_dept (v_deptno IN v_name IN v_loc IN END over_pack; / dept.deptno%TYPE, dept.dname%TYPE, dept.loc%TYPE); Selected Answer: False Correct Answer: False Feedback: Correct! There is only one procedure here so it is not written as overloaded. Question 19 4 out of 4 points In the package below, the value in rate_value will be placed into the tax vairable: CREATE OR REPLACE PACKAGE BODY taxes IS -- declare all variables and procedures/functions -- define all procedures and functions BEGIN SELECT rate_value INTO tax FROM tax_rates WHERE rate_name = TAX ; END taxes; / Selected Answer: The first time anything is called that is inside the taxes package. Correct Answer: The first time anything is called that is inside the taxes package. Answer Feedback: Correct! The first time anything is called that is inside the taxes package, this one-time-only block of code at the end of the package body will be executed. Feedback: Correct! The first time anything is called that is inside the taxes package, this one-time-only block of code at the end of the package body will be executed. Question 20 4 out of 4 points All of the following statements have been added or extended in PL/SQL to support Native Dynamic SQL except: Selected Answer: WRITE Correct Answer: WRITE Feedback: Correct! Question 21 4 out of 4 points The Oracle supplied package you would use to generate a simple web page is: Selected Answer: HTP Correct Answer: HTP Feedback: Correct. You would use the HTP package. Question 22 4 out of 4 points All SQL statements go through some or all of the following stages except: Selected Answer: Set Correct Answer: Set Feedback: Correct! Question 23 4 out of 4 points The Oracle supplied packaged procedure that allows you to put text to the output line of the buffer is: Selected Answer: DBMS_OUTPUT.PUT_LINE Correct Answer: DBMS_OUTPUT.PUT_LINE Feedback: Correct! I knew you would get this one!!! Question 24 4 out of 4 points CREATE PROCEDURE create_table( table_name VARCHAR2, col_specs VARCHAR2) IS BEGIN /* WHICH EXECUTE COMMAND WOULD YOU PUT HERE??? */ END; / Selected Answer: EXECUTE IMMEDIATE 'CREATE TABLE '||table_name|| ' (' || col_specs || ')'; Correct Answer: EXECUTE IMMEDIATE 'CREATE TABLE '||table_name|| ' (' || col_specs || ')'; Feedback: EXECUTE IMMEDIATE 'CREATE TABLE '||table_name|| ' (' || col_specs || ')'; is correct! Question 25 4 out of 4 points CREATE OR REPLACE PACKAGE BODY taxes_pak IS v_tax NUMBER := .08; BEGIN INSERT INTO emp VALUES (... -- your executable statements here BEGIN SELECT rate_value INTO v_tax FROM tax_rates WHERE rate_name = 'TAX'; -- rate_value in the tax_rate table for TAX is .10 END taxes_pak; / Given the above, the value in v_tax, when anything in this block is called (which will bring this block into memory), will be: Selected Answer: .10 Correct Answer: .10 Feedback: Correct!