PL/SQL Section 12 Quiz

 1. 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;


(1) Point

2. Which of the following are NOT benefits of using the NOCOPY hint? (Choose two)

(1) Point

3. You want to take make a copy of all the cities in the world listed in the cities table, which contains millions of rows. The following procedure accomplishes this efficiently. True or False?

CREATE OR REPLACE PROCEDURE copy_cities IS
  TYPE t_cities IS TABLE OF cities%ROWTYPE INDEX BY BINARY_INTEGER;
  v_citiestab t_emp;
BEGIN
  SELECT * BULK COLLECT INTO v_citiestab FROM cities;
  FORALL i IN v_citiestab.FIRST..v_citiestab.LAST
  INSERT INTO new_cities VALUES v_citiestab(i);
END copy_cities;


(1) Point

4. In the following example, where do you place the phrase DETERMINISTIC?

CREATE OR REPLACE FUNCTION total_sal
  (p_dept_id IN -- Position A
employees.department_id%TYPE)
  RETURN NUMBER -- Position B
    IS v_total_sal NUMBER;
BEGIN
  SELECT SUM(salary) INTO v_total_sal
    FROM employees WHERE department_id = p_dept_in;
  RETURN v_total_sal -- Position C;
END total_sal;


(1) Point

5. What is the correct syntax to use the RETURNING phrase at Position A?

DECLARE
TYPE EmpRec IS RECORD (last_name employees.last_name%TYPE, salary employees.salary%TYPE);
emp_info EmpRec;
emp_id NUMBER := 100;
BEGIN
  UPDATE employees
  SET salary = salary * 1.1 WHERE employee_id = emp_id
-- Position A
  dbms_output.put_line('Just gave a raise to ' || emp_info.last_name || ', who now makes ' || emp_info.salary);
END;


(1) Point

1. The following statement is a valid example of using the RETURNING clause. True or False?

DECLARE
   TYPE EmpRec IS RECORD (last_name employees.last_name%TYPE, salary employees.salary%TYPE);
   emp_info EmpRec;
   emp_id NUMBER := 100;
BEGIN
   UPDATE employees
   SET salary = salary * 1.1 WHERE employee_id = emp_id;
     RETURNING last_name, salary INTO emp_info;
     dbms_output.put_line('Just gave a raise to ' || emp_info.last_name ||
     ', who now makes ' || emp_info.salary);
END;


(1) Point

2. You want to take make a copy of all the cities in the world listed in the cities table, which contains millions of rows. The following procedure accomplishes this efficiently. True or False?

CREATE OR REPLACE PROCEDURE copy_cities IS
  TYPE t_cities IS TABLE OF cities%ROWTYPE INDEX BY BINARY_INTEGER;
  v_citiestab t_emp;
BEGIN
  SELECT * BULK COLLECT INTO v_citiestab FROM cities;
  FORALL i IN v_citiestab.FIRST..v_citiestab.LAST
  INSERT INTO new_cities VALUES v_citiestab(i);
END copy_cities;


(1) Point

3. A function-based index may be made using your own functions, but only if the function is created using the DETERMINISTIC clause. True or False?

(1) Point

4. What does the RETURNING clause do in the example below?

CREATE OR REPLACE PROCEDURE new_dept
  (p_dept_name IN departments.name%TYPE) IS
  v_new_dept_id departments.dept_id%TYPE;
BEGIN
  INSERT INTO departments (dept_id, name)
    VALUES dept_seq.NEXTVAL, p_dept_name
    RETURNING dept_seq.CURRVAL INTO v_new_dept_id;
  DBMS_OUTPUT.PUT_LINE(p_dept_name ||' is department number ' || v_new_dept_id);
END new_dept;


(1) Point

5. FORALL can only be used with the INSERT statement. True or False?

(1) Point

1. The following statement is a valid example of using the RETURNING clause. True or False?

DECLARE
   TYPE EmpRec IS RECORD (last_name employees.last_name%TYPE, salary employees.salary%TYPE);
   emp_info EmpRec;
   emp_id NUMBER := 100;
BEGIN
   UPDATE employees
   SET salary = salary * 1.1 WHERE employee_id = emp_id;
     RETURNING last_name, salary INTO emp_info;
     dbms_output.put_line('Just gave a raise to ' || emp_info.last_name ||
     ', who now makes ' || emp_info.salary);
END;


(1) Point

2. 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;


(1) Point

3. In the following example, where do you place the phrase DETERMINISTIC?

CREATE OR REPLACE FUNCTION total_sal
  (p_dept_id IN -- Position A
employees.department_id%TYPE)
  RETURN NUMBER -- Position B
    IS v_total_sal NUMBER;
BEGIN
  SELECT SUM(salary) INTO v_total_sal
    FROM employees WHERE department_id = p_dept_in;
  RETURN v_total_sal -- Position C;
END total_sal;


(1) Point

4. Where would you place the BULK COLLECT statement in the following example?

DECLARE
 TYPE DeptRecTab IS TABLE OF departments%ROWTYPE;
 dept_recs DeptRecTab;
CURSOR c1 IS
SELECT department_id, department_name, manager_id, location_id
  -- Position A
  FROM departments
  WHERE department_id > 70;
BEGIN
 OPEN c1
  -- Position B;
 FETCH c1
  -- Position C
 INTO dept_recs;
END;


(1) Point

5. You want to take make a copy of all the cities in the world listed in the cities table, which contains millions of rows. The following procedure accomplishes this efficiently. True or False?

CREATE OR REPLACE PROCEDURE copy_cities IS
  TYPE t_cities IS TABLE OF cities%ROWTYPE INDEX BY BINARY_INTEGER;
  v_citiestab t_emp;
BEGIN
  SELECT * BULK COLLECT INTO v_citiestab FROM cities;
  FORALL i IN v_citiestab.FIRST..v_citiestab.LAST
  INSERT INTO new_cities VALUES v_citiestab(i);
END copy_cities;


(1) Point

Komentar

Postingan populer dari blog ini

PL/SQL Section 15 Quiz

PL/SQL Section 13 Quiz