Oracle Quiz Answers. Oracle Quiz Questions An asterisk (*) indicates a correct answer.
joi, 14 februarie 2013
PLSQL Mid Term Exam Semester 1 - Part II
1. A cursor is declared as:
CURSOR c IS SELECT * FROM departments FOR UPDATE;
After opening the cursor and fetching some rows, you want to delete the most recently
fetched row. Which of the following will do this successfully?
DELETE FROM c WHERE CURRENT OF c;
DELETE FROM departments WHERE CURRENT OF c; (*)
DELETE FROM c WHERE CURRENT OF departments;
DELETE FROM departments WHERE c%ROWCOUNT = 1;
None of the above.
2. Examine the following code:
DECLARE
CURSOR c IS SELECT * FROM employees FOR UPDATE;
c_rec c%ROWTYPE;
BEGIN
OPEN c;
FOR i IN 1..20 LOOP
FETCH c INTO c_rec;
IF i = 6 THEN
UPDATE employees SET first_name = 'Joe'
WHERE CURRENT OF c;
END IF;
END LOOP;
CLOSE c;
END;
Which employee row or rows will be updated when this block is executed?
The first 6 fetched rows will be updated.
No rows will be updated because you locked the rows when the cursor was opened.
The 6th fetched row will be updated. (*)
The block will not compile because the cursor should have been declared .... FOR
UPDATE WAIT 5;
None of the above.
3. You want to declare a cursor which locks each row fetched by the cursor.
Examine the following code:
DECLARE
CURSOR emp_curs IS
SELECT * FROM employees
FOR --Point A
Which of the following can NOT be coded at Point A?
UPDATE;
UPDATE OF salary;
UPDATE OF employees; (*)
UPDATE NOWAIT;
4. Which of the following cursor attributes is set to the total number of rows returned so far?
Mark for Review
(1) Points
%ISOPEN
%NOTFOUND
%FOUND
%ROWCOUNT (*)
5. Assume that you have declared a cursor called C_EMP. Which of the following
statements about C_EMP is correct? (Choose two.) (Choose all correct answers)
You can use c_emp%NOTFOUND to exit a loop. (*)
You can fetch rows when c_emp%ISOPEN evaluates to FALSE.
You can use c_emp%ROWCOUNT to return the number of rows returned by the cursor so far. (*)
You can use c_emp%FOUND after the cursor is closed.
6. The DEPARTMENTS table contains four columns. Examine the following code:
DECLARE
CURSOR dept_curs IS
SELECT * FROM departments;
v_dept_rec dept_curs%ROWTYPE;
CURSOR dept_curs IS
SELECT * FROM departments;
v_dept_rec dept_curs%ROWTYPE;
BEGIN
OPEN dept_curs;
FETCH dept_curs INTO v_dept_rec;
...
Which one of the following statements is true?
v_dept_rec contains the first four rows of the departments table.
The FETCH will fail because the structure of v_dept_rec does not match the structure of the cursor.
v_dept_rec contains the first row of the departments table. (*)
The block will fail because the declaration of v_dept_rec is invalid.
7. The following cursor has been declared:
CURSOR emp_curs IS
SELECT first_name, last_name, job_id, salary
FROM employees;
Which of the following correctly declares a composite record with the same structure as the cursor?
emp_rec emp_rec%ROWTYPE;
emp_rec emp_curs%TYPE;
emp_rec emp_curs%ROWTYPE; (*)
emp_rec cursor%ROWTYPE;
8. Which of the following cursor attributes evaluates to TRUE if the cursor is open?
%ISOPEN (*)
%NOTFOUND
%FOUND
%ROWCOUNT
9. Examine the following code fragment:
DECLARE
CURSOR emp_curs IS
SELECT first_name, last_name FROM employees;
v_emp_rec emp_curs%ROWTYPE;
BEGIN
...
FETCH emp_curs INTO v_emp_rec;
DBMS_OUTPUT.PUT_LINE(... Point A ...);
 ...
To display the fetched last name, what should you code at Point A?
v_emp_rec.last_name (*)
v_emp_rec(last_name)
v_emp_rec
last_name
None of the above
10. Which statement best describes when a WHILE loop shouild be used?
When the number of iterations is known
When repeating a sequence of statements until the controlling condition is no longer true (*)
When assigning a value to a Boolean variable
When testing whether a variable is null
11. Which of the following blocks produces the same output as this block?
BEGIN
FOR i in 1 .. 3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
DECLARE
i PLS_INTEGER := 0;
BEGIN
WHILE i<3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i + 1;
END LOOP;
END;
DECLARE
i PLS_INTEGER := 0;
BEGIN
WHILE i<3 LOOP
i := i + 1;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END; (*)
DECLARE
i PLS_INTEGER := 0;
BEGIN
WHILE i<3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
i := i+ 1;
END;
12. What will happen when the following code is executed?
BEGIN
FOR i in 1 ..3 LOOP
DBMS_OUTPUT.PUT_LINE (i);
i := i + 1;
END LOOP;
END; END;
It will display 1, 2, 3.
It will display 2, 3, 4.
It will result in an error because you cannot modify the counter in a FOR loop. (*)
It will result in an error because the counter was not explicitly declared.
13. In a WHILE loop, the statements inside the loop must execute at least once. True or False?
True
False (*)
14. In a FOR loop, an implicitly declared counter automatically increases or
decreases with each iteration. True or False?
True (*)
False
15. Examine the following code:
DECLARE
v_bool BOOLEAN := FALSE;
v_counter NUMBER(4) := 0;
BEGIN
... Line A
END;
Which of the following is NOT valid at line A?
WHILE NOT v_boolean LOOP
WHILE v_boolean AND v_counter < 6 LOOP
WHILE v_counter > 8 LOOP
WHILE v_counter IN 1..5 LOOP (*)
16. You want to assign a value to v_result which depends on the value of v_grade: if v_grade
= 'A' set v_result to 'Very Good' and so on.
DECLARE
v_grade CHAR(1);
v_result VARCHAR2(10);
BEGIN
v_result :=
CASE v_grade
The next line should be
WHEN v_grade = 'A' THEN 'Very Good'
WHEN 'A' THEN 'Very Good';
WHEN 'A' THEN v_result := 'Very Good';
WHEN 'A' THEN 'Very Good' (*)
17. What value will v_answer contain after the following code is executed?
DECLARE
v_age NUMBER:= 18;
v_answer VARCHAR2(10);
BEGIN
v_answer :=
CASE
WHEN v_age < 25 THEN 'Young'
WHEN v_age = 18 THEN 'Exactly 18'
ELSE 'Older'
END CASE;
END;
Exactly 18
Young (*)
Null
Older
Correct
18. What will be the value of v_result after the following code is executed?
DECLARE
v_grade CHAR(1) := NULL;
v_result VARCHAR2(10);
BEGIN
CASE v_grade
WHEN 'A' THEN v_result := 'Very Good';
WHEN 'F' THEN v_result := 'Poor';
ELSE v_result := 'In Between';
END;
END;
Poor
In Between (*)
Null
Very Good
19. What will be the value of v_sal_desc after the following code is executed?
DECLARE
v_salary NUMBER(6,2) := NULL;
v_sal_desc VARCHAR2(10);
BEGIN
CASE
WHEN v_salary < 10000 THEN v_sal_desc := 'Low Paid';
WHEN v_salary >= 10000 THEN v_sal_desc := 'High Paid';
END CASE;
END;
High Paid
Low Paid
Null
The code will fail and return an exception (*)
20. You want to display a message which depends on the value of v_grade: if
v_grade = 'A' display 'Very Good', if v_grade = 'B' then display 'Good', and so on.
DECLARE
v_grade CHAR(1);
BEGIN
CASE v_grade
The next line should be
WHEN 'A' THEN (*)
WHEN v_grade = 'A' THEN
WHEN 'A' THEN;
IF 'A' THEN
21. Which of these constructs can be used to fetch multiple rows from a cursor's active set?
A CASE statement
An IF .... ELSE statement
A basic loop which includes FETCH and EXIT WHEN statements (*)
A basic loop which includes OPEN, FETCH and CLOSE statements
22. An explicit cursor must always be declared, opened and closed by the PL/SQL
programmer. True or False?
True
False (*)
23. Examine the following code:
DECLARE
CURSOR emp_curs IS
SELECT last_name, salary
FROM employees
ORDER BY salary;
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
...
Which of the following statements successfully opens the cursor and fetches the first row of
the active set?
OPEN emp_curs;
FETCH emp_curs INTO v_last_name, v_salary; (*)
OPEN emp_curs;
FETCH emp_curs INTO v_salary, v_last_name;
OPEN emp_curs;
FETCH FIRST emp_curs INTO v_last_name, v_salary;
OPEN emp_curs;
FETCH emp_curs;
24. Which of these statements about implicit cursors is NOT true?
They are declared automatically by Oracle for single-row SELECT statements.
They are declared automatically by Oracle for all DML statements.
They are declared by the PL/SQL programmer. (*)
They are opened and closed automatically by Oracle.
25. After a cursor has been closed, it can be opened again in the same PL/SQL block. True or False?
True (*)
False
26. The employees table contains 20 rows. What will happen when the following code is executed?
DECLARE
 CURSOR emp_curs IS
 SELECT job_id FROM employees;
v_job_id employees.job_id%TYPE;
BEGIN
OPEN emp_curs;
LOOP
FETCH emp_curs INTO v_job_id;
DBMS_OUTPUT.PUT_LINE(v_job_id);
EXIT WHEN emp_curs%NOTFOUND;
END LOOP;
CLOSE emp_curs;
END;
20 job_ids will be displayed.
The block will fail and an error message will be displayed.
21 rows of output will be displayed; the first job_id will be displayed twice.
21 rows of output will be displayed; the last job_id will be displayed twice. (*)
27. What will happen when the following code is executed?
DECLARE
CURSOR emp_curs IS
SELECT salary FROM employees;
v_salary employees.salary%TYPE;
BEGIN
FETCH emp_curs INTO v_salary;
DBMS_OUTPUT.PUT_LINE(v_salary);
CLOSE emp_curs;
END;
The first employee's salary will be fetched and displayed.
All employees' salaries will be fetched and displayed.
The execution will fail and an error message will be displayed. (*)
The lowest salary value will be fetched and displayed.
28. For which type of SQL statement must you use an explicit cursor?
DML statements that process more than one row.
Queries that return more than one row. (*)
Data Definition Language (DDL) statements.
Queries that return a single row.
29. When using multiple nested cursors, what kinds of loops can you use?
Cursor FOR loops only.
Basic loops only.
WHILE loops only.
None of the above.
All of the above. (*)
30. How many explicit cursors can be declared and used in a single PL/SQL block?
One or two.
Only one.
As many as needed. (*)
Up to eight cursors.
None of the above.
31. What is wrong with the following code?
DECLARE
CURSOR emp_curs(p_dept_id NUMBER) IS
SELECT * FROM employees WHERE department_id = p_dept_id;
BEGIN
FOR dept_rec IN (SELECT * FROM departments) LOOP
DBMS_OUTPUT.PUT_LINE(dept_rec.department_name);
FOR emp_rec IN emp_curs(dept_rec.department_id) LOOP
DBMS_OUTPUT.PUT_LINE(emp_rec.last_name);
END LOOP;
END LOOP;
END;
The DEPARTMENTS cursor must be declared with a parameter.
You cannot use a cursor with a subquery in nested loops.
You cannot use two different kinds of loop in a single PL/SQL block.
EMP_CURS should not be DECLAREd explicitly; it should be coded as a subquery in a cursor FOR loop.
Nothing is wrong. The block will execute successfully and display all departments and the employees in those departments. (*)
32. Examine the following code:
BEGIN
FOR i IN 1..5 LOOP
FOR j IN 1..8 LOOP
EXIT WHEN j = 7;
DBMS_OUTPUT.PUT_LINE(i || j);
END LOOP;
END LOOP;
END;
How many lines of output will be displayed when this code is executed?
35
6
30 (*)
40
33. What kinds of loops can be nested?
BASIC loops
WHILE loops
FOR loops
All of the above (*)
34. A PL/SQL block contains the following code:
v_counter := 1;
LOOP
EXIT WHEN v_counter = 5;
v_counter := v_counter + 1;
END LOOP;
What is the value of V_COUNTER after the loop is finished?
5 (*)
6
1
This is an infinite loop; the loop will never finish.
35. What kind of statement is best suited for displaying the multiplication table for "sixes": 6x1=6, 6x2=12 ... 6x12=72?
CASE expression
IF statement
CASE statement
LOOP statement (*)
36. Which one of these is NOT a kind of loop?
ASCENDING loop (*)
FOR loop
Basic loop
WHILE loop
37. A PL/SQL block contains the following code:
v_counter := 1;
LOOP
EXIT WHEN v_counter=5;
END LOOP;
v_counter := v_counter + 1;
What is the value of V_COUNTER after the loop is finished?
5
6
1
This is an infinite loop; the loop will never finish. (*)
38. Which one of these tasks is best done using a LOOP statement?
Assigning a letter grade to a numerical score
Calculating and displaying the sum of all integers from 1 to 100 (*)
Testing if a condition is true, false or null
Fetching and displaying an employee's last name from the database
39. What is the correct form of a compound IF statement?
IF condition
THEN statement1
ELSE statement 2;
IF condition
THEN statement1
ELSE statement 2;
END IF;
IF condition;
THEN statement1;
ELSE statement2;
END IF;
IF condition THEN statement1;
ELSE statement2;
END IF; (*)
40. Examine the following code:
DECLARE
v_salary NUMBER(6);
v_constant NUMBER(6) := 15000;
v_result VARCHAR(6); := 'MIDDLE';
BEGIN
IF v_salary != v_constant THEN
v_result := 'HIGH';
ELSE
v_result := 'LOW';
END IF;
END;
What is the final value of v_result?
HIGH
LOW (*)
MIDDLE
Null
41. What is the correct form of a simple IF statement?
IF condition THEN statement;
IF condition THEN statement;
END IF; (*)
IF condition;
THEN statement;
END IF;
IF condition
THEN statement
ENDIF;
42. What is the correct name for CASE, LOOP, WHILE, and IF-THEN-ELSE
structures ?
Control structures (*)
Array structures
Memory structures
Cursor structures
43. There are 12 distinct JOB_IDs in the EMPLOYEES table. You need to write
some PL.SQL code to fetch and display all the employees with a specific JOB_ID. The
chosen JOB_ID can be different each time the code is executed.
What is the best way to do this?
Write 12 separate PL/SQL blocks, each declaring a cursor with a different JOB_ID in the WHERE clause.
Write a single PL/SQL block which declares 12 cursors, one for each distinct value of JOB_ID.
Write a single PL/SQL block which declares one cursor using a parameter for the JOB_ID. (*)
Write a single PL/SQL block which uses a cursor to fetch all the employee rows, with an IF statement to decide which of the fetched rows to display.
44. Examine the following declaration of a cursor with a parameter. What should be coded at Point A? DECLARE
CURSOR emp_curs(--Point A --) IS
SELECT * FROM employees
WHERE job_id = p_job_id;
p_job_id
ST_CLERK'
p_job_id VARCHAR2(25)
p_job_id VARCHAR2 (*)
job_id VARCHAR2
45. Examine the following code. To display the salary of an employee, what must be coded at Point A?
DECLARE
CURSOR emp_curs IS SELECT * FROM employees;
BEGIN
FOR emp_rec IN emp_curs LOOP
DBMS_OUTPUT.PUT_LINE( --what goes here ? );
END LOOP;
END;
salary
emp_curs.salary
emp_rec.salary (*)
employees.salary
emp_rec.salary IN emp_curs
46. When using a cursor FOR loop, OPEN, CLOSE and FETCH statements should not be explicitly coded. True or False?
True (*)
False
47. What is wrong with the following code?
DECLARE
CURSOR dept_curs IS SELECT * FROM departments;
BEGIN
FOR dept_rec IN dept_curs LOOP
DBMS_OUTPUT.PUT_LINE(dept_curs%ROWCOUNT || dept_rec.department_name);
END LOOP;
DBMS_OUTPUT.PUT_LINE(dept_rec.department_id);
END;
The cursor DEPT_CURS has not been opened.
The implicitly declared record DEPT_REC cannot be referenced outside the cursor FOR loop. (*)
You cannot use %ROWCOUNT with a cursor FOR loop.
The cursor DEPT_CURS has not been closed.
Nothing is wrong, this code will execute successfully.
PLSQL Semester 1 Mid Term Exam - Part I
1. PL/SQL is an Oracle proprietary, procedural, 4GL programming language. True or False?
True
False (*)
2. PL/SQL extends SQL by including all of the following except:
variables
conditional statements
reusable program units
constants
nonprocedural constructs (*)
3. Which of the following statements about PL/SQL and SQL is true?
PL/SQL and SQL are both ANSI-compliant.
PL/SQL and SQL can be used with many types of databases, including Oracle.
PL/SQL and SQL are both Oracle proprietary programming languages.
PL/SQL allows basic program logic and control flow to be combined with SQL statements. (*)
4. Using Oracle Application Express, you can create Web applications that include PL/SQL. True or False?
True (*)
False
5. The fact that PL/SQL is portable is a good thing because:
Exceptions can be ported to different operating systems
Blocks can be sent to the operating system.
PL/SQL code can be developed on one platform and deployed on another (*)
PL/SQL code can be run on any operating system without a database
6. Which of the following can you use PL/SQL to do?
Update data (DML)
Develop Web applications using the Web Application Toolkit
Manage database security
Create customized reports
All of the above (*)
7. Which of the following tools can NOT be used to develop and test PL/SQL code?
Oracle Jdeveloper
Oracle Application Express
Oracle JSQL (*)
Oracle iSQL*Plus
8. What kind of block is defined by the following PL/SQL code?
BEGIN
DBMS_OUTPUT.PUT_LINE('My first quiz');
END;
procedure
subroutine
function
anonymous (*)
9. Given below are the parts of a PL/SQL block:
1. END;
2. EXCEPTION
3. DECLARE
4. BEGIN
Arrange the parts in order.
2,1,4,3
3,4,2,1 (*)
3,2,4,1
4,3,2,1
10. Which lines of code will correctly display the message "The cat sat on the mat"? (Choose two.)
(Choose all correct answers)
DBMS_OUTPUT.PUT_LINE('The cat sat on the mat'); (*)
DBMS_OUTPUT.PUT_LINE(The cat sat on the mat);
DBMS_OUTPUT.PUT_LINE('The cat' || 'sat on the mat');
DBMS_OUTPUT.PUT_LINE('The cat sat ' || 'on the mat'); (*)
11. What is the purpose of using DBMS_OUTPUT.PUT_LINE in a PL/SQL block?
To perform conditional tests
To allow a set of statements to be executed repeatedly
To display results to check if our code is working correctly (*)
To store new rows in the database
12. Errors are handled in the Exception part of the PL/SQL block. True or False?
True (*)
False
13. Type of a variable determines the range of values the variable can have and the set of operations that are defined for values of the type.
True (*)
False
14. Which of these are PL/SQL data types? (Choose three.) (Choose all correct answers)
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
15. A movie is an example of which category of data type?
Scalar
Composite
Reference
LOB (*)
16. Which of the following are valid identifiers? (Choose two.) (Choose all correct answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
17. Which of the following are PL/SQL lexical units? (Choose two.) (Choose all correct answers)
Identifiers (*)
Table Columns
Reserved Words (*)
Anonymous Blocks
SQL Workshop
18. Delimiters are _____ that have special meaning to the Oracle database.
identifiers
variables
symbols (*)
19. When nested blocks are used, which blocks can or must be labeled?
The inner block must be labeled, the outer block can be labeled.
Both blocks must be labeled
Nested blocks cannot be labeled
The outer block must be labeled if it is to be referred to in the inner block. (*)
20. What will be displayed when the following block is executed?
<<outer>>
DECLARE
v_myvar VARCHAR2(10) := 'Hello' ;
BEGIN
<<inner>> DECLARE
v_myvar VARCHAR2(10) := 'World';
BEGIN
v_myvar := v_myvar || ' ' || outer.v_myvar;
END;
DBMS_OUTPUT.PUT_LINE(inner.v_myvar);
END;
HelloWorld
Hello World
World
The code will fail since the inner variable is not within the scope of the outer block. (*)
21. In the following code, Line A causes an exception. What value will be displayed when the code is executed?
DECLARE
outer_var VARCHAR2(50) := 'My';
BEGIN
outer_var := outer_var || ' name';
DECLARE
inner_var NUMBER;
BEGIN
inner_var := 'Mehmet'; -- Line A
outer_var := outer_var || ' is';
END;
outer_var := outer_var || ' Zeynep';
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(outer_var);
END;
My
My name (*)
My name is
My name is Zeynep
22. What will be displayed when the following code is executed?
DECLARE
x VARCHAR2(6) := 'Chang';
BEGIN
DECLARE
x VARCHAR2(12) := 'Susan';
BEGIN
x := x || x;
END;
DBMS_OUTPUT.PUT_LINE(x);
END;
Susan
Chang (*)
ChangChang
SusanChang
The code will fail with an error
23. Examine the following code. Line A causes an exception. What will be displayed when the block is executed?
DECLARE
var_a NUMBER := 6;
var_b DATE;
BEGIN
var_a := var_a * 2;
var_b := '28 December 2006'; -- Line A
var_a := var_a * 2;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(var_a);
END;
12 (*)
24
6
Nothing will be displayed
24. To comment a single line of code, use two dashes after the comment. True or False?
True
False (*)
25. Which of the following will help to make code easier to read?
Naming variables.
Using %Type.
Including comments in the code. (*)
26. Using standards for naming conventions is recommended. True or False?
True (*)
False
27. If today's date is 14th June 2007, which statement will correctly convert today's date to the value: June 14, 2007 ?
TO_CHAR(sysdate)
TO_DATE(sysdate)
TO_DATE(sysdate,'Month DD, YYYY')
TO_CHAR(sysdate, 'Month DD, YYYY') (*)
28. Examine the following code. What is the final value of V_MYBOOL ?
DECLARE
v_mynumber NUMBER;
v_mybool BOOLEAN ;
BEGIN
v_mynumber := 6;
v_mybool := (v_mynumber BETWEEN 10 AND 20);
v_mybool := NOT (v_mybool);
END;
True (*)
False
29. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
81
49
14 (*)
18
30. Single row character functions are valid SQL functions in PL/SQL. True or False?
True (*)
False
31. The implicit data type conversion at Point A may not work correctly. Why not?
DECLARE
v_mydate DATE;
BEGIN
V_MYDATE := '29-Feb-04'; -- Point A
END;
There are only 28 days in February
Oracle cannot implicitly convert a character string to a date, even if the string contains a valid date value
If the database language is not English, 'Feb' has no meaning. (*)
V_MYDATE has been entered in uppercase
32. Examine the following code:
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= '300';
5 END;
After line 4, what is the value of x?
'300'
300 (*)
NULL
33. When you use a function to convert data types in a PL/SQL program, it is called ______ conversion.
Explicit (*)
Implicit
TO_CHAR
34. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of:
Implicit conversion functions
Explicit conversion functions (*)
Character functions
Operators
35. Assignment statements can continue over several lines in PL/SQL. True or False?
True (*)
False
36. When a variable is defined using the NOT NULL keywords, the variable must contain a value. True or False?
True (*)
False
37. Evaluate the following declaration. Determine whether or not it is legal.
DECLARE
maxsalary NUMBER(7) = 5000;
Correct.
Not correct. (*)
38. Variables can be used in the following ways in a PL/SQL block. (Choose two.) (Choose all correct answers)
To store data values. (*)
To rename tables and columns.
To refer to a single data value several times. (*)
To comment code.
39. A variable must have a value if NOT NULL is specified. True or False?
True (*)
False
40. You need to declare a variable to hold a value which has been read from the SALARY column of the EMPLOYEES table. Which of the following is an advantage of declaring the variable as: employees.salary%TYPE ?
It is shorter than coding NUMBER(8,2)
If the SALARY column is ALTERed later, the PL/SQL code need not be changed. (*)
It executes much faster than using NUMBER(8,2)
It allows the software to perform implicit data type conversions.
41. Which of the following declarations is invalid?
v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):='Harvard';
v_pages CONSTANT NUMBER; (*)
v_start_date DATE := sysdate+1;
42. Given this first section of code:
DECLARE
v_result employees.salary%TYPE;
BEGIN
Which statement will always return exactly one value?
SELECT salary
INTO v_result
FROM employees;
SELECT salary
INTO v_result
FROM employees
WHERE last_name ='Smith';
SELECT salary
INTO v_result
FROM employees
WHERE department_id = 80;
SELECT SUM(salary)
INTO v_result
FROM employees; (*)
43. The following code will return the last name of the employee whose employee id is equal to 100: True or False?
DECLARE
v_last_name employees.last_name%TYPE;
employee_id employees.employee_id%TYPE := 100;
BEGIN
SELECT last_name INTO v_last_name
FROM employees
WHERE employee_id = employee_id;
END;
True
False (*)
44. Which one of these SQL statements can be directly included in a PL/SQL executable block?
SELECT last_name FROM employees
WHERE employee_id=100;
DESCRIBE employees;
UPDATE employees
SET last_name='Smith'; (*)
DROP TABLE employees;
45. Which of the following is NOT a good guideline for retrieving data in PL/SQL?
Declare the receiving variables using %TYPE
The WHERE clause is optional in nearly all cases. (*)
Specify the same number of variables in the INTO clause as database columns in the SELECT clause.
THE SELECT statement should fetch exactly one row.
46. The following anonymous block of code is run:
BEGIN
INSERT INTO countries (id, name)
VALUES ('XA', 'Xanadu');
SAVEPOINT XA;
INSERT INTO countries (id, name)
VALUES ('NV','Neverland');
COMMIT;
ROLLBACK TO XA;
END;
What happens when the block of code finishes?
No data is inserted and no errors occur.
No data is inserted and an error occurs
Two rows are inserted and no errors occur.
Two rows are inserted and an error occurs. (*)
47. The following anonymous block of code is run:
BEGIN
INSERT INTO countries (id, name)
VALUES ('XA', 'Xanadu');
INSERT INTO countries (id, name)
VALUES ('NV','Neverland');
COMMIT;
COMMIT;
ROLLBACK;
END;
What happens when the block of code finishes?
You have nothing new; the last ROLLBACK undid the INSERTs.
You have the rows added twice; there are four new rows.
You have the two new rows added. (*)
You get an error; you cannot COMMIT twice in a row.
48. Which SQL statement can NOT use an implicit cursor?
A DELETE statement
An UPDATE statement
A SELECT statement that returns multiple rows (*)
A SELECT statement that returns one row
49. A PL/SQL block includes the following statement:
SELECT last_name INTO v_last_name
FROM employees
WHERE employee_id=100;
What is the value of SQL%ISOPEN immediately after the SELECT statement is executed?
True
False (*)
Null
Error. That attribute does not apply for implicit cursors.
50. There are no employees in Department 77. What will happen when the following block is executed?
BEGIN
DELETE FROM employees
WHERE department_id=77;
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
END;
A NO_DATA_FOUND exception is raised.
A NULL is displayed.
A zero (0) is displayed. (*)
An exception is raised because the block does not contain a COMMIT statement.
PLSQL Semester 1 Mid Term Exam - Part I
1. PL/SQL is an Oracle proprietary, procedural, 4GL programming language. True or False?
True
False (*)
2. PL/SQL extends SQL by including all of the following except:
variables
conditional statements
reusable program units
constants
nonprocedural constructs (*)
3. Which of the following statements about PL/SQL and SQL is true?
PL/SQL and SQL are both ANSI-compliant.
PL/SQL and SQL can be used with many types of databases, including Oracle.
PL/SQL and SQL are both Oracle proprietary programming languages.
PL/SQL allows basic program logic and control flow to be combined with SQL statements. (*)
4. Using Oracle Application Express, you can create Web applications that include PL/SQL. True or False?
True (*)
False
5. The fact that PL/SQL is portable is a good thing because:
Exceptions can be ported to different operating systems
Blocks can be sent to the operating system.
PL/SQL code can be developed on one platform and deployed on another (*)
PL/SQL code can be run on any operating system without a database
6. Which of the following can you use PL/SQL to do?
Update data (DML)
Develop Web applications using the Web Application Toolkit
Manage database security
Create customized reports
All of the above (*)
7. Which of the following tools can NOT be used to develop and test PL/SQL code?
Oracle Jdeveloper
Oracle Application Express
Oracle JSQL (*)
Oracle iSQL*Plus
8. What kind of block is defined by the following PL/SQL code?
BEGIN
DBMS_OUTPUT.PUT_LINE('My first quiz');
END;
procedure
subroutine
function
anonymous (*)
9. Given below are the parts of a PL/SQL block:
1. END;
2. EXCEPTION
3. DECLARE
4. BEGIN
Arrange the parts in order.
2,1,4,3
3,4,2,1 (*)
3,2,4,1
4,3,2,1
10. Which lines of code will correctly display the message "The cat sat on the mat"? (Choose two.)
(Choose all correct answers)
DBMS_OUTPUT.PUT_LINE('The cat sat on the mat'); (*)
DBMS_OUTPUT.PUT_LINE(The cat sat on the mat);
DBMS_OUTPUT.PUT_LINE('The cat' || 'sat on the mat');
DBMS_OUTPUT.PUT_LINE('The cat sat ' || 'on the mat'); (*)
11. What is the purpose of using DBMS_OUTPUT.PUT_LINE in a PL/SQL block?
To perform conditional tests
To allow a set of statements to be executed repeatedly
To display results to check if our code is working correctly (*)
To store new rows in the database
12. Errors are handled in the Exception part of the PL/SQL block. True or False?
True (*)
False
13. Type of a variable determines the range of values the variable can have and the set of operations that are defined for values of the type.
True (*)
False
14. Which of these are PL/SQL data types? (Choose three.) (Choose all correct answers)
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
15. A movie is an example of which category of data type?
Scalar
Composite
Reference
LOB (*)
16. Which of the following are valid identifiers? (Choose two.) (Choose all correct answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
17. Which of the following are PL/SQL lexical units? (Choose two.) (Choose all correct answers)
Identifiers (*)
Table Columns
Reserved Words (*)
Anonymous Blocks
SQL Workshop
18. Delimiters are _____ that have special meaning to the Oracle database.
identifiers
variables
symbols (*)
19. When nested blocks are used, which blocks can or must be labeled?
The inner block must be labeled, the outer block can be labeled.
Both blocks must be labeled
Nested blocks cannot be labeled
The outer block must be labeled if it is to be referred to in the inner block. (*)
20. What will be displayed when the following block is executed?
<<outer>>
DECLARE
v_myvar VARCHAR2(10) := 'Hello' ;
BEGIN
<<inner>> DECLARE
v_myvar VARCHAR2(10) := 'World';
BEGIN
v_myvar := v_myvar || ' ' || outer.v_myvar;
END;
DBMS_OUTPUT.PUT_LINE(inner.v_myvar);
END;
HelloWorld
Hello World
World
The code will fail since the inner variable is not within the scope of the outer block. (*)
21. In the following code, Line A causes an exception. What value will be displayed when the code is executed?
DECLARE
outer_var VARCHAR2(50) := 'My';
BEGIN
outer_var := outer_var || ' name';
DECLARE
inner_var NUMBER;
BEGIN
inner_var := 'Mehmet'; -- Line A
outer_var := outer_var || ' is';
END;
outer_var := outer_var || ' Zeynep';
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(outer_var);
END;
My
My name (*)
My name is
My name is Zeynep
22. What will be displayed when the following code is executed?
DECLARE
x VARCHAR2(6) := 'Chang';
BEGIN
DECLARE
x VARCHAR2(12) := 'Susan';
BEGIN
x := x || x;
END;
DBMS_OUTPUT.PUT_LINE(x);
END;
Susan
Chang (*)
ChangChang
SusanChang
The code will fail with an error
23. Examine the following code. Line A causes an exception. What will be displayed when the block is executed?
DECLARE
var_a NUMBER := 6;
var_b DATE;
BEGIN
var_a := var_a * 2;
var_b := '28 December 2006'; -- Line A
var_a := var_a * 2;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(var_a);
END;
12 (*)
24
6
Nothing will be displayed
24. To comment a single line of code, use two dashes after the comment. True or False?
True
False (*)
25. Which of the following will help to make code easier to read?
Naming variables.
Using %Type.
Including comments in the code. (*)
26. Using standards for naming conventions is recommended. True or False?
True (*)
False
27. If today's date is 14th June 2007, which statement will correctly convert today's date to the value: June 14, 2007 ?
TO_CHAR(sysdate)
TO_DATE(sysdate)
TO_DATE(sysdate,'Month DD, YYYY')
TO_CHAR(sysdate, 'Month DD, YYYY') (*)
28. Examine the following code. What is the final value of V_MYBOOL ?
DECLARE
v_mynumber NUMBER;
v_mybool BOOLEAN ;
BEGIN
v_mynumber := 6;
v_mybool := (v_mynumber BETWEEN 10 AND 20);
v_mybool := NOT (v_mybool);
END;
True (*)
False
29. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
81
49
14 (*)
18
30. Single row character functions are valid SQL functions in PL/SQL. True or False?
True (*)
False
31. The implicit data type conversion at Point A may not work correctly. Why not?
DECLARE
v_mydate DATE;
BEGIN
V_MYDATE := '29-Feb-04'; -- Point A
END;
There are only 28 days in February
Oracle cannot implicitly convert a character string to a date, even if the string contains a valid date value
If the database language is not English, 'Feb' has no meaning. (*)
V_MYDATE has been entered in uppercase
32. Examine the following code:
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= '300';
5 END;
After line 4, what is the value of x?
'300'
300 (*)
NULL
33. When you use a function to convert data types in a PL/SQL program, it is called ______ conversion.
Explicit (*)
Implicit
TO_CHAR
34. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of:
Implicit conversion functions
Explicit conversion functions (*)
Character functions
Operators
35. Assignment statements can continue over several lines in PL/SQL. True or False?
True (*)
False
36. When a variable is defined using the NOT NULL keywords, the variable must contain a value. True or False?
True (*)
False
37. Evaluate the following declaration. Determine whether or not it is legal.
DECLARE
maxsalary NUMBER(7) = 5000;
Correct.
Not correct. (*)
38. Variables can be used in the following ways in a PL/SQL block. (Choose two.) (Choose all correct answers)
To store data values. (*)
To rename tables and columns.
To refer to a single data value several times. (*)
To comment code.
39. A variable must have a value if NOT NULL is specified. True or False?
True (*)
False
40. You need to declare a variable to hold a value which has been read from the SALARY column of the EMPLOYEES table. Which of the following is an advantage of declaring the variable as: employees.salary%TYPE ?
It is shorter than coding NUMBER(8,2)
If the SALARY column is ALTERed later, the PL/SQL code need not be changed. (*)
It executes much faster than using NUMBER(8,2)
It allows the software to perform implicit data type conversions.
PLSQL Semester 1 Mid Term Exam - Part I
1. PL/SQL is an Oracle proprietary, procedural, 4GL programming language. True or False?
True
False (*)
2. PL/SQL extends SQL by including all of the following except:
variables
conditional statements
reusable program units
constants
nonprocedural constructs (*)
3. Which of the following statements about PL/SQL and SQL is true?
PL/SQL and SQL are both ANSI-compliant.
PL/SQL and SQL can be used with many types of databases, including Oracle.
PL/SQL and SQL are both Oracle proprietary programming languages.
PL/SQL allows basic program logic and control flow to be combined with SQL statements. (*)
4. Using Oracle Application Express, you can create Web applications that include PL/SQL. True or False?
True (*)
False
5. The fact that PL/SQL is portable is a good thing because:
Exceptions can be ported to different operating systems
Blocks can be sent to the operating system.
PL/SQL code can be developed on one platform and deployed on another (*)
PL/SQL code can be run on any operating system without a database
6. Which of the following can you use PL/SQL to do?
Update data (DML)
Develop Web applications using the Web Application Toolkit
Manage database security
Create customized reports
All of the above (*)
7. Which of the following tools can NOT be used to develop and test PL/SQL code?
Oracle Jdeveloper
Oracle Application Express
Oracle JSQL (*)
Oracle iSQL*Plus
8. What kind of block is defined by the following PL/SQL code?
BEGIN
DBMS_OUTPUT.PUT_LINE('My first quiz');
END;
procedure
subroutine
function
anonymous (*)
9. Given below are the parts of a PL/SQL block:
1. END;
2. EXCEPTION
3. DECLARE
4. BEGIN
Arrange the parts in order.
2,1,4,3
3,4,2,1 (*)
3,2,4,1
4,3,2,1
10. Which lines of code will correctly display the message "The cat sat on the mat"? (Choose two.)
(Choose all correct answers)
DBMS_OUTPUT.PUT_LINE('The cat sat on the mat'); (*)
DBMS_OUTPUT.PUT_LINE(The cat sat on the mat);
DBMS_OUTPUT.PUT_LINE('The cat' || 'sat on the mat');
DBMS_OUTPUT.PUT_LINE('The cat sat ' || 'on the mat'); (*)
11. What is the purpose of using DBMS_OUTPUT.PUT_LINE in a PL/SQL block?
To perform conditional tests
To allow a set of statements to be executed repeatedly
To display results to check if our code is working correctly (*)
To store new rows in the database
12. Errors are handled in the Exception part of the PL/SQL block. True or False?
True (*)
False
13. Type of a variable determines the range of values the variable can have and the set of operations that are defined for values of the type.
True (*)
False
14. Which of these are PL/SQL data types? (Choose three.) (Choose all correct answers)
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
15. A movie is an example of which category of data type?
Scalar
Composite
Reference
LOB (*)
16. Which of the following are valid identifiers? (Choose two.) (Choose all correct answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
17. Which of the following are PL/SQL lexical units? (Choose two.) (Choose all correct answers)
Identifiers (*)
Table Columns
Reserved Words (*)
Anonymous Blocks
SQL Workshop
18. Delimiters are _____ that have special meaning to the Oracle database.
identifiers
variables
symbols (*)
19. When nested blocks are used, which blocks can or must be labeled?
The inner block must be labeled, the outer block can be labeled.
Both blocks must be labeled
Nested blocks cannot be labeled
The outer block must be labeled if it is to be referred to in the inner block. (*)
20. What will be displayed when the following block is executed?
<<outer>>
DECLARE
v_myvar VARCHAR2(10) := 'Hello' ;
BEGIN
<<inner>> DECLARE
v_myvar VARCHAR2(10) := 'World';
BEGIN
v_myvar := v_myvar || ' ' || outer.v_myvar;
END;
DBMS_OUTPUT.PUT_LINE(inner.v_myvar);
END;
HelloWorld
Hello World
World
The code will fail since the inner variable is not within the scope of the outer block. (*)
21. In the following code, Line A causes an exception. What value will be displayed when the code is executed?
DECLARE
outer_var VARCHAR2(50) := 'My';
BEGIN
outer_var := outer_var || ' name';
DECLARE
inner_var NUMBER;
BEGIN
inner_var := 'Mehmet'; -- Line A
outer_var := outer_var || ' is';
END;
outer_var := outer_var || ' Zeynep';
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(outer_var);
END;
My
My name (*)
My name is
My name is Zeynep
22. What will be displayed when the following code is executed?
DECLARE
x VARCHAR2(6) := 'Chang';
BEGIN
DECLARE
x VARCHAR2(12) := 'Susan';
BEGIN
x := x || x;
END;
DBMS_OUTPUT.PUT_LINE(x);
END;
Susan
Chang (*)
ChangChang
SusanChang
The code will fail with an error
23. Examine the following code. Line A causes an exception. What will be displayed when the block is executed?
DECLARE
var_a NUMBER := 6;
var_b DATE;
BEGIN
var_a := var_a * 2;
var_b := '28 December 2006'; -- Line A
var_a := var_a * 2;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(var_a);
END;
12 (*)
24
6
Nothing will be displayed
24. To comment a single line of code, use two dashes after the comment. True or False?
True
False (*)
25. Which of the following will help to make code easier to read?
Naming variables.
Using %Type.
Including comments in the code. (*)
26. Using standards for naming conventions is recommended. True or False?
True (*)
False
27. If today's date is 14th June 2007, which statement will correctly convert today's date to the value: June 14, 2007 ?
TO_CHAR(sysdate)
TO_DATE(sysdate)
TO_DATE(sysdate,'Month DD, YYYY')
TO_CHAR(sysdate, 'Month DD, YYYY') (*)
28. Examine the following code. What is the final value of V_MYBOOL ?
DECLARE
v_mynumber NUMBER;
v_mybool BOOLEAN ;
BEGIN
v_mynumber := 6;
v_mybool := (v_mynumber BETWEEN 10 AND 20);
v_mybool := NOT (v_mybool);
END;
True (*)
False
29. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
81
49
14 (*)
18
30. Single row character functions are valid SQL functions in PL/SQL. True or False?
True (*)
False
31. The implicit data type conversion at Point A may not work correctly. Why not?
DECLARE
v_mydate DATE;
BEGIN
V_MYDATE := '29-Feb-04'; -- Point A
END;
There are only 28 days in February
Oracle cannot implicitly convert a character string to a date, even if the string contains a valid date value
If the database language is not English, 'Feb' has no meaning. (*)
V_MYDATE has been entered in uppercase
32. Examine the following code:
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= '300';
5 END;
After line 4, what is the value of x?
'300'
300 (*)
NULL
33. When you use a function to convert data types in a PL/SQL program, it is called ______ conversion.
Explicit (*)
Implicit
TO_CHAR
34. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of:
Implicit conversion functions
Explicit conversion functions (*)
Character functions
Operators
35. Assignment statements can continue over several lines in PL/SQL. True or False?
True (*)
False
36. When a variable is defined using the NOT NULL keywords, the variable must contain a value. True or False?
True (*)
False
37. Evaluate the following declaration. Determine whether or not it is legal.
DECLARE
maxsalary NUMBER(7) = 5000;
Correct.
Not correct. (*)
38. Variables can be used in the following ways in a PL/SQL block. (Choose two.) (Choose all correct answers)
To store data values. (*)
To rename tables and columns.
To refer to a single data value several times. (*)
To comment code.
39. A variable must have a value if NOT NULL is specified. True or False?
True (*)
False
40. You need to declare a variable to hold a value which has been read from the SALARY column of the EMPLOYEES table. Which of the following is an advantage of declaring the variable as: employees.salary%TYPE ?
It is shorter than coding NUMBER(8,2)
If the SALARY column is ALTERed later, the PL/SQL code need not be changed. (*)
It executes much faster than using NUMBER(8,2)
It allows the software to perform implicit data type conversions.
PLSQL Mid Term Exam Semester 1 - Part II
1. For which type of SQL statement must you use an explicit cursor?
DML statements that process more than one row.
Queries that return more than one row. (*)
Data Definition Language (DDL) statements.
Queries that return a single row.
2. After a cursor has been closed, it can be opened again in the same PL/SQL block. True or False?
True (*)
False
3. Which of these is NOT a valid cursor declaration?
CURSOR emp_curs IS
SELECT salary
FROM employees
ORDER BY salary DESC;
CURSOR emp_curs IS
SELECT salary
FROM employees
WHERE last_name LIKE 'S%';
CURSOR emp_dept_curs IS
SELECT e.salary, d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id;
CURSOR emp_curs IS
SELECT salary INTO v_salary
FROM employees; (*)
4. Which of these constructs can be used to fetch multiple rows from a cursor's active set?
A CASE statement
An IF .... ELSE statement
A basic loop which includes FETCH and EXIT WHEN statements (*)
A basic loop which includes OPEN, FETCH and CLOSE statements
5. The employees table contains 20 rows. What will happen when the following code is executed?
DECLARE
 CURSOR emp_curs IS
 SELECT job_id FROM employees;
v_job_id employees.job_id%TYPE;
BEGIN
OPEN emp_curs;
LOOP
FETCH emp_curs INTO v_job_id;
DBMS_OUTPUT.PUT_LINE(v_job_id);
EXIT WHEN emp_curs%NOTFOUND;
END LOOP;
CLOSE emp_curs;
END;
20 job_ids will be displayed.
The block will fail and an error message will be displayed.
21 rows of output will be displayed; the first job_id will be displayed twice.
21 rows of output will be displayed; the last job_id will be displayed twice. (*)
6. Which of these statements about implicit cursors is NOT true?
They are declared automatically by Oracle for single-row SELECT statements.
They are declared automatically by Oracle for all DML statements.
They are declared by the PL/SQL programmer. (*)
They are opened and closed automatically by Oracle.
7. What will happen when the following code is executed?
DECLARE
CURSOR emp_curs IS
SELECT salary FROM employees;
v_salary employees.salary%TYPE;
BEGIN
FETCH emp_curs INTO v_salary;
DBMS_OUTPUT.PUT_LINE(v_salary);
CLOSE emp_curs;
END;
The first employee's salary will be fetched and displayed.
All employees' salaries will be fetched and displayed.
The execution will fail and an error message will be displayed. (*)
The lowest salary value will be fetched and displayed.
8. What will happen when the following code is executed?
DECLARE CURSOR emp_curs IS
SELECT salary FROM employees;
v_salary employees.salary%TYPE;
BEGIN
OPEN emp_curs;
FETCH emp_curs INTO v_salary;
CLOSE emp_curs;
FETCH emp_curs INTO v_salary;
END;
The block will fail and an INVALID_CURSOR exception will be raised. (*)
The first employee row will be fetched twice.
The first two employee rows will be fetched.
The block will fail and a TOO_MANY_ROWS exception will be raised.
9. In the following code fragment, you want to exit from the outer loop at Line A if v_number = 6. Which statement would you write on Line A?
<<big_loop>>
WHILE condition_1 LOOP
<<small_loop>>
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE(i);
--Line A
END LOOP;
END LOOP;
IF v_number = 6 THEN EXIT;
EXIT outer_loop WHEN v_number = 6;
EXIT big_loop WHEN v_number = 6; (*)
EXIT small_loop WHEN v_number = 6;
Incorrect. Refer to Section 4.
10. You want to display multiplication tables for numbers up to 12. The display
should look like this:
1 x 1 = 1
1 x 2 = 2
.....
1 x 12 = 12
2 x 1 = 2
2 x 2 = 4
.....
2 x 12 = 24
3 x 1 = 3
.....
.....
12 x 12 = 144
Which of the following is an efficient way to do this in PL/SQL?
Use two nested FOR loops. (*)
Store all the numbers from 1 to 144 in a table, then fetch and display them using a cursor.
Create a function which accepts two numbers as IN parameters and returns their product.
Invoke the function 144 times.
Write an anonymous block which contains 144 calls to DBMS_OUTPUT, each looking like: DBMS_OUTPUT.PUT_LINE('7 x 9 = 63');
11. Examine the following code fragment:
DECLARE
CURSOR emp_curs IS
SELECT first_name, last_name FROM employees;
v_emp_rec emp_curs%ROWTYPE;
BEGIN
...
FETCH emp_curs INTO v_emp_rec;
DBMS_OUTPUT.PUT_LINE(... Point A ...);
 ...
To display the fetched last name, what should you code at Point A?
v_emp_rec.last_name (*)
v_emp_rec(last_name)
v_emp_rec
last_name
None of the above
12. Assume that you have declared a cursor called C_EMP. Which of the following
statements about C_EMP is correct? (Choose two.) (Choose all correct answers)
You can use c_emp%NOTFOUND to exit a loop. (*)
You can fetch rows when c_emp%ISOPEN evaluates to FALSE.
You can use c_emp%ROWCOUNT to return the number of rows returned by the cursor so far. (*)
You can use c_emp%FOUND after the cursor is closed.
13. The following cursor has been declared:
CURSOR emp_curs IS
SELECT first_name, last_name, job_id, salary
FROM employees;
Which of the following correctly declares a composite record with the same structure as the cursor?
emp_rec emp_rec%ROWTYPE;
emp_rec emp_curs%TYPE;
emp_rec emp_curs%ROWTYPE; (*)
emp_rec cursor%ROWTYPE;
14. Which of the following cursor attributes evaluates to TRUE if the cursor is open?
%ISOPEN (*)
%NOTFOUND
%FOUND
%ROWCOUNT
15. Which of the following cursor attributes is set to the total number of rows returned so far?
%ISOPEN
%NOTFOUND
%FOUND
%ROWCOUNT (*)
16. The employees table contains 11 columns. The following block declares a cursor and a record based on the cursor:
DECLARE
CURSOR emp_curs IS
SELECT * FROM employees;
v_emp_rec emp_curs%ROWTYPE;
A twelfth column is now added to the employees table. Which of the following statements is true?
The declaration of emp_rec must be changed to add an extra field.
The block will still work correctly without any changes to the PL/SQL code. (*)
The block will fail and an INVALID_CURSOR exception will be raised.
An extra scalar variable must be declared to correspond to the twelfth table column.
17. The following code fragment shows a cursor FOR loop:
FOR emp_record IN emp_cursor LOOP ......
Which of the following do NOT need to be coded explicitly? (Choose three.) (Choose all correct answers)
OPEN emp_cursor; (*)
DECLARE CURSOR emp_cursor IS ... emp_record emp_cursor%ROWTYPE; (*)
FETCH emp_cursor INTO emp_record; (*)
END LOOP;
18. What is wrong with the following code?
DECLARE
CURSOR dept_curs IS SELECT * FROM departments;
BEGIN
FOR dept_rec IN dept_curs LOOP
DBMS_OUTPUT.PUT_LINE(dept_curs%ROWCOUNT || dept_rec.department_name);
END LOOP;
DBMS_OUTPUT.PUT_LINE(dept_rec.department_id);
END;
The cursor DEPT_CURS has not been opened.
The implicitly declared record DEPT_REC cannot be referenced outside the cursor FOR loop. (*)
You cannot use %ROWCOUNT with a cursor FOR loop.
The cursor DEPT_CURS has not been closed.
Nothing is wrong, this code will execute successfully.
19. When using a cursor FOR loop, OPEN, CLOSE and FETCH statements should not be explicitly coded. True or False?
True (*)
False
20. Examine the following declaration of a cursor with a parameter. What should be coded at Point A? DECLARE
CURSOR emp_curs(--Point A --) IS
SELECT * FROM employees
WHERE job_id = p_job_id;
p_job_id
ST_CLERK'
p_job_id VARCHAR2(25)
p_job_id VARCHAR2 (*)
job_id VARCHAR2
21. A cursor has been declared as:
CURSOR c_curs (p_param VARCHAR2) IS
SELECT * FROM mytable
WHERE mycolumn = p_param.
Which of the following will open the cursor successfully?
OPEN c_curs(p_param = 'ABC');
OPEN c_curs('ABC'); (*)
OPEN c_curs USING ('ABC');
p_param := 'ABC';
OPEN c_curs(p_param);
22. A PL/SQL block contains the following code:
v_counter := 1;
LOOP
EXIT WHEN v_counter=5;
END LOOP;
v_counter := v_counter + 1;
What is the value of V_COUNTER after the loop is finished?
5
6
1
This is an infinite loop; the loop will never finish. (*)
23. Which one of these is NOT a kind of loop?
ASCENDING loop (*)
FOR loop
Basic loop
WHILE loop
24. Which one of these tasks is best done using a LOOP statement?
Assigning a letter grade to a numerical score
Calculating and displaying the sum of all integers from 1 to 100 (*)
Testing if a condition is true, false or null
Fetching and displaying an employee's last name from the database
25. The EXIT statement can be located anywhere inside a basic loop. True or False?
True (*)
False
26. A PL/SQL block contains the following code:
v_counter := 1;
LOOP
EXIT WHEN v_counter = 5;
v_counter := v_counter + 1;
END LOOP;
What is the value of V_COUNTER after the loop is finished?
5 (*)
6
1
This is an infinite loop; the loop will never finish.
27. What will be the value of v_sal_desc after the following code is executed?
DECLARE
v_salary NUMBER(6,2) := NULL;
v_sal_desc VARCHAR2(10);
v_salary NUMBER(6,2) := NULL;
v_sal_desc VARCHAR2(10);
BEGIN
CASE
WHEN v_salary < 10000 THEN v_sal_desc := 'Low Paid';
WHEN v_salary >= 10000 THEN v_sal_desc := 'High Paid';
END CASE;
END;
High Paid
Low Paid
Null
The code will fail and return an exception (*)
28. You want to display a message which depends on the value of v_grade: if
v_grade = 'A' display 'Very Good', if v_grade = 'B' then display 'Good', and so on.
DECLARE
v_grade CHAR(1);
BEGIN
CASE v_grade
The next line should be
WHEN 'A' THEN (*)
WHEN v_grade = 'A' THEN
WHEN 'A' THEN;
IF 'A' THEN
29. What will be the value of v_result after the following code is executed?
DECLARE
v_grade CHAR(1) := NULL;
v_result VARCHAR2(10);
BEGIN
CASE v_grade
WHEN 'A' THEN v_result := 'Very Good';
WHEN 'F' THEN v_result := 'Poor';
ELSE v_result := 'In Between';
END;
END;
Poor
In Between (*)
Null
Very Good
30. What value will v_answer contain after the following code is executed?
DECLARE
v_age NUMBER:= 18;
v_answer VARCHAR2(10);
BEGIN
v_answer :=
CASE
WHEN v_age < 25 THEN 'Young'
WHEN v_age = 18 THEN 'Exactly 18'
ELSE 'Older'
END CASE;
END;
Exactly 18
Young (*)
Null
Older
31. You want to assign a value to v_result which depends on the value of v_grade: if v_grade
= 'A' set v_result to 'Very Good' and so on.
DECLARE
v_grade CHAR(1);
v_result VARCHAR2(10);
v_grade CHAR(1);
v_result VARCHAR2(10);
BEGIN
v_result := CASE v_grade
The next line should be
WHEN v_grade = 'A' THEN 'Very Good'
WHEN 'A' THEN 'Very Good';
WHEN 'A' THEN v_result := 'Very Good';
WHEN 'A' THEN 'Very Good' (*)
32. You want to declare a cursor which locks each row fetched by the cursor.
Examine the following code:
DECLARE
CURSOR emp_curs IS
SELECT * FROM employees
FOR --Point A
Which of the following can NOT be coded at Point A?
UPDATE;
UPDATE OF salary;
UPDATE OF employees; (*)
UPDATE NOWAIT;
33. User TOM has locked a row in the WORKERS table. Now, user DICK wants to open the following cursor:
CURSOR c IS
SELECT * FROM workers FOR UPDATE NOWAIT;
What will happen when DICK opens the cursor and tries to fetch rows?
TOM's session is rolled back. DICK's session successfully fetches rows from the cursor.
DICK's session waits indefinitely.
Both sessions wait for a few seconds; then the system breaks all locks and both sessions raise an exception.
DICK's session immediately raises an exception. (*)
The c%NOWAIT attribute is set to TRUE.
34. Consider the following cursor:
CURSOR c IS
SELECT e.last_name, e.salary, d.department_name
FROM employees e JOIN departments d
USING(department_id)
WHERE e.last_name='Smith'
FOR UPDATE;
When the cursor is opened and rows are fetched, what is locked?
The whole EMPLOYEES table is locked.
In the EMPLOYEES table, only the 'Smith' rows are locked. Nothing in the
DEPARTMENTS table is locked.
Each 'Smith' row is locked and Smith's matching rows in DEPARTMENTS are locked.
No other rows are locked in either table. (*)
The whole EMPLOYEES and DEPARTMENTS tables are locked.
Nothing is locked because the cursor was not declared with NOWAIT.
35. Which statement best describes when a FOR loop should be used?
When the number of iterations is known (*)
When testing the value in a Boolean variable
When the controlling condition must be evaluated at the start of each iteration
36. Which statement best describes when a WHILE loop shouild be used?
When the number of iterations is known
When repeating a sequence of statements until the controlling condition is no longer true (*)
When assigning a value to a Boolean variable
When testing whether a variable is null
37. Which of the following blocks produces the same output as this block?
BEGIN
FOR i in 1 .. 3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
DECLARE
i PLS_INTEGER := 0;
BEGIN
WHILE i<3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i + 1;
END LOOP;
END;
DECLARE
i PLS_INTEGER := 0;
BEGIN
WHILE i<3 LOOP
i := i + 1;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END; (*)
DECLARE
i PLS_INTEGER := 0;
BEGIN
WHILE i<3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
i := i+ 1;
END;
38. Examine the following code:
DECLARE
v_bool BOOLEAN := FALSE;
v_counter NUMBER(4) := 0;
BEGIN
... Line A
END;
Which of the following is NOT valid at line A?
WHILE NOT v_boolean LOOP
WHILE v_boolean AND v_counter < 6 LOOP
WHILE v_counter > 8 LOOP
WHILE v_counter IN 1..5 LOOP (*)
39. In a FOR loop, an implicitly declared counter automatically increases or decreases with each iteration. True or False?
True (*)
False
40. In a WHILE loop, the statements inside the loop must execute at least once. True or False?
True
False (*)
41. What is the correct form of a simple IF statement?
IF condition THEN statement;
END IF; (*)
IF condition;
THEN statement;
END IF;
IF condition
THEN statement
ENDIF;
42. You need to execute a set of statements 10 times, increasing a counter by 1 each
time. Which of the following PL/SQL constructs can do this? (Choose three) (Choose all correct answers)
IF ... THEN ... ELSE
A WHILE loop (*)
CASE ... WHEN ... THEN
A FOR loop (*)
A basic loop (*)
43. Examine the following code:
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := FALSE;
c BOOLEAN := TRUE;
d BOOLEAN := FALSE;
game char(4) := 'lost';
BEGIN
IF ((a AND b) AND (c OR d))
THEN game := 'won';
END IF;
What is the value of GAME at the end of this block?
NULL
won'
lost' (*)
False
44. What is the correct form of a compound IF statement?
IF condition
THEN statement1
ELSE statement 2;
IF condition
THEN statement1
ELSE statement 2;
END IF;
IF condition;
THEN statement1;
ELSE statement2;
END IF;
IF condition THEN statement1;
ELSE statement2;
END IF; (*)
45. You want to display all locations, and the departments in each location. Examine the following code:
DECLARE
CURSOR loc_curs IS SELECT * FROM locations;
CURSOR dept_curs(p_loc_id NUMBER) IS
SELECT * FROM departments WHERE location_id = p_loc_id;
BEGIN
FOR loc_rec IN loc_curs LOOP
DBMS_OUTPUT.PUT_LINE(loc_rec.city);
FOR dept_rec IN dept_curs(--Point A --) LOOP
DBMS_OUTPUT.PUT_LINE(dept_rec.department_name);
END LOOP;
END LOOP;
END;
What should you code at Point A?
p_loc_id
location_id
null
LOOP ... END LOOP;
loc_rec.location_id (*)
46. Which of the following is a good reason to declare and use multiple cursors in a single PL/SQL block?
Multiple cursors improve performance. They are faster than using a single cursor.
Multiple cursors use less memory than a single cursor.
Multiple cursors allow us to fetch rows from two or more related tables without using a
JOIN. (*)
Multiple cursors are the only way to use cursors with parameters.
Multiple cursors can be opened many times, while a single cursor can be opened only once.
47. When using multiple nested cursors, what kinds of loops can you use?
Cursor FOR loops only.
Basic loops only.
WHILE loops only.
None of the above.
All of the above. (*)
PLSQL Mid Term Exam Semester 2
1. Which of the following statements about packages is NOT true ?
All procedures and functions must be declared in the specification. (*)
Cursors can be declared in the specification.
The body contains the detailed code of the subprograms.
Variables can be declared in the body.
The specification must be created before the body.
2. The following package specification has been created:
CREATE OR REPLACE PACKAGE mypack IS
FUNCTION myfunc(p_funcparam DATE) RETURN BOOLEAN;
PROCEDURE myproc(p_procparam IN NUMBER);
END mypack;
Which of the following will correctly invoke the package subprograms? (Choose two.) (Choose all correct answers)
mypack.myfunc('22-JAN-07');
mypack.myproc(35);(*)
IF NOT mypack.myfunc(SYSDATE) THEN DBMS_OUTPUT.PUT_LINE('Message');
END IF; (*)
myproc(40);
v_num := mypack.myproc(22);
3. Which one of the following can NOT be part of a Package ?
Procedures
Explicit cursors
Triggers (*)
Functions
Global variables
4. What is wrong with the following syntax for creating a package specification?
CREATE OR REPLACE PACKAGE mypack IS
g_constant1 NUMBER(6) := 100;
FUNCTION func1 (p_param1 IN VARCHAR2);
FUNCTION func2;
END mypack;
You cannot declare constants in the specification.
A package must contain at least one procedure.
The RETURN datatype of the functions must be specified.(*)
The first line should be: CREATE OR REPLACE PACKAGE SPECIFICATION mypack IS
Nothing is wrong, this code contains no errors.
5. Which of the following statements about a package initialization block is true?
It cannot contain any SQL statements.
It is an anonymous block at the end of a package body. (*)
It is a procedure in a package that must be invoked before the rest of the package can be used.
It is an anonymous block in the package specification.
It is executed automatically every time any global variable in the package is referenced.
6. Package HRPACK contains the following public function:
FUNCTION empfunc (p_deptno NUMBER) RETURN NUMBER IS
BEGIN
UPDATE employees SET salary = salary * 1.1
WHERE department_id = p_deptno;
RETURN SQL%ROWCOUNT;
END empfunc;
What will happen when the following SQL statement is executed?
SELECT department_name, hrpack.empfunc(department_id)
FROM departments;
The SELECT will fail because you cannot return SQL%ROWCOUNT from a packaged function.
The SELECT will fail because you cannot call packaged functions from within a SQL statement.
The SELECT will fail because you cannot execute a DML statement from within a query.
The SELECT will succeed because it is referencing a different table from the function. (*)
7. Package TAXPACK declares a global variable G_TAXRATE NUMBER(2,2) . The value of the tax rate is stored in table TAXTAB in the database. You want to read this value automatically into G_TAXRATE each time a user session makes its first call to TAXPACK. How would you do this?
Declare the global variable as:
g_taxrate NUMBER(2,2) := SELECT tax_rate FROM taxtab;
Create a database trigger that includes the following code:
SELECT tax_rate INTO taxpack.g_taxrate FROM taxtab;
Add a private function to the package body of TAXPACK, and invoke the
function from the user session.
Add a package initialization block to the package body of TAXPACK. (*)
8. We never need to use a forward declaration when invoking a public subprogram. True or False?
True (*)
False
9. We need to declare a package variable named MYVAR, which can be referenced by any subprogram in the package but can NOT be referenced from outside the package. In the following code, where should MYVAR be declared?
CREATE OR REPLACE PACKAGE varpack IS
-- Point A
...
END varpack;
CREATE OR REPLACE PACKAGE BODY varpack IS
-- Point B
PROCEDURE varproc IS
-- Point C
BEGIN
...
END varproc;
PROCEDURE ...
...
-- Point D
END varpack;
Point A
Point B (*)
Point C
Point D
Point B or Point C, they will both work
10. In a package, public components are declared in the specification but private components are not. True or False?
True (*)
False
11. We want to remove the specification (but not the body) of package BIGPACK from the database. Which of the following commands will do this ?
DROP PACKAGE bigpack;
DROP PACKAGE SPECIFICATION bigpack;
DROP PACKAGE bigpack SPECIFICATION;
DROP PACKAGE HEADER bigpack;
None of the above (*)
12. Which of the following will display the detailed code of the subprograms in package DEPTPACK in your schema ?
SELECT text FROM USER_SOURCE
WHERE name = 'DEPTPACK'
AND type = 'PACKAGE'
ORDER BY line;
SELECT text FROM USER_SOURCE
WHERE name = 'DEPTPACK'
AND type = 'PACKAGE BODY'
ORDER BY line; (*)
SELECT text FROM USER_SOURCE
WHERE object_name = 'DEPTPACK'
AND object_type = 'PACKAGE BODY'
ORDER BY line;
SELECT text FROM USER_SOURCE
WHERE name = 'DEPTPACK'
AND type = 'BODY'
ORDER BY line;
13. Package OLDPACK is in your schema. What will happen when the following statement is executed?
DROP PACKAGE oldpack;
The body will be dropped but the specification will be retained.
The specification will be dropped but the body will be retained.
Both the specification and the body will be dropped. (*)
The statement will fail because you must drop the body before you can drop the specification.
14. Examine the following package specification:
CREATE OR REPLACE PACKAGE taxpack IS
CURSOR empcurs IS SELECT * FROM employees;
PROCEDURE taxproc;
END mypack;
The package body of TAXPACK also includes a function called TAXFUNC.
Which one of the following statements is NOT true?
The procedure can be invoked by:
BEGIN
taxpack.taxproc;
END;
The package will not compile because you cannot declare a cursor in the specification. (*)
TAXPROC is a public procedure and TAXFUNC is a private function
TAXPROC can invoke TAXFUNC if TAXPROC is coded before TAXFUNC
TAXPROC can open the cursor
15. Package NEWPACK contains several procedures and functions, inc
luding private function PRIVFUNC. From where can PRIVFUNC be invoked? (Choose two.)
(Choose all correct answers)
From an anonymous block
From any procedure in NEWPACK (*)
From any private function in another package
From any function in NEWPACK (*)
From any public procedure in another package
16. The DBMS_OUTPUT.PUT procedure places text in a buffer but does not display the contents of the buffer. True or False?
True (*)
False
17. Which of the following best describes the purpose of the UTL_FILE package?
It is used to load binary files such as employees' photos into the database.
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 query CHAR and VARCHAR2 columns in tables.
18. Why is it better to use DBMS_OUTPUT only in anonymous blocks, not inside stored subprograms such as procedures?
Because DBMS_OUTPUT cannot be used inside procedures
Because anonymous blocks display messages while the block is executing, while procedures do not display anything until their execution has finished
Because DBMS_OUTPUT should be used only for testing and debugging PL/SQL code (*)
Because DBMS_OUTPUT can raise a NO_DATA_FOUND exception if used inside a packaged procedure
19. The UTL_FILE package can be used to create binary files such as JPEG s as well as text files. True or False?
True
False (*)
20. You want to create a function which drops a table. You write the following code:
CREATE OR REPLACE FUNCTION droptab
(p_tab_name IN VARCHAR2)
RETURN BOOLEAN IS
BEGIN
DROP TABLE p_tab_name;
RETURN TRUE;
EXCEPTION
WHEN OTHERS THEN RETURN FALSE;
END;
Why will this procedure not compile successfully?
Because you can never drop a table from inside a function
Because the PL/SQL compiler cannot check if the argument of p_tab_name is a valid table-name (*)
Because you do not have the privilege needed to drop a table
Because you cannot use RETURN in the exception section
21. MARY wants HENRY to be able to query her EMPLOYEES table. Mary executes the following code:
DECLARE
v_grant_stmt VARCHAR2(50);
BEGIN
v_grant_stmt := 'GRANT SELECT ON employees TO henry';
DBMS_SQL.EXECUTE(v_grant_stmt);
END;
Mary has successfully granted the privilege to Henry. True or False?
True
False (*)
22. Examine the following code:
CREATE OR REPLACE PROCEDURE myproc IS
CURSOR c_curs IS SELECT view_name FROM user_views;
BEGIN
FOR v_curs_rec IN c_curs LOOP
EXECUTE IMMEDIATE 'DROP VIEW ' || v_curs_rec.view_name;
END LOOP;
END;
What will happen when this procedure is invoked?
All views in the user's schema will be dropped. (*)
The procedure will not compile successfully because the syntax of EXECUTE IMMEDIATE is incorrect.
The procedure will raise an exception because Dynamic SQL can drop tables but cannot drop views.
The procedure will raise an exception because one of the views is a complex view.
23. The easiest way to include DDL statements in a PL/SQL block is touse the DBMS_SQL package. True or False?
True
False (*)
24. Package MULTIPACK declares the following global variable:
g_myvar NUMBER;
User DICK executes the following:
multipack.g_myvar := 45;
User HAZEL now connects to the database. Both users immediately execute:
BEGIN
DBMS_OUTPUT.PUT_LINE(multipack.g_myvar);
END;
What values will Dick and Hazel see?
Dick: 45, Hazel: 45
Dick: 45, Hazel: 0
Dick: 45, Hazel: null (*)
Dick: 0, Hazel: 0
Both queries will fail because the syntax of DBMS_OUTPUT.PUT_LINE is incorrect
25. When a user session changes the value of a package variable, the new value can immediately be seen by other sessions. True or False?
True
False (*)
26. In the following code:
CREATE TRIGGER mytrigg
INSTEAD OF INSERT OR UPDATE ON my_object_name
FOR EACH ROW
BEGIN ...
my_object_name can be the name of a table. True or False?
True
False (*)
27. INSTEAD OF triggers are always row triggers, even if FOR EACH RO
W is omitted. True or False?
True (*)
False
28. Which of the following can NOT be coded in the body of a DML trig
ger? (Choose two.) (Choose all correct answers)
IF DELETING THEN
IF SELECTING THEN (*)
IF INSERTING THEN
IF UPDATING ('JOB_ID') THEN
IF OTHERS THEN (*)
29. With which kind of trigger can the :OLD and :NEW qualifiers be used?
DDL triggers
Database Event triggers
Statement triggers
Row triggers (*)
AFTER triggers
30. MARY and JOE's schemas each contain an EMPLOYEES table. JOE creates the following trigger:
CREATE TRIGGER upd_trigg
AFTER DELETE ON joe.employees
FOR EACH ROW
BEGIN
DELETE FROM mary.employees
WHERE employee_id = :OLD.employee_id;
END;
A third user TOM needs to delete rows from JOE's EMPLOYEES table. What object privileges will TOM and JOE need?
TOM does not need any object privileges, but JOE needs DELETE on both TOM.EMPLOYEES and MARY.EMPLOYEES
TOM needs DELETE on JOE.EMPLOYEES and JOE needs DELETE on MARY.EMPLOYEES (*)
JOE does not need any object privileges, but TOM needs DELETE on MARY.EMPLOYEES
TOM needs DELETE on MARY.EMPLOYEES and JOE needs EXECUTE on TOM.UPD_TRIGG
31. You need to disable all triggers that are associated with DML statements on the DEPARTMENTS table. Which of the following commands should you use?
ALTER TABLE departments DISABLE ALL TRIGGERS; (*)
ALTER TRIGGER DISABLE ALL ON departments;
ALTER TABLE departments DISABLE TRIGGERS;
DISABLE ALL TRIGGERS ON departments;
ALTER TABLE departments DROP ALL TRIGGERS;
32. User AYSEGUL successfully creates the following trigger:
CREATE TRIGGER loc_trigg
BEFORE UPDATE ON aysegul.locations
BEGIN ....
AYSEGUL now tries to drop the LOCATIONS table. What happens?
An error message is displayed because you cannot drop a table that is associated with a trigger.
The table is dropped and the trigger is disabled.
The trigger is dropped but the table is not dropped.
Both the table and the trigger are dropped. (*)
None of the above.
33. The database administrator wants to write a log record every time an Oracle Server error occurs in any user's session. The DBA creates the following trigger:
CREATE TRIGGER log_errs_trigg
-- Line A
BEGIN
INSERT INTO errlog_table VALUES (...);
END;
What should the DBA code at Line A ?
AFTER ERROR ON DATABASE
AFTER SERVER ERROR ON DATABASE
AFTER SERVERERROR ON SCHEMA
AFTER SERVERERROR ON DATABASE (*)
AFTER ORACLE ERROR ON SCHEMA
34. You want to prevent any objects in your schema from being altered or dropped. You decide to create the following trigger:
CREATE TRIGGER stop_ad_trigg
-- Line A
BEGIN
RAISE_APPLICATION_ERROR(-20203,'Invalid Operation');
END;
What should you code at Line A ?
AFTER ALTER OR DROP ON SCHEMA
INSTEAD OF ALTER OR DROP ON SCHEMA
BEFORE ALTER OR DROP ON SCHEMA (*)
BEFORE ALTER, DROP ON SCHEMA
AFTER ALTER, DROP ON SCHEMA
35. Examine this code:
CREATE TRIGGER de_trigg
-- Line A
BEGIN ...
Which of the following are NOT valid at Line A ? (Choose two.) (Choose all correct answers)
AFTER LOGOFF ON SCHEMA (*)
AFTER LOGON ON SCHEMA
BEFORE LOGOFF ON SCHEMA
BEFORE DISCONNECT ON SCHEMA (*)
AFTER SERVERERROR ON SCHEMA
36. Which of the following statements could cause a DDL trigger to fire?
DROP TABLE employees;
ALTER TABLE departments ADD (budget NUMBER(8,2));
CREATE TABLE newemp AS SELECT * FROM employees;
TRUNCATE TABLE locations;
All of the above (*)
37. Examine this code:
CREATE TRIGGER new_trigg
AFTER CREATE ON reserved_word
BEGIN ...
Which of the following can be used in place of reserved_word? (Choose two.) (Choose all correct answers)
TABLE
SCHEMA (*)
USER
DATABASE (*)
TABLE employees
38. Which kinds of trigger can cause a mutating table problem? (Choose two.) (Choose all correct answers)
BEFORE UPDATE row triggers (*)
DDL triggers
AFTER DELETE row triggers (*)
Database Event triggers
INSTEAD OF triggers
39. Examine the following code:
CREATE TRIGGER emp_trigg
AFTER UPDATE OF salary ON employees
FOR EACH ROW
DECLARE
v_count NUMBER;
BEGIN
-- Line A
END;
Which of the following statements is NOT allowed at Line A?
SELECT count(*) INTO v_count FROM departments;
UPDATE employees SET job_id = 'IT_PROG' WHERE employee_id = : OLD.employee_id;
SELECT count(*) INTO v_count FROM employees; (*)
DBMS_OUTPUT.PUT_LINE('A salary was updated');
None. All of the above are allowed.
40. What is wrong with the following code?
CREATE OR REPLACE TRIGGER loc_trigg
BEFORE DELETE ON locations
BEGIN
RAISE_APPLICATION_ERROR(-20201,'Invalid delete');
ROLLBACK;
END;
The last line should be: END loc_trigg;
You cannot use RAISE_APPLICATION_ERROR inside a trigger.
The second line should be: BEFORE DELETE OF locations
You cannot use ROLLBACK inside a trigger. (*)
Nothing is wrong, this trigger will compile and execute successfully.
41. What is wrong with the following code?
CREATE TRIGGER dept_trigg
BEFORE UPDATE OF department_name ON departments
BEGIN
DBMS_OUTPUT.PUT_LINE(:NEW.department_name);
END;
You cannot use :NEW in a BEFORE trigger, only in an AFTER trigger.
You cannot use :NEW or :OLD in a statement trigger. (*)
You cannot use DBMS_OUTPUT.PUT_LINE inside a trigger.
The second line should be: BEFORE UPDATE ON departments.department_name
42. You need to create a trigger that will fire whenever an employee's s
alary or job_id is updated, but not when any other column of the EMPLOYEES
table is updated. Which of the following is the correct syntax to do this?
CREATE TRIGGER emp_upd_trigg
AFTER UPDATE ON employees (salary, job_id)
BEGIN ...
CREATE TRIGGER emp_upd_trigg
AFTER UPDATE OF salary, job_id ON employees
BEGIN ...(*)
CREATE TRIGGER emp_upd_trigg
AFTER UPDATE OF (salary, job_id) ON employees
BEGIN ...
CREATE TRIGGER emp_upd_trigg
AFTER UPDATE OF salary OR job_id ON employees
BEGIN ...
43. The following code will successfully create emp_trigg: True or False?
CREATE OR REPLACE TRIGGER emp_trigg
BEFORE DELETE OF salary ON employees
BEGIN
RAISE_APPLICATION_ERROR(-20202,'Deleting salary is not allowed');
END;
True
False (*)
44. What type of database object would you create to write an auditing record automatically every time a user connects to the database?
A procedure
A complex view
A trigger (*)
A function
A package
45. The following objects have been created in a user's schema:
-a function FUNC1
-A package PACK1 which contains a public procedure PACKPROC and a
private function PACKFUNC
-a trigger TRIGG1.
The procedure and functions each accept a single IN parameter of type NU
MBER, and the functions return BOOLEANs. Which of the following calls to
these objects (from an anonymous block) are correct? (Choose two.) (Choose all correct answers)
pack1.packproc(25); (*)
SELECT func1(100) FROM dual;
trigg1;
IF pack1.packfunc(40) THEN ...
IF func1(75) THEN ... (*)
46. You can use a trigger to prevent rows from being deleted from the EMPLOYEES table on Mondays. True or False?
True (*)
False
47. Which of the following are good guidelines to follow when creating a
database trigger? (Choose two.) (Choose all correct answers)
Where possible, use a trigger to enforce a foreign key constraint.
Use triggers to override privilege checking and view other users' private tables.
Do not use a trigger to replace or duplicate something which the Oracle Server does automatically. (*)
Use triggers to prevent unauthorized users from SELECTing confidential data.
Do not create a trigger that automatically fires another trigger. (*)
48. Which of the following are NOT stored inside the database? (Choose two.) (Choose all correct answers)
A PL/SQL package specification
A database trigger
An anonymous block (*)
An application trigger (*)
A sequence
49. A business rule states that an employee's salary cannot be greater than 99,999.99 or less than 0. The best way to enforce this rule is by using:
A datatype of NUMBER(7,2) for the SALARY column
A database trigger
A check constraint (*)
An application trigger
A view
50. Which of the following best describes a database trigger?
A subprogram that checks whether a user has typed the correct password to log on to the database.
A PL/SQL subprogram that executes automatically whenever an associated database event occurs. (*)
A PL/SQL subprogram that always returns exactly one value.
A subprogram that is invoked explicitly by the calling application.
A PL/SQL subprogram that inserts rows into a logging table.
Abonați-vă la:
Postări (Atom)