Test: Semester 1 Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
1337415626886 0 Y Y 1055564065

1. You can use %ROWTYPE with tables and views. True (*) False Correct 2. An INDEX BY TABLE type can only have one data field. True (*) False Incorrect. Refer to Section 6 Lesson 2. 3. Department-id 99 does not exist. What will be displayed when the following code is executed? DECLARE v_deptname departments.department_name%TYPE; BEGIN SELECT department_name INTO v_deptname FROM departments WHERE department_id = 99; EXCEPTION WHEN NO_DATA_FOUND THEN RAISE_APPLICATION_ERROR(-20201,'Department does not exist'); END;

RAISE e_my_excep.PUT_LINE('Message 3'). Correct 6. There are no employees in department 99. RAISE exception-name. A user-defined exception is raised by using: FLAG exception_name. Message 1 Message 3 Message 1 Message 2 Message 1 Message 3 Message 4 Message 1 Message 4 (*) Correct 5. (*) PRAGMA EXCEPTION_INIT RAISE(error_number. True or False? True (*) .PUT_LINE('Message 4'). What message or messages will be displayed when the following code is executed? DECLARE e_my_excep EXCEPTION.PUT_LINE('Message 2'). DBMS_OUTPUT. EXCEPTION WHEN e_my_excep THEN DBMS_OUTPUT. EXCEPTION WHEN e_my_excep THEN DBMS_OUTPUT.ORA-01403: No Data Found ORA-20201: Department does not exist ORA-01403: No Data Found ORA-20201: Department does not exist (*) None of the above Correct 4. exception_name). BEGIN BEGIN UPDATE employees SET salary = 10000 WHERE department_id = 99.PUT_LINE('Message 1'). A user-defined exception must be declared as a variable of data type EXCEPTION. IF SQL%ROWCOUNT = 0 THEN RAISE e_my_excep. END. END. END IF. DBMS_OUTPUT.

Examine the following code. more than one exception can occur at the same time. Why does the exception handler not follow good practice guidelines? DECLARE v_salary employees. Correct 9.Which of these exceptions can be handled by an EXCEPTION section in a PL/SQL block? A SELECT statement returns no rows A SELECT statement returns more than one row Any other kind of exception that can occur within the block All of the above (*) None of the above Correct Section 7 . (*) The exception handler should COMMIT the transaction. The exception handler should test for the named exception NO_DATA_FOUND. While a PL/SQL block is executing.PUT_LINE('An error occurred'). You should not use DBMS_OUTPUT. The programmer makes a spelling mistake while writiing the PL/SQL code.False Correct 7. employee_id 999 does not exist in the employees table. Correct 10. END.PUT_LINE in an exception handler. An error occurs during execution which disrupts the normal operation of the program.salary%TYPE. True or False? True False (*) Correct 8. EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT. Which of the following best describes a PL/SQL exception? A user enters an invalid password while trying to log on to the database. (*) A DML statement does not modify any rows. BEGIN SELECT salary INTO v_salary FROM employees WHERE employee_id = 999.

Line A END IF. How can you do this? DECLARE v_salary employees. At Line A.11. SQLERRM). (*) Test for WHEN OTHERS in the exception section.) True False (*) Correct 13. char_col) VALUES (SQLCODE.salary%TYPE. True or False? EXCEPTION WHEN OTHERS THEN INSERT INTO err_log_table (num_col.. IF v_salary > 30000 THEN -. The following exception handler will successfully insert the Oracle error number and error message into a log table whenever an Oracle Server error occurs. Correct 12. Examine the following code fragment. because WHEN OTHERS traps all exceptions. you want to raise an exception if the fetched salary value is greater than 30000..) . END. . BEGIN SELECT salary INTO v_salary FROM employees WHERE employee_id = 100. (Assume that err_log_table has been created with suitable columns and datatypes. Which of the following are examples of predefined Oracle Server errors? (Choose three. Use RAISE_APPLICATION_ERROR to raise an exception explicitly. Define an EXCEPTION variable and associate it with an Oracle Server error number using PRAGMA EXCEPTION_INIT. Test for WHEN VALUE_TOO_HIGH in the exception section.

Which of the following best describes a user-defined exception? A predefined Oracle Server error such as NO_DATA_FOUND A non-predefined Oracle Server error such as ORA-01400 An error which is not automatically raised by the Oracle server (*) Any error which has an Oracle error number of the form ORA-nnnnn Correct .(Choose all correct answers) TOO_MANY_ROWS (*) NO_DATA_FOUND (*) OTHERS ZERO_DIVIDE (*) E_INSERT_EXCEP Correct 14. Which of the following best describes a predefined Oracle Server error? Has a standard Oracle error number but must be named by the PL/SQL programmer Is not raised automatically but must be declared and raised explicitly by the PL/SQL programmer Has a standard Oracle error number and a standard name which can be referenced in the EXCEPTION section (*) Is associated with an Oracle error number using PRAGMA EXCEPTION_INIT Correct 15.

END. BEGIN RAISE e_excep1. It will fail to compile because e_excep1 is out of scope in the subblock. END. and test for WHEN e_null_excep in the exception section. It will compile successfully and return an unhandled e_excep2 to the calling environment. Exceptions declared in a block are considered local to that block. Then test for WHEN e_null_excep in the exception section. associate it with ORA01400 using a PRAGMA directive. It will fail to compile because you cannot have a subblock inside an exception section. What will happen when the following code is executed? DECLARE e_excep1 EXCEPTION. How can you code an exception handler to trap this exception? Test for WHEN ORA-1400 in the exception section. Declare a variable as follows: e_null_excep EXCEPTION := -01400. Correct 17. e_excep2 EXCEPTION. and test for WHEN e_null_excep in the exception section. An attempt to insert a null value into a NOT NULL table column raises an ORA-01400 exception. True or False? True (*) . Declare a variable e_null_excep of type EXCEPTION. EXCEPTION WHEN e_excep1 THEN BEGIN RAISE e_excep2. It will fail to compile because you cannot declare more than one exception in the same block. associate it with ORA01400 using a PRAGMA directive.16. (*) Correct 18. and global to all its sub-blocks. (*) Declare a variable e_null_excep of type VARCHAR2.

The code will execute successfully and 'Outer Raised' will be displayed. What will happen when the following code is executed? DECLARE e_outer_excep EXCEPTION. a TOO_MANY_ROWS exception is raised within the inner block.PUT_LINE('Outer raised').PUT_LINE('Inner raised').False Correct 19. Which of the following exception handlers will successfully handle the exception? WHEN TOO_MANY_ROWS in the inner block WHEN TOO_MANY_ROWS in either block WHEN OTHERS in either block WHEN OTHERS in the inner block All of the above (*) . END. (*) The code will propagate the e_outer_excep back to the calling environment. The code will fail to compile because e_inner_excep was declared but never RAISEd. END. EXCEPTION WHEN e_outer_excep THEN DBMS_OUTPUT. BEGIN RAISE e_outer_excep. Using two nested blocks. Correct 20. WHEN e_inner_excep THEN DBMS_OUTPUT. The code will fail to compile because e_inner_excep cannot be referenced in the outer block. BEGIN DECLARE e_inner_excep EXCEPTION.

True or Fals True . END. True or False? True (*) False Correct 25. The procedure will be created successfully. The statement will fail because the last line of code should be END emp_proc./SQL subprogram can be invoked from within many applications.Correct Section 8 21.A nested subprogram can only be invoked from the main subprogram. DBMS_OUTPUT. Correct 23. What will happen when the followin executed? CREATE OR REPLACE PROCEDURE emp_proc IS v_salary employees. (*) The statement will fail because the procedure does not have any parameters. They can have an exception section.) (Choose all correct answers) They are named PL/SQL blocks (*) They must return exactly one value to the calling environment.salary%TYPE. BEGIN SELECT salary INTO v_salary FROM employees WHERE employee_id = 999. They can accept parameters.Which of the following are characteristics of PL/SQL stored procedures? (Choose three.One PL. The statement will fail because you cannot declare variables such as v_salary inside a procedure.View and reload your code later by clicking on the History button in the SQL Commands window.A programmer wants to create a PL/SQL procedure named EMP_PROC. True or False? True (*) False Correct 24. (*) They can be invoked from inside a SQL statement. The statement will raise a NO_DATA_FOUND exception because employee_id 999 does not exist.PUT_LINE('The salary is: ' || v_salary). (*) Correct 22.

.. Refer to Section 8 Lesson 3. The procedure was called as SOMEPROC(10. Correct 29.A stored PL/SQL procedure can be invoked from which of the following? A. 28. 70). A PL/SQL anonymous block B. 60 => C).The following procedure has been created: CREATE OR REPLACE PROCEDURE defproc (A IN NUMBER := 50.. B.D=>50). C IN NUMBER DEFAULT 40) IS .Suppose you set up a parameter with an explicit IN mode. What is true about that parameter? . B and C (*) B and C Correct 27. 25 => C). D.False (*) Correct 26. defproc(30.. B IN NUMBER. Another PL/SQL procedure C. (*) defproc(10 => A. C. Which one of the following will invoke the procedure correctly? defproc(30 => A). defproc.Procedure SOMEPROC has five parameters named A. How was parameter B referenced? Positional (*) Named A combination of positionally and named A combination of named and defaulted Defaulted Incorrect. A calling application A only A and B A and C A. E in that order.20. defproc(40.

BEGIN smallproc(v_param).. It cannot have a DEFAULT value. Correct 30. It cannot have a DEFAULT value. It must be the same type as the matching IN parameter. END. (*) It must be the same type as the matching OUT parameter. (*) It acts like a constant (its value cannot be changed inside the subprogram).Suppose you set up a parameter with an explicit OUT mode. What is true about that parameter? It must have a DEFAULT value.. Examine the following procedure: CREATE OR REPLACE PROCEDURE smallproc (p_param IN NUMBER) IS BEGIN . Which of the following best describes how an IN parameter affects a procedure? It describes the order in which the procedure's statements should be executed.It must have a DEFAULT value. (*) It allows complex calculations to be executed inside the procedure. It inherits its type from the matching OUT parameter. It passes a value into the procedure when the procedure is invoked. Correct Section 8 31. Which of the following statements is true? p_param is a parameter and v_param is an argument p_param is a formal parameter and 20 is an actual parameter . The procedure is invoked by: DECLARE v_param NUMBER := 20.. It makes the procedure execute faster. Correct 32. It inherits its type from the matching IN parameter. It acts like a constant (its value cannot be changed inside the subprogram). It describes which parts of the procedure's code are optional or conditional.

You have created procedure MYPROC with a single parameter PARM1 NUMBER. Which of the following is NOT correct coding for a procedure parameter? (p_param IN VARCHAR2) (p_param VARCHAR2) (p_param VARCHAR2(50)) (*) (p_param employees. Which of the following statements about actual parameters is NOT true? An actual parameter is declared in the calling environment. Refer to Section 8 Lesson 2. Once a procedure has been created. CREATE OR REPLACE PROCEDURE someproc (parm1 NUMBER.p_param is a formal parameter and v_param is an actual parameter (*) p_param and v_param are both formal parameters. parm2 NUMBER) IS BEGIN . Which of the following will change the procedure successfully? ALTER PROCEDURE myproc ADD (parm2 NUMBER). not in the called procedure An actual parameter must be the name of a variable (*) An actual parameter can have a Boolean datatype The datatypes of an actual parameter and its formal parameter must be compatible An actual parameter can have a TIMESTAMP datatype Correct 34.last_name%TYPE) (p_param IN OUT VARCHAR2) Incorrect.. (*) Correct 36. Now you want to add a second parameter to the procedure. the number of parameters cannot be changed. parm2 NUMBER) IS BEGIN .. parm2 NUMBER).. CREATE OR REPLACE PROCEDURE someproc (parm1 NUMBER. while 20 is an actual parameter p_param is an actual parameter and v_param is a formal parameter Correct 33.. 35. How do you specify that you want a procedure MYPROCA to use Invoker's Rights? CREATE OR REPLACE PROCEDURE myproca . (You do not need to repeat the detailed code of the procedure. The procedure cannot be modified. only the header) REPLACE PROCEDURE someproc (parm1 NUMBER.

This function accepts one IN parameter of datatype VARCHAR2 and returns a NUMBER. GRANT INVOKER TO myprocA. Correct 37. User REYHAN creates the following procedure: CREATE PROCEDURE proc1 AUTHID CURRENT_USER IS v_count NUMBER.employees. Correct 39. BEGIN -. What privileges will BILL need? EXECUTE on REYHAN.PROC1 and SELECT on TOM. END. 38. You want to invoke the function within the following anonymous block: DECLARE v_var1 NUMBER(6.. therefore no extra code is needed.. A function named MYFUNC has been created. Refer to Section 9 Lesson 6.AUTHID CURRENT_USER IS.EMPLOYEES.. User BILL wants to execute this procedure.. ALTER PROCEDURE myproca TO INVOKER.PROC1 SELECT on TOM.EMPLOYEES BILL needs no privileges None of the above.Line A . CREATE OR REPLACE PROCEDURE myproca AUTHID OWNER IS. (*) Invoker's Rights are the default. When must AUTHID CURRENT_USER be included in an autonomous transaction subprogram? When declaring Definer's rights When declaring Invoker's rights (*) When using COMMIT or ROLLBACK When using GRANT on the subprogram Incorrect. BEGIN SELECT COUNT(*) INTO v_count FROM tom. The procedure will fail to compile because REYHAN does not have SELECT privilege on TOM.EMPLOYEES (*) EXECUTE on REYHAN.2).

v_var1). (*) myfunc('Crocodile'.END. Correct Section 9 41. A function cannot be used within a SQL statement. Correct 40. A subprogram which invokes another subprogram. Which Dictionary view can you query to see the errors? USER_SOURCE USER_ERRORS (*) USER_OBJECTS USER_DEPENDENCIES USER_COMPILES Correct 42. What could be coded at Lıine A? myfunc('Crocodile') := v_var1. and must return exactly one value. a procedure can be used within SQL. v_var1 := myfunc('Crocodile'). (*) A subprogram that must have at least one IN parameter. The function does not compile correctly because there are errors in your code. A subprogram that executes automatically when a DML statement is executed on a table. Which of the following best describes a stored function? A subprogram that must return exactly one value. True False (*) . An explicit cursor can be declared in a procedure. procedures can be nested to at least 8 levels.A function must have at least one IN parameter. but not in a function. A function must return a value. myfunc(v_var1) := 'Crocodile'. A procedure can have default values for parameters. a procedure may or may not. (*) Correct 43. myfunc(v_var1. A subprogram that has no OUT or IN OUT parameters.Which of the following is a difference between a procedure and a function? Functions cannot be nested. while a function cannot.You try to create a function named MYFUNC. 'Crocodile').

child2.You want to remove the procedure NO_NEED from your schema. while a procedure cannot. A function must have at least one IN parameter. CHILD2 is dropped successfully. but a function cannot.Which of the following is a difference between a procedure and a function? A procedure can include DML statements. PARENT is marked INVALID. while parameters are optional for a procedure. (*) . What happens? You cannot drop CHILD2 because PARENT is dependent on it. A procedure can return a BOOLEAN datatype. A function can be used inside a SQL statement. Which Data Dictionary views are updated automatically? USER_PROCEDURES USER_OBJECTS USER_SOURCE All of the above.The following code shows the dependencies between three procedures: CREATE PROCEDURE parent IS BEGIN child1. while a function cannot. CHILD1 is still valid.Correct 44. The database automatically drops PARENT as well. CHILD2 is dropped successfully. Correct 45. END parent. You now try to execute: DROP PROCEDURE child2. while a function cannot. Correct 46.Which Data Dictionary view can be used to display the detailed code of a procedure in your schema? USER_PROCEDURES USER_OBJECTS USER_SOURCE (*) USER_SUBPROGRAMS None of the above. (*) None of the above. You execute: DROP PROCEDURE no_need. (*) A procedure can include an EXCEPTION section. Correct 47. PARENT and CHILD1 are both marked INVALID.

A benefit of user-defined functions is that the function can accept any SQL or PL/SQL data type. 50. Refer to Section 9 Lesson 2. True or False? SELECT first_name. The example below is a valid use of of this function.The function avg_ann_sal returns the average annual salary for a particular department.The database automatically drops CHILD1 as well.Which of the following is a legal location for a function call in a SQL statement? (Choose 3) (Choose all correct answers) CREATE TABLE statement WHERE clause in a DELETE statement (*) The ORDER BY and GROUP BY clauses of a query (*) VALUES clause of an INSERT statement (*) Correct . True (*) False Incorrect. last_name FROM employees WHERE avg_ann_sal(20) > 15000. True or False? True False (*) Correct 49. Correct 48.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.