Sie sind auf Seite 1von 46

Test: Semester 2 Mid Term Exam

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

Section 12 (Answer all questions in this section)

1. The following procedure compiles successfully. True or False? CREATE OR REPLACE PACKAGE emp_pkg IS TYPE t_emp IS TABLE OF employees%ROWTYPE INDEX BY BINARY_INTEGER; PROCEDURE emp_proc (p_small_arg IN NUMBER, p_big_arg NOCOPY OUT t_emp); ... END emp_pkg;

Mark for Review (1) Points

True

False (*)

Correct

2. What is wrong with this code example? CREATE OR REPLACE PROCEDURE insert_emps IS TYPE t_emp IS TABLE OF employees%ROWTYPE INDEX BY BINARY_INTEGER; v_emptab t_emp; BEGIN FORALL i IN v_emptab.FIRST..v_emptab.LAST INSERT INTO employees VALUES v_emptab(i); END LOOP; END insert_emps;

Mark for Review (1) Points

The phrase should be FOR ALL.

v_emptab is incorrectly typed.

FORALL does not require END LOOP. (*)

Nothing is wrong; it will compile successfully.

Correct

3. In the following example, where do you place the phrase BULK COLLECT? DECLARE TYPE NameList IS TABLE OF emp.ename%TYPE; names NameList; CURSOR c1 IS SELECT ename -- Position A FROM emp WHERE job = 'CLERK'; BEGIN OPEN c1; FETCH c1 -- Position B INTO -- Position C names; ... CLOSE c1; END;

Mark for Review

(1) Points

Position A

Position B (*)

Position C

Correct

4. What are benefits of using the NOCOPY hint? (Choose two) Mark for Review (1) Points

(Choose all correct answers)

Safer because it uses passing by value.

Efficient since it uses less memory. (*)

Uses a larger block of server memory for faster access.

Faster because a single copy of the data is used. (*)

Incorrect. Refer to Section 12 Lesson 2.

5. Name two reasons for using Dynamic SQL. Mark for Review (1) Points

(Choose all correct answers)

Avoid errrors at compile time of DML statements.

Create a SQL statement with varying column data, or different conditions. (*)

Enables data-definition statements to be written and executed from PL/SQL. (*)

Enables system control statements to be written and executed from PL/SQL.

Correct

6. A programmer wants to code a procedure which will create a table with a single column. The datatype of the column will be chosen by the user who invokes the procedure. The programmer writes the following code:

CREATE OR REPLACE PROCEDURE create_tab (p_col_datatype IN VARCHAR2) IS BEGIN CREATE TABLE newtab (only_col p_col_datatype); END;

Why will this procedure not compile successfully? Mark for Review (1) Points

Because you cannot create a table inside a procedure

Because the invoking user may not have CREATE TABLE privilege

Because when the procedure is compiled, Oracle cannot check if the parameter value passed into the procedure is a valid column datatype (*)

Because table NEWTAB may already exist

None of the above; the procedure will compile successfully

Correct

7. Examine the following procedure, which drops a table whose name is passed as an IN parameter: CREATE OR REPLACE PROCEDURE drop_tab (p_table_name IN VARCHAR2) IS v_sql_statement VARCHAR2(100); BEGIN ... END;

Which of the following will work correctly when coded in the procedure's executable section? (Choose two.) Mark for Review (1) Points

(Choose all correct answers)

EXECUTE IMMEDIATE 'DROP TABLE p_table_name';

EXECUTE IMMEDIATE 'DROP TABLE ' || p_table_name; (*)

v_sql_statement := 'DROP TABLE ' || p_table_name; EXECUTE IMMEDIATE v_sql_statement;

(*)

v_sql_statement := 'DROP TABLE ' || p_table_name; EXECUTE IMMEDIATE 'v_sql_statement';

v_sql_statement := 'DROP TABLE '; EXECUTE IMMEDIATE v_sql_statement p_table_name;

Correct

8. What will happen when the following procedure is invoked? CREATE OR REPLACE PROCEDURE do_some_work IS CURSOR c_curs IS SELECT object_name FROM user_objects WHERE object_type = 'FUNCTION'; BEGIN FOR v_curs_rec IN c_curs LOOP EXECUTE IMMEDIATE 'ALTER FUNCTION ' || v_curs_rec.object_name || ' COMPILE'; EXIT WHEN c_curs%ROWCOUNT > 2; END LOOP;

END;

Mark for Review (1) Points

All functions in the user's schema will be recompiled.

The first two functions in the user's schema will be recompiled.

The first three functions in the user's schema will be recompiled. (*)

The procedure will not compile successfully because you cannot ALTER functions using Dynamic SQL.

The procedure will not compile successfully because the syntax of the ALTER FUNCTION statement is incorrect.

Correct

Section 13 (Answer all questions in this section)

9. We want to create a log record automatically every time any DML operation is executed on either or both of the EMPLOYEES and DEPARTMENTS tables. What is the smallest number of triggers that must be create to do this? Mark for Review (1) Points

One

Two (*)

Three

Six

Eight

Correct

10. A BEFORE statement trigger inserts a row into a logging table every time a user updates the salary column of the employees table. The user now tries to update the salaries of three employees with a single UPDATE statement, but the update fails because it violates a check constraint. How many rows will be inserted into the logging table? Mark for Review (1) Points

None, the transactions are rolled back because the update failed. (*)

One

Three

Four

None of the above

Correct

Page 1 of 5 Next Summary

Test: Semester 2 Mid Term Exam

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

Section 13 (Answer all questions in this section)

11. Which of the following are possible keywords for the timing component of a trigger? (Choose three.) Mark for Review (1) Points

(Choose all correct answers)

BEFORE (*)

INSTEAD

WHENEVER

INSTEAD OF (*)

AFTER (*)

Correct

12. We want to prevent employees from being deleted on Sundays. To do this, we create the following trigger: CREATE OR REPLACE TRIGGER stop_del_emps ....... DELETE ON employees -- Line A BEGIN IF TO_CHAR(SYSDATE','DY') = 'SUN' THEN RAISE_APPLICATION_ERROR(-20101,'Invalid delete'); END IF; END;

Should this be a BEFORE or AFTER trigger, and why? Mark for Review (1) Points

It should be a BEFORE trigger because if an AFTER trigger were created, the employee would already have been deleted by the time the trigger checks the date. (*)

It should be a BEFORE trigger because you cannot use RAISE_APPLICATION_ERROR with AFTER triggers.

It should be an AFTER trigger because the Oracle Server cannot fire the trigger until it knows that the employee has been deleted.

It does not matter, either a BEFORE or an AFTER trigger could be created.

Correct

13. User KULJIT creates two triggers named EMP1_TRIGG and EMP2_TRIGG, which are both DML triggers referencing her EMPLOYEES table. Kuljit now wants to remove both of these triggers from the database. What command(s) should Kuljit use to do this? Mark for Review (1) Points

DROP ALL TRIGGERS ON employees;

DROP TRIGGERS ON employees;

DROP TRIGGER emp1_trigg; DROP TRIGGER emp2_trigg; (*)

DROP TRIGGER emp1_trigg AND emp2_trigg;

Correct

14. Which command would you use to see if your triggers are enabled or disabled? Mark for Review (1) Points

SELECT trigger_name, status FROM USER_TRIGGERS; (*)

SELECT object_name, status FROM USER_OBJECTS WHERE object_type = 'TRIGGER';

SELECT trigger_name, trigger_type FROM USER_TRIGGERS;

DESCRIBE TRIGGER

Correct

15. You have created several DML triggers which reference your DEPARTMENTS table. Now you want to disable all of them using a single SQL statement. Which command should you use? Mark for Review (1) Points

ALTER TRIGGER DISABLE ALL ON departments;

ALTER TABLE departments DISABLE ALL TRIGGERS; (*)

ALTER TABLE departments DISABLE TRIGGERS;

DROP ALL TRIGGERS ON departments;

Correct

16. What is the benefit of using the CALL statement in a trigger body? Mark for Review (1) Points

It allow both DDL events and database events to be handled by a single trigger.

It prevents data being read from a mutating table.

It allows the database administrator to monitor who is currently connected to the database.

It allows the trigger body code to be placed in a separate procedure. (*)

Correct

17. You have been granted CREATE TRIGGER privilege. You can now create an AFTER LOGOFF ON SCHEMA trigger. True or False? Mark for Review (1) Points

True

False (*)

Correct

18. Which of the following could NOT cause a DDL or Database Event trigger to fire? Mark for Review (1) Points

A table is dropped.

A user connects to the database.

The DBA starts up the database.

A user deletes rows from the EMPLOYEES table. (*)

A specific exception is raised in a user's session.

Correct

19. What is wrong with the following code? CREATE OR REPLACE TRIGGER call_trigg AFTER UPDATE OR DELETE ON employees BEGIN CALL del_emp_proc END;

Mark for Review (1) Points

When CALL is used, the BEGIN and END; statements should be omitted. (*)

The CALL statement should end with a semicolon (;)

You cannot use a CALL statement in a DML trigger.

When using CALL, only one DML statement can be tested, so UPDATE OR DELETE is wrong.

Correct

20. Which of the following are NOT allowed within a database trigger? (Choose two) Mark for Review (1) Points

(Choose all correct answers)

COMMIT (*)

A call to a packaged procedure

INSERT

A Boolean variable

SAVEPOINT (*)

Correct

Previous Page 2 of 5 Next Summary

Test: Semester 2 Mid Term Exam

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

Section 13 (Answer all questions in this section)

21. Which of the following are good guidelines to follow when creating triggers? (Choose two) Mark for Review (1) Points

(Choose all correct answers)

Be aware of recursive and cascading effects (*)

Where possible, use triggers to enforce NOT NULL constraints

Avoid lengthy trigger logic by creating a procedure and invoking it from within the trigger (*)

Use triggers to replace functionality which is already built into the database

Always create more triggers than you need, because it is better to be safe

Correct

22. A user's schema contains procedure MYPROC, function MYFUNC, trigger MYTRIGG and package MYPACK which contains a public procedure PACKPROC. These subprograms have no parameters, and the function returns a NUMBER. Which of the following calls to these objects (from an anonymous block) are incorrect? (Choose two) Mark for Review (1) Points

(Choose all correct answers)

mypack.packproc;

mytrigg; (*)

myproc;

v_number := myfunc;

IF NOT myfunc THEN ... (*)

Correct

23. Which of the following best describes a database trigger? Mark for Review (1) Points

It allows users to log on to the database

It executes automatically whenever a particular event occurs within the database (*)

It prevents unique constraints from being violated

It executes automatically whenever a user clicks on a button with their mouse

It allows foreign key constraints to be violated

Correct

24. A business rule states that an employee's salary must be between 4000 and 30000. We could enforce this rule using a check constraint, but it is better to use a database trigger. True or False? Mark for Review (1) Points

True

False (*)

Correct

25. Which of the following could NOT be done by a database trigger? Mark for Review (1) Points

Enforcing a complex business rule

Enforcing a complex database security check

Recalculating the total salary bill for a department whenever an employee's salary is changed

Ensuring that a student never arrives late for a class (*)

Keeping a log of how many rows have been inserted into a table

Correct

26. Examine the following code. To create a row trigger, what code should be included at Line A? CREATE OR REPLACE TRIGGER del_emp_trigg BEFORE DELETE ON employees ---- Line A BEGIN ...

Mark for Review (1) Points

FOR EVERY ROW

FOR EACH ROW (*)

FOR EVERY ROW

FOR ALL ROWS

Nothing is needed because DML triggers are row triggers by default.

Correct

27. Which of the following statements about INSTEAD OF triggers are NOT true? (Choose two.) Mark for Review (1) Points

(Choose all correct answers)

They can be created on a table. (*)

They can be created on a simple view.

They can be created on a complex view.

They can be statement triggers. (*)

They can be row triggers.

Correct

28. What are the timing events for a compound trigger? Mark for Review (1) Points

Before the triggering statement; After the triggering statement; Instead of the triggering statement.

Before the triggering statement; Before each row; After each row; After the triggering statement. (*)

Before the triggering statement; After the triggering statement; After each row.

Before the triggering statement; Before each row; After the triggering statement.

Correct

29. The following view and trigger have been created: CREATE VIEW dept_view AS SELECT * FROM departments;

CREATE OR REPLACE TRIGGER dept_view_trigg INSTEAD OF UPDATE ON dept_view BEGIN DBMS_OUTPUT.PUT_LINE('Sample Message'); END;

Departments 50 and 80 exist but department 81 does not. A user now executes the following statement:

UPDATE dept_view SET department_name = 'Sales' WHERE department_id IN (50,80,81);

What happens? Mark for Review (1) Points

Two rows are updated and "Sample Message" is displayed once.

No rows are updated and "Sample Message" is displayed once.

No rows are updated and "Sample Message" is displayed twice. (*)

No rows are updated and "Sample Message" is displayed three times.

None of the above.

Incorrect. Refer to Section 13 Lesson 3.

30. A row trigger has been created which is fired by UPDATE ON employees. A user now executes a single SQL statement which updates four rows of the EMPLOYEES table. How many times will the row trigger fire? Mark for Review (1) Points

Once

Twice

Four times (*)

Five times

Eight times

Correct

Previous Page 3 of 5 Next Summary

Test: Semester 2 Mid Term Exam

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

Section 10 (Answer all questions in this section)

31. Your schema contains a package called EMP_PKG. You want to remove the package body but not the specification. The correct syntax to do this is: DROP BODY emp_pkg; True or False? Mark for Review (1) Points

True

False (*)

Correct

32. What will be displayed when a user executes the following statement? SELECT object_name FROM user_objects WHERE object_type LIKE 'PACK%';

Mark for Review (1) Points

The names of all package specifications in the user's schema

The names of all package specifications and package bodies in the user's schema (*)

The parameters which must be used when invoking all packaged subprograms in the user's schema

The detailed code of all packages in the user's schema

The names of all packages which can be invoked by the user

Correct

33. A local variable defined inside a package procedure is visible to the calling environment. True or False? Mark for Review (1) Points

True

False (*)

Correct

34. When one component of a package is called, all the package's components are loaded into memory. True or False? Mark for Review (1) Points

True (*)

False

Correct

35. Examine the following package specification:

CREATE OR REPLACE PACKAGE mypack IS percent_tax NUMBER := 20; PROCEDURE proc1; END mypack;

The package body of mypack also includes a function called func1. Which of the following statements are true? (Choose three.)

Mark for Review (1) Points

(Choose all correct answers)

proc1 is a public procedure and func1 is a private function. (*)

The package will not compile because you cannot declare variables in the specification, only procedures and functions. .

The variable can be modified by: BEGIN mypack.percent_tax := 10; END;

(*)

The function can be invoked from outside the package.

The procedure can be invoked by: BEGIN mypack.proc1; END;

(*)

Correct

36. A number variable declared in a package is initialized to 0 unless assigned another value. True or False? Mark for Review (1) Points

True

False (*)

Correct

37. Package EMP_PACK contains two procedures, DEL_EMP and SHOW_EMP. You want to write an anonymous block which invokes these procedures but you have forgotten which parameters they use. Which of the following will give you this information? Mark for Review (1) Points

DESCRIBE del_emp DESCRIBE show_emp

DESCRIBE emp_pack(del_emp, show_emp)

DESCRIBE emp_pack (*)

DESCRIBE emp_pack.del_emp DESCRIBE emp_pack.show_emp

None of the above

Correct

38. Which of the following can be included in a package? Mark for Review (1) Points

procedures

variables

PL/SQL types

Exceptions

All of the above (*)

Correct

39. The two parts of a package are stored as separate objects in the database. True or False? Mark for Review (1) Points

True (*)

False

Correct

40. How would you invoke the constant km_to_mile from the global_consts bodiless package at VARIABLE A? SELECT trail_name, distance_in_km * VARIABLE A FROM trails WHERE park_name = 'YOSEMITE';

Mark for Review (1) Points

km_to_mile.global_consts

km_to_mile (global_consts)

global_consts.km_to_mile (*)

global_consts (km_to_mile)

Correct

Previous Page 4 of 5 Next Summary

Test: Semester 2 Mid Term Exam

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

Section 10 (Answer all questions in this section)

41. The following example package specification is valid to create a data type ed_type that can be used in other subprograms. True or False?

CREATE OR REPLACE PACKAGE emp_dept_pkg IS TYPE ed_type IS RECORD (f_name employees.first_name%TYPE, l_name employees.last_name%TYPE, d_name departments.department_name%TYPE); PROCEDURE sel_emp_dept (p_emp_id IN employees.employee_id%TYPE, p_emp_dept_rec OUT ed_type); END emp_dept_pkg;

Mark for Review (1) Points

True (*)

False

Correct

42. The package name must be included when calling a package function from a SELECT statement executed outside the package. True or False? Mark for Review (1) Points

True (*)

False

Correct

43. Which two of these functions could not be in the same package?

FUNCTION get_emp (p1 DATE) RETURN VARCHAR2; FUNCTION get_emp (p1 DATE, p2 NUMBER) RETURN VARCHAR2; FUNCTION get_emp (p1 DATE, p2 NUMBER) RETURN NUMBER; FUNCTION get_emp (p1 NUMBER, p2 DATE) RETURN VARCHAR2; Mark for Review (1) Points

1 and 2

1 and 4

2 and 4

2 and 3 (*)

3 and 4

Correct

44. Which of the following best describes a package initialization block? Mark for Review (1) Points

It is a named procedure in a package which must be invoked by a user before any other part of the package can be invoked.

It is an anonymous block in the package specification.

It is an anonymous block at the end of a package body which executes automatically the first time each user session invokes a subprogram in the package. (*)

It is a private function within the package body.

Because it is an anonymous block, it cannot be invoked and therefore will never execute. It is treated as a set of comments.

Correct

Section 11 (Answer all questions in this section)

45. In the following example, which statement best fits in Line 1? (Choose 1) DECLARE v_more_rows_exist BOOLEAN := TRUE; BEGIN -- Line 1 LOOP v_more_rows_exist := curs_pkg.fetch_n_rows(3); DBMS_OUTPUT.PUT_LINE('-------'); EXIT WHEN NOT v_more_rows_exist; END LOOP; curs_pkg.close_curs; END;

Mark for Review (1) Points

curs_pkg.emp_curs%ISOPEN;

curs_pkg.close_curs;

curs_pkg.open_curs; (*)

EXIT WHEN curs_pkg.emp_curs%NOTFOUND;

Correct

46. Users A and B call the same procedure in a package to initialize a global variable my_pkg.g_var. What will be the value of my_pkg.g_var for User A at Point A? User A: my_pkg.g_var is 10 User B: my_pkg.g_var is 10 User A: my_pkg.g_var is 50 User B: my_pkg.g_var is 25 Point A Mark for Review (1) Points

10

50 (*)

25

Correct

47. The DBMS_OUTPUT package is useful for which of the following activities? (Choose two) Mark for Review (1) Points

(Choose all correct answers)

Interact with a user during execution of a function or procedure.

Display results to the developer during testing for debugging purposes. (*)

Trace the code execution path for a function or procedure. (*)

Write operating system text files to the user's screen.

Correct

48. Using the FOPEN function, you can do which actions with the UTL_FILE package? (Choose 2) Mark for Review (1) Points

(Choose all correct answers)

It is used to append to a file until processing is complete. (*)

It is used to read and write text files stored outside the database. (*)

It is used to find out how much free space is left on an operating system disk.

It is used to manipulate large object data type items in columns.

Correct

49. Which general exceptions may be handled by the UTL_FILE package? (Choose 2) Mark for Review (1) Points

(Choose all correct answers)

TOO_MANY_ROWS

VALUE_ERROR (*)

ZERO_DIVIDE

NO_DATA_FOUND (*)

Correct

50. The DBMS_OUTPUT gives programmers an easy-to-use interface to see for instance the current value of a loop counter or if a program makes it to a particular branch of an IF statement. (True or False?) Mark for Review (1) Points

True (*)

False

Correct

Previous Page 5 of 5 Summary