Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

Database Programming with PL/SQL

Final Exam
Name: Dizqy Hidayat DM (2101092044-MI2B)

1. What are the steps for using a cursor?

a. Define, select, close


b. Open, fetch, close
c. Define, open, fetch, close
d. Open, select, fetch, close

2. The following statement is a valid cursor declaration. (True or False)


DECLARE CURSOR dept_emp_cursor IS
SELECT department_name, COUNT(*) AS how_many
FROM departments d, employees e
WHERE d.department_id = e.department_id GROUP BY
d.department_name
HAVING COUNT(*) > 1;

3. OPEN is an executable statement that performs which of the following operations (circle answers)?

a. Executes the SELECT statement in the cursor declaration, returning the results into the active
set (fills the box with data)
b. Dynamically allocates memory for a context area
c. Retrieves the first row from the cursor.
d. Positions the pointer to the first row in the active set.

4. How do you test to see whether the cursor contains rows?


Adding COUNT(*) to the SELECT statement.
5. What is wrong with the following code?
The FETCH is before the OPEN the cursor

DECLARE
CURSOR emp_curs IS
SELECT last_name, salary FROM employees;
v_last_name employees.last_name%TYPE; v_salary
employees.salary%TYPE;
BEGIN
FETCH emp_curs INTO v_last_name, v_salary;
OPEN emp_curs;
FETCH emp_curs INTO v_last_name, v_salary;
CLOSE emp_curs;
END;

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
6. A cursor may be reopened at any time. (True or False)

7. The example below uses what type of composite data type structure? Cursor

DECLARE
CURSOR emp_cursor IS SELECT
employee_id, last_name FROM employees
WHERE department_id = 30; v_emp_record
emp_cursor%ROWTYPE; BEGIN
OPEN emp_cursor; LOOP
FETCH emp_cursor INTO v_emp_record;
...

8. How do you reference the last_name value inside the loop in the example below?
v_last_name

DECLARE
CURSOR emp_cursor IS SELECT
employee_id, last_name FROM employees
WHERE department_id = 30; v_emp_record
emp_cursor%ROWTYPE; BEGIN
OPEN emp_cursor; LOOP
FETCH emp_cursor INTO v_emp_record;
...
9. Which are the cursor attributes that return useful information about the execution of a cursor
manipulation statement (circle answers)?

a. %OPEN
b. %FOUND
c. %NOTFOUND
d. %ROWTYPE
e. %ROWCOUNT

10. What type of loop performs the following actions: The cursor is opened, a row is fetched once for each
iteration in the loop, the loop is terminated automatically when the last row is processed, and the
cursor is closed automatically.
For Loop

11. To display the last name of an employee, what code should you write at Point A in the
example below? Emp_record.salary

DECLARE
CURSOR emp_cursor IS SELECT * FROM employees; BEGIN
FOR emp_record IN emp_cursor LOOP DBMS_OUTPUT.PUT_LINE( --
Point A -- );
END LOOP; END;

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

2
12. Select the correct method for opening the cursor in the example below (circle answer).

CURSOR emp_curs
(p_dept_id employees.department_id%TYPE, p_job_id
employees.job_id%TYPE) IS SELECT * FROM
employees
WHERE department_id = p_dept_id AND job_id =
p_job_id;

a. OPEN emp_curs (20);


b. FOR emp_rec IN emp_curs (20) LOOP
c. OPEN emp_curs ('IT_PROG', 20);
d. FOR emp_rec IN emp_curs (20, 'IT_PROG') LOOP

13. Is this a valid cursor declaration? (Yes or No)

CURSOR dept_curs (p_loc_id NUMBER(4)) IS SELECT


* FROM departments
WHERE location_id = p_loc_id;

14. What is the main purpose of the FOR UPDATE clause in a cursor declaration?
Specify that a cursor can be updated
15. In which DML statements would you use the WHEN CURRENT OF clause?
UPDATE y DELETE

16. You want to fetch rows from the EMPLOYEES table. You want to lock the fetched rows, to prevent
other users from updating them. What would you write in Line A?

CURSOR emp_curs IS
SELECT department_name, employee_id, last_name, salary FROM employees
e, departments d
WHERE e.department_id = d.department_id
-- Line A -- ;

a. FOR UPDATE
b. FOR UPDATE OF employee_id
c. FOR UPDATE OF departments

17. You have declared a cursor as SELECT.....FOR UPDATE; You have OPENed the cursor and locked
the FETCHed rows. When are these row locks released?
When you explicitly COMMIT or ROLLBACK your transaction

18. What would you enter at Line A?

DECLARE
CURSOR region_cur IS SELECT *
FROM regions;
v_region_rec region_cur%ROWTYPE;
CURSOR country_cur (p_region_id NUMBER) IS SELECT *
FROM countries
WHERE region_id = p_region_id; v_country_rec
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

3
country_cur%ROWTYPE; BEGIN
OPEN region_cur; LOOP
FETCH region_cur INTO v_region_rec; EXIT WHEN
region_cur%NOTFOUND; DBMS_OUTPUT.PUT_LINE
(v_region_rec.region_name);
-- Line A -- LOOP
FETCH country_cur INTO v_country_rec; EXIT
WHEN country_cur%NOTFOUND;
......
a. OPEN country_cur (p_region_id);
b. OPEN country_cur (region_cur.region_id);
c. OPEN country_cur (region_cur.region_id);
d. OPEN country_cur (v_region_rec.region_id);

19. You cannot use a FOR loop with multiple cursors. (True or False)

20. A PL/SQL record is a composite data type consisting of a group of related data items stored as
fields, each with its own name and data type.
21. How do you create a PL/SQL record based on the EMPLOYEES table?

a. p_emp_record IN employees%TYPE
b. p_emp_record IN employees%ROWTYPE
c. p_emp_record IN employees%RECORD

22. How do you reference the SALARY field in the P_EMP_RECORD record?

23. A user-defined record cannot be defined using other records. (True or False)

24. The declaration below is a valid definition of a user-defined record using the
PERSON_TYPE record. (True or False)

TYPE employee_type IS RECORD (job_id


VARCHAR2(10), salary
NUMBER(8,2), person_data
person_type);
25. A PL/SQL collection is a composite data type and contains a set of occurrences of the same kind of data.

26. An INDEX BY table is based on a single field or column.

27. What is the default data type of the primary key of an index? the syntax to create it can be either CREATE
TABLE or ALTER TABLE . being on value NOT NULL

28. The following example declares two variables using the T_NAMES type. (True
or False)

DECLARE
TYPE t_names IS TABLE OF VARCHAR2(50) INDEX BY
PLS_INTEGER;
last_names_tab t_names; first_names_tab
t_names;
...
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

4
29. What are examples of methods to reference data or information about a table (circle answers)?

a. EXISTS
b. COUNT
c. PREVIOUS
d. NEXT

30. What does the following assignment do?

indicates that the longest / highest number

in the table will be delivered

v_highest_number :=

last_names_tab.LAST;
31. Which of the following examples declares an INDEX BY table of record?

a. TYPE t_emprec IS TABLE OF employees%TYPE INDEX


BY BINARY_INTEGER;
b. TYPE t_emprec IS TABLE OF employees%ROWTYPE INDEX
BY BINARY_INTEGER;
c. TYPE t_emprec IS INDEX TABLE OF employees%ROWTYPE
BY BINARY_INTEGER;

32. An exception is an error that occurs during the execution of the block, which disrupts the
normal operation of the program. (True or False)

33. What functions does an exception handler perform (circle answers)?

a. Defines the recovery actions to be performed when exceptions are raised.


b. Passes the error to the calling environment.
c. Allows a block of code to be executed completely.

34. The WHEN OTHERS handler can be the first of multiple handlers. (True or False)

35. An user_defined exception is raised when the programmer issues the RAISE statement.

36. A PRAGMA-EXEPTION-INIT Oracle server error has an Oracle-supplied name associated with it.

37. The TOO_MANY_ROWS error is raised under what typical condition?

exception

38. The example below is a valid block of code. (True or


Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

5
False) EXCEPTION
WHEN NO_DATA_FOUND THEN
Statement 1;
WHEN NO_DATA_FOUND THEN
Statement 2;
WHEN OTHERS THEN
Statement 3; END;

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

6
39. The example below is a valid block of code. (True or False)

EXCEPTION
WHEN ZERO_DIVIDE OR TOO_MANY_ROWS OR NO_DATA_FOUND THEN
Statement 1;
WHEN OTHERS THEN
Statement 2; END;

40. What two pre-defined functions provide the Oracle serer error number and message?

SQLCODE y SQLERRM

41. The example declaration below is valid for a non-predefined exception. (True or

False) DECLARE
e_insert_exp EXCEPTION;
PRAGMA EXCEPTION_INIT (e_insert_exp, -01400);

42. What message will appear when this exception is reached? _

WHEN OTHERS THEN


DBMS_OUTPUT.PUT_LINE (SQLCODE ||': '|| SQLERRM); END;

a. The code number and its associated error message.


b. The code will fail because SQLCODE and SQLERRM cannot be used directly in a SQL statement.
c. The code will fail because SQLCODE and SQLERRM were not declared.
d. The code will fail because the error number is represented by SQLERRNUM.
b
43. What type of exception is raised by the programmer?
User-defined exceptions

44. What steps are necessary for a programmer to define and use an error not defined by the
database (circle answers)?

a. Name the exception


b. Associate it with an error number
c. Explicitly raise the exception
d. Handle the exception

45. What is the method for calling an exception not defined by the database?

a. e_insert_exp;
b. CALL e_insert_exp;
c. RAISE e_insert_exp;
d. PRAGMA EXCEPTION_INIT (e_insert_exp);

46. To display your own error message and code, what is the correct code?

a. RAISE_APPLICATION_ERROR(20001, 'Message');
b. RAISE_ERROR (-20001, 'Message');
c. RAISE_APPLICATION_ERROR (-20001, 'Message');

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

7
d. RAISE APPLICATION_ERROR (20001, 'Message');

47. How would you reference the father’s birth date in Line A?
v_date_of_birth

<<outer>> DECLARE
v_father_name VARCHAR2(20):='Patrick';
v_date_of_birth DATE:='20-Apr-1972'; BEGIN
DECLARE
v_child_name VARCHAR2(20):='Mike';
v_date_of_birth DATE:='12-Dec-2002'; BEGIN
DBMS_OUTPUT.PUT_LINE('Name of father: '
|| v_father_name); DBMS_OUTPUT.PUT_LINE('Date of Birth: '
|| -- Line A -- );

48. What is the scope and visibility of v_name in the example below?

<<outer>> DECLARE
v_name VARCHAR2(20) BEGIN
<<inner>> DECLARE
v_name VARCHAR2(20) BEGIN
... END;
... END;

a. It is in scope and visible in the outer block only.


b. It is visible in both blocks but in scope only in the outer block.
c. It is in scope and visible in both blocks.
d. It is in scope in both blocks but visible only in the outer block.
49. Why does this example fail?
due to the blocks being declared incorrectly, because the message must be referenced for each specific block

<<outer>> DECLARE
v_name1 VARCHAR2(20); BEGIN
<<inner>> DECLARE
v_name2 VARCHAR2(20); BEGIN
DBMS_OUTPUT.PUT_LINE(v_name1); END;
DBMS_OUTPUT.PUT_LINE(v_name2); END;

50. A pre-defined Oracle server exception can be raised in an inner block and must be handled in
the outermost block. (True or False)

51. Two records exist for department 50. What will be displayed when this code is run?

DECLARE
v_last_name VARCHAR2(20); BEGIN
DBMS_OUTPUT.PUT_LINE('Message 1'); BEGIN
SELECT last_name into v_last_name
FROM employees WHERE department_id = 50; DBMS_OUTPUT.PUT_LINE('Message 2');
END; DBMS_OUTPUT.PUT_LINE('Message 3');
EXCEPTION

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

8
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Message 4');
END;

a. Message 1
b. Message 1 Message 4
c. Message 1 Message
3 Message 4

52. Procedures and functions are PL/SQL blocks compiled and stored in the database.
53. What is the command to make a new procedure named get_name?

a. INSERT OR REPLACE PROCEDURE get_name…


b. CREATE PROCEDURE get_name…
c. SAVE PROCEDURE get_name;

54. Stored procedures and functions improve performance of PL/SQL code. (True or False)

55. Which data dictionary views contain information about a procedure (circle answer)?

a. USER_PROCEDURES
b. USER_OBJECTS
c. USER_CODE

56. What are the ways to execute the procedure get_name (circle answers)?

a. From an anonymous block


b. From another procedure
c. From a DML statement
d. From Application Express

57. What is the phrase to update corrected code for the procedure get_name?

58. Which data dictionary view contains the code of the procedure get_name?

59. A parameter is the name of the variable passed into or out of a procedure. (True or False)

60. What is an argument?

a. A parameter
b. A variable
c. A value

61. Choose the correct syntax to create a procedure named get_name with two values p_id and p_name.

a. CREATE PROCEDURE (p_id NUMBER, p_name VARCHAR2) get_name IS…


b. CREATE PROCEDURE get_name (p_id NUMBER, p_name VARCHAR2) IS…
c. CREATE PROCEDURE get_name (p_id NUMBER(3), p_name VARCHAR2(25)) IS…
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

9
62. The name of a variable can be passed into a procedure as an argument. (True or False)

63. Formal parameter data types are defined with sizes. (True or False)
64. What is an actual parameter (circle answers)?

a. A variable
b. A literal value
c. An expression

65. What is the default parameter mode if no mode is specified? IN is the default mode for parameters

66. What is the parameter mode for a_emp_name in the query_emp procedure in the following example?

DECLARE
a_emp_name employees.last_name%TYPE; a_emp_sal
employees.salary%TYPE; BEGIN
query_emp(178, a_emp_name, a_emp_sal);
DBMS_OUTPUT.PUT_LINE('Name: ' || a_emp_name);
DBMS_OUTPUT.PUT_LINE('Salary: ' || a_emp_sal); END;

67. What is the actual parameter of the get_name procedure?

CREATE PROCEDURE get_name (p_id


INTEGER)
IS ...
BEGIN ... END;

DECLARE
v_id NUMBER(3) := 50; BEGIN
subproc(v_id); END;

a. p_id
b. v_id
c. 50
68. What is the correct method for calling the procedure add_dept (circle answers)?

CREATE OR REPLACE PROCEDURE add_dept


(p_name IN departments.department_name%TYPE, p_loc IN
departments.location_id%TYPE := 25) IS BEGIN
INSERT INTO departments (department_id, department_name, location_id) VALUES
(departments_seq.NEXTVAL, p_name, p_loc);
END add_dept;

a. EXECUTE add_dept ('Administration', 25);


b. add_dept ('Administration', 25);
c. add_dept ('Administration', p_loc=>25);
d. add_dept ('Administration');

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

10
69. Which mode of parameters cannot have a DEFAULT value? Un IN OUT

70. What command is used to remove a procedure from the database?


Un DROP PROCEDURE

71. A function is a named PL/SQL block that can accept optional IN parameters and must return a
single value. (True or False)

72. A function can be called as part of a PL/SQL expression only. (True or False)

73. What can a function do that a procedure cannot do (circle answer)?

a. Use all parameter three modes


b. Require a RETURN statement
c. Be called in a SQL expression

74. What is a valid call of the get_sal function shown below (circle answers)?

CREATE OR REPLACE 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;

a. v_salary := get_sal (100);


b. get_sal (100);
c. DBMS_OUTPUT.PUT_LINE (get_sal(100));
d. SELECT get_sal(100) FROM dual;

75. A RETURN statement cannot be included in an exception handler in a function. (True or False)

76. What is wrong with the following code?


The RETURN NUMBER has ascale and precesion

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;

77. A function cannot be used in a WHERE clause. (True or False)

78. A function can be used in the SET clause of an UPDATE statement. (True or False)

79. Which of the following SELECT statements using the function double_sal will work (circle answers)?

CREATE OR REPLACE FUNCTION double_sal (p_salary IN


employees.salary%TYPE) RETURN NUMBER IS
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

11
BEGIN
RETURN (p_salary * 2); END;

a. SELECT * FROM employees WHERE


double_sal (salary) > 20000;
b. SELECT last_name, double_sal (salary) FROM employees
WHERE department_id = 50;
c. SELECT SUM double_sal (salary) FROM employees;

80. What is the correct statement to remove the double_sal function from your schema?

a. DELETE FUNCTION double_sal;


b. DROP FUNCTION double_sal;
c. ALTER FUNCTION double_sal DISABLE;
d. DROP SUBPROGRAM double_sal;

81. Which data dictionary view is used to see the code of a function you created?
USER_OBJECT

82. Which dictionary view will list all the PL/SQL subprograms in your schema?
user_objects

83. Which data dictionary view will contain the list of tables that you have privileges to?
ALL * tables

84. Which privileges are found for tables but not for views (circle answers)?

a. SELECT
b. UDPATE
c. INDEX
d. ALTER

85. Christina creates a view called EMP_VIEW that is based on a SELECT from her EMPLOYEES
table. She now wants Tony to be able to query the view. What is the smallest set of object privileges
that Christina must grant to Tony?
GRANT SELECT OM EMPLOYEES TO Tony

86. Which statement will fail?

a. GRANT ALTER ON dept_view TO PUBLIC;


b. GRANT INSERT, UPDATE ON employees TO TOM, SUSAN;
c. GRANT SELECT ON departments TO PUBLIC;

87. To invoke a subprogram using Definer’s Rights, a user needs only EXECUTE privilege on the
subprogram. The user does NOT need any privileges on the objects referenced by SQL
statements within the subprogram. (True or False)

88. Jared creates a procedure called DEL_REGION using Definer's Rights, which deletes a row from his
REGIONS table. What privilege(s) will Pete need to be able to execute Jared’s procedure?

A user of the defines rights procedure requires only the privilege to execute the procedure, because the define
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

12
rights procedure operates under the security domain of the user who owns the procedure, regardless of who is
executing it. The procedure owner must have all the necessary object previliage for the referenced objects

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

13
89. Petra owns a DEPARTMENTS table. Zachary needs to update the location_id column of Petra’s table,
but no other columns. Which SQL statement should Petra execute to allow this?

a. GRANT UPDATE ON departments TO zachary;


b. GRANT UPDATE (location_id) ON departments TO zachary;
c. GRANT UPDATE ON departments (location_id) TO zachary;
d. GRANT UPDATE ON departments.location_id TO zachary;

90. What command is used to remove privileges from a user? Revoke this command

91. What is the clause to invoke Invoker’s Rights? AUTHID


92. Procedure UPD_EMPS includes an UPDATE on the EMPLOYEES table. The procedure was
created using Invoker's Rights. Which of the following statements are true (circle answers)?

a. The creator of the procedure needs UPDATE privilege on EMPLOYEES.


b. The user who executes the procedure needs EXECUTE privilege on the procedure.
c. The user who executes the procedure needs UPDATE privilege on EMPLOYEES.
d. The user who executes the procedure does not need any privileges.

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

14
Database Programming with PL/SQL
Final Exam
Name: M.Rifki Ferdian (2101092030-MI2B)

1. A trigger executes immediately whenever the associated action occurs. (True


or False)

2. Name the types of DML triggers (circle answers).

a. Row
b. Application
c. User connection
d. Statement

3. A database trigger executes whenever a data event, systems event, or application event occurs on
the database. (True or False)

4. A good use of a trigger is to validate that a value is not null in a column. (True or False)

5. Which data dictionary contains the source code for a user’s triggers?
The USER_SOURCE data dictionary contains the source code for a user’s triggers in oracle

6. Which of the following are NOT allowed within a database trigger (circle answers)?

a. INSERT
b. A call to a packaged procedure
c. DROP
d. A mouse click on a radio button
e. COMMIT

7. DML triggers only fire once upon execution of a complete DML statement. (True or False)

8. A row trigger executes how many times?


A row trigger executes once for each affected row by the trigger statment
9. A statement trigger executes once even if no rows are affected. (True or False)

10. The INSTEAD OF trigger is used mainly for what type of database object? The INSTEAD OF trigger is mainly used
for views. It allows you to execute specific actions instead of the triggering action, such as insert, update, or delete on a view
that cannot be done directly

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
11. How many times will this trigger execute and when?
This trigger will execute once after an insert statement on the "employees" table is executed. It will insert a row into the
"log_emp_table" containing the username of the user who executed the insert statement and the current date and time.

CREATE OR REPLACE TRIGGER log_emp


AFTER INSERT ON employees BEGIN
INSERT INTO log_emp_table (who, when) VALUES (USER,
SYSDATE);
END;

12. You want a trigger to fire when the SALARY column is updated in the EMPLOYEES table. Which of
the following is the correct syntax for creating that DML trigger?

a. CREATE OR REPLACE TRIGGER sal_upd_trigg


AFTER UPDATE ON employees (salary)
BEGIN
… END;
b. CREATE OR REPLACE TRIGGER sal_upd_trigg AFTER
UPDATE OF salary ON employees BEGIN
… END;
c. CREATE OR REPLACE TRIGGER sal_upd_trigg
BEFORE UPDATE OF salary ON employees BEGIN
… END;

13. What is wrong with the following code?

CREATE OR REPLACE TRIGGER mytrigg


AFTER DELETE ON departments BEGIN
INSERT INTO audit_table (who, when)
VALUES (USER, SYSDATE); COMMIT;
END;

14. What is the clause to include when creating a row-level trigger? The FOR EACH ROW clause is used when creating a
row-level trigger. This clause specifies that the trigger will execute once for each affected row by the triggering statement

15. If there are 4 employees in department 20, how many times will a row-level AFTER trigger fire when an
UPDATE statement is executed? If there are 4 employees in department 20 and an UPDATE statement is
executed on the table that contains these employees, a row-leve

16. 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? A BEFORE statement trigger inserts a row into a logging table every
time a user updates the salary column of the employees table. If the user tries to update the salaries of three
employees with a single UPDATE statement but the update fails because it violates a check constraint, no row
will be inserted into the logging table since the

17. The OLD and NEW qualifiers can be used with statement triggers as well as row triggers. (True or
False)
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

2
18. INSTEAD OF triggers are only row-level triggers. (True or False)

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

3
19. Which of the following are DDL or database event triggers (circle answers)?

a. A view is dropped
b. A user deletes a row from the DEPARTMENTS table
c. A user connects to the database
d. A specific exception is raised in a user’s session

20. What clause would be inserted into Line A to write a log record every time a new object is created
in our schema? The clause "AFTER CREATE ON SCHEMA" would be inserted into Line A in order to
write a log record every time a new object is created in our schema. This triggers the log_create_trigg trigger
every time an object is created in the schema, and the INSERT INTO log_table statement writes the current
user and current date and time to the log_table.

CREATE OR REPLACE TRIGGER log_create_trigg


-- Line A -- BEGIN
INSERT INTO log_table VALUES (USER,
SYSDATE); END;

21. You can create a trigger that prevents DDL statements on an individual table, while still
allowing DDL on other tables in the same schema. (True or False)

22. The DBA wants to keep track of server error ORA-00942. What clause is inserted into Line A in
the following code? IF (ORA_IS_INTERNAL_ERROR(942))

CREATE OR REPLACE TRIGGER servererror_trig AFTER


SERVERERROR ON SCHEMA
BEGIN
-- Line A --
INSERT INTO error_log_table ... END
IF; END;

23. What is a mutating table?

a. A table with more than one trigger


b. A table that is being modified by a DML statement
c. A table that is part of a view
24. What is the purpose of the CALL keyword in a trigger?
The CALL keyword is used in a trigger to invoke a stored procedure, function or package. It is used to execute specific
actions within the trigger body. The CALL keyword is typically used to perform complex calculations or to perform
additional data validation and manipulation that cannot be done directly within the trigger.

25. What is wrong with the following code? The problem with the following code is

that it's an incomplete trigger definition The BEGIN keyword is missing before

the CALL statement.

CREATE OR REPLACE TRIGGER emp_trig AFTER UPDATE


OR DELETE ON employees BEGIN
CALL del_emp_proc; END;

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

4
26. Why will this trigger fail?

CREATE OR REPLACE TRIGGER check_salary


BEFORE INSERT OR UPDATE OF salary, job_id ON employees FOR EACH
ROW
DECLARE
v_minsalary employees.salary%TYPE; v_maxsalary
employees.salary%TYPE; BEGIN
SELECT MIN(salary), MAX(salary) INTO
v_minsalary, v_maxsalary FROM
employees WHERE job_id = :NEW.job_id;
IF
:NEW.salary < v_minsalary OR
:NEW.salary > v_maxsalary THEN RAISE_APPLICATION_ERROR(-
20505,'Salary out of range'); END IF;
END;

a. DECLARE is not a valid clause in a trigger definition.


b. The trigger is SELECTing from the same table as the triggering DML statement is referencing.
c. SELECT is invalid in a DML trigger.

27. Statements in the trigger body use the privileges of the trigger user, not the privileges of the
owner executing the operation that fires the trigger. (True or False)

28. A user must be granted the CREATE TRIGGER system privilege to create a trigger in his/her
schema. (True or False)
29. What privileges listed below will James need to create the following trigger (circle answers)?

CREATE OR REPLACE TRIGGER upd_tom_emp_trig AFTER


UPDATE ON tom.employees
BEGIN
INSERT INTO mary.log_table VALUES(USER,SYSDATE);
sharon.calledproc; END;

a. CREATE TRIGGER
b. EXECUTE on sharon.calledproc
c. ALTER on tom.employees
d. INSERT INTO mary.log_table

30. What clause should be in Line A to see the trigger code for the RESTRICT_SALARY trigger?

SELECT trigger_name, trigger_type, triggering_event,


table_name, status, trigger_body
-- Line A --
WHERE trigger_name = 'RESTRICT_SALARY';

31. Which data dictionary view shows the compilation errors of a trigger?
The data dictionary view that shows the compilation errors of a trigger is the USER_ERRORS view.

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

5
32. Which statement will disable the triggers on the DEPARTMENTS table?

a. ALTER TRIGGER ALL TRIGGERS ON departments DISABLE;


b. ALTER TRIGGER DISABLE ALL TRIGGERS ON TABLE departments;
c. ALTER TABLE departments DISABLE ALL TRIGGERS;

33. What command will recompile the EMP_TRIG trigger?

a. COMPILE TRIGGER emp_trig;


b. ALTER TRIGGER COMPILE emp_trig;
c. ALTER TRIGGER emp_trig COMPILE;

34. All triggers on a table are removed when the table is removed. (True or False)
35. What happens when the user removes the EMPLOYEES table?

CREATE OR REPLACE TRIGGER emp_trigg


AFTER DELETE ON employees BEGIN
... END;

a. An error message appears because you cannot remove a table that has a trigger.
b. The table is dropped, and the trigger is disabled.
c. The trigger and the table are dropped.

36. In which data dictionary view can you see the status of a schema object?
In the USER_OBJECTS data dictionary view, you can see the status of a schema object.

37. A procedure is said to be cascaded when it is referenced by a table.

38. A single PL/SQL subprogram such as a procedure can be both a referenced object and a
dependent object. (True or False)

39. If the table EMPLOYEES is updated to include a new column, what is the status of a
procedure that contains a cursor based on the EMPLOYEES table? (Valid or Invalid)

40. The ADD_EMP procedure contains a SELECT statement using the EMP_VIEW, which is a subset of
the EMPLOYEES table. What is the relationship of the ADD_EMP procedure to the EMPLOYEES
table?
The relationship of the ADD_EMP procedure to the EMPLOYEES table is dependent.

41. The following statement will show the dependencies and references for the listed objects. (True
or False)

SELECT name, type, referenced_name, referenced_typeFROM USER_DEPENDENCY WHERE


referenced_name IN ('EMPLOYEES','EMP_VW' );

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

6
42. Which of the following statements will show whether procedure ADD_EMP is valid or invalid?

a. SELECT valid FROM USER_OBJECTS WHERE


object_type = 'PROCEDURE' AND object_name =
'ADD_EMP';
b. SELECT status FROM USER_OBJECTS WHERE
object_type = 'PROCEDURE' AND object_name =
'ADD_EMP';
c. SELECT status FROM USER_PROCEDURES
WHERE procedure_name = 'ADD_EMP';
d. SELECT * FROM deptree;

43. What does the following example PL/SQL code do?

BEGIN deptree_fill('TABLE','ALICE','EMPLOYEES'); END;

a. Displays the DEPTREE table showing the dependencies on EMPLOYEES in ALICE’s schema.
b. Fills the DEPTREE table showing the dependencies on EMPLOYEES in ALICE’s schema.
c. Inserts data into the DEPTREE_TEMPTAB showing the dependencies on EMPLOYEES in ALICE’s
schema.

44. What object do you use to see the dependencies after executing the DEPTREE_FILL procedure?
After executing the DEPTREE_FILL procedure, you can use the DEPTREE table to see the dependencies of the
specified object.

45. The IDEPTREE view shows dependencies by indenting the lines of output instead of by using
a NESTED_LEVEL column. (True or False)

46. Which methods below minimizes dependency failure (circle answers)?

a. Declaring records with the %ROWTYPE attribute


b. Declaring variables with the %TYPE attribute
c. Querying with the SELECT [column] notation
d. Including a column list with INSERT statements

47. What four objects can you manually recompile?

1. Procedures: A procedure can be recompiled using the ALTER PROCEDURE statement.


2. Functions: A function can be recompiled using the ALTER FUNCTION statement.
3. Packages: A package can be recompiled using the ALTER PACKAGE statement.
4. Triggers: A trigger can be recompiled using the ALTER TRIGGER statement.

48. Package DEPT_PKG contains two public procedures: GET_DEPT and UPD_DEPT. A separate procedure
DEPT_RPT invokes DEPT_PKG.GET_DEPT. The UPD_DEPT package body code is now altered, and
the package body (but not the package specification) is recreated. DEPT_RPT will be marked invalid and
needs to be recompiled. (True or False)

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

You might also like