Database Programming With PL/SQL Semester 1 Final Review
Database Programming With PL/SQL Semester 1 Final Review
Database Programming With PL/SQL Semester 1 Final Review
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.
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.
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
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
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;
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;
14. What is the main purpose of the FOR UPDATE clause in a cursor declaration?
Especificar que un cursor puede ser actualizado
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
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
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?
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
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?
Sabiendo que se debe referenciar “record_name.field_name” entonces: P_EMP_RECORD.SALARY
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)
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
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.
27. What is the default data type of the primary key of an index?
La syntax para crearla puede ser mediante CREATE TABLE o ALTER TABLE, siendo un valor 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;
...
29. What are examples of methods to reference data or information about a table (circle answers)?
a. EXISTS
b. COUNT
c. PREVIOUS
d. NEXT
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)
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-EXCEPTIOM-INITOracle server error has an Oracle-supplied name associated with it.
EXCEPTION
WHEN NO_DATA_FOUND THEN
Statement 1;
WHEN NO_DATA_FOUND THEN
Statement 2;
WHEN OTHERS THEN
Statement 3; END;
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);
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');
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?
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
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 bloques_ compiled and stored in the database.
53. What is the command to make a new procedure named 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)?
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
a. USER_PROCEDURES
b. USER_OBJECTS
c. USER_CODE
56. What are the ways to execute the procedure get_name (circle answers)?
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)
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.
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)
a. A variable
b. A literal value
c. An expression
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)?
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)
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
73. What can a function do that a procedure cannot do (circle answer)?
74. What is a valid call of the get_sal function shown below (circle answers)?
75. A RETURN statement cannot be included in an exception handler in a function. (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)?
80. What is the correct statement to remove the double_sal function from your schema?
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 ON EMPLOYEES TO Tony
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?
Un usuario de definer's rights procedure requiere solo el privilegio para ejecutar el procedimiento, porque el
procedimiento de definer’s rights opera bajo el dominio de seguridad del usuario propietario del
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
procedimiento, independientemente de quién lo esté ejecutando. El propietario del procedimiento debe tener
todos los privilegios de objeto necesarios para los objetos a los que se hace referencia.
Para otorgar el creador del procedemiento solo se debe utilizar el privilegio EXECUTE al usuario primero
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?
90. What command is used to remove privileges from a user? El commando REVOKE
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