Вы находитесь на странице: 1из 27

1.

Which of
the Mark for Review
following (1) Points
is NOT a
good
guideline
for
retrieving
data in
PL/SQL?
The WHERE clause is optional in nearly all cases. (*)
Declare the receiving variables using %TYPE
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.

Correct

2. Given this first section of code:


Mark for Review
(1) Points
DECLARE
v_result employees.salary%TYPE;
BEGIN

Which statement will always return exactly one value?


SELECT SUM(salary)
INTO v_result
FROM employees;

(*)
SELECT salary
INTO v_result
FROM employees;
SELECT salary
INTO v_result
FROM employees
WHERE department_id = 80;
SELECT salary
INTO v_result
FROM employees
WHERE last_name ='Smith';
Correct

3. Which rows will be deleted from the EMPLOYEES table when the following code is
Mark for Review
executed?
(1) Points

DECLARE
salary employees.salary%TYPE := 12000;
BEGIN
DELETE FROM employees
WHERE salary > salary;
END;
All rows whose SALARY column value is greater than 12000.
All rows in the table.
No rows. (*)
All rows whose SALARY column value is equal to 12000.

Correct

4. A variable is declared as:


Mark for Review
(1) Points
DECLARE
v_holdit employees.last_name%TYPE;
BEGIN ...

Which of the following is a correct use of the INTO clause?

SELECT *
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees
WHERE employee_id=100;

(*)
SELECT last_name
INTO v_holdit
FROM employees;
SELECT salary
INTO v_holdit
FROM employees
WHERE employee_id=100;
Correct

5. The following code will return the last name of the employee whose employee id
is equal to 100: True or False? Mark for Review
(1) Points
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 (*)

Test: Section 3 Quiz


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

Section 3 Quiz
(Answer all questions in this section)
6. What will happen when the following statement is executed?
Mark for Review
(1) Points
UPDATE employees
SET salary = 5000, commission_pct = NULL WHERE department_id = 50; ;
Assume there are no integrity constraint issues.
All employees who have a salary of 5000 have their commission percentage set to
NULL.
The statement fails because you cannot use NULL in the SET clause.
All employees in department 50 have their salary changed to 5000 and their
commission percentage set to NULL. (*)
The statement fails because you cannot modify more than one column in a single
UPDATE statement.
Correct

7. The following table has been created:


Mark for Review

CREATE TABLE student_table (1) Points


(stud_id NUMBER(6),
last_name VARCHAR2(20),
first_name VARCHAR2(20),
lunch_num NUMBER(4));
Which one of the following INSERT statements will fail?
INSERT INTO student_table (stud_id, last_name, first_name, lunch_num)
VALUES (143354, 'Roberts', 'Cameron', 6543);
INSERT INTO student_table (stud_id, lunch_num, first_name, last_name)
VALUES (143352, 6543, 'Cameron', 'Roberts');
INSERT INTO student_table (stud_id, last_name, lunch_num)
VALUES (143354, 'Roberts', 6543, 'Cameron');

(*)
INSERT INTO student_table
VALUES (143354, 'Roberts', 'Cameron', 6543);
Correct

8. When INSERTing a row, the NULL keyword can be included in the VALUES (....) list.
True or False? Mark for Review
(1) Points

True (*)
False

Correct

9. Which of the following will delete all employees who work in the Sales department?
Mark for Review
(1) Points
DELETE FROM employees
WHERE department_id =
SELECT department_id
FROM departments
WHERE department_name = 'Sales';
DELETE FROM employees e, departments d
WHERE e.department_id = d.department_id
AND department_name = 'Sales';
DELETE (SELECT department_id

FROM
WHEREdepartments
department_name = 'Sales')
FROM employees;
DELETE FROM employees
WHERE department_id =
(SELECT department_id
FROM departments
WHERE department_name = 'Sales');

(*)
Correct

10. The MERGE statement will INSERT or DELETE rows in a target table based on matching
Mark for Review
values in a source table. True or False?
(1) Points
True
False (*)

Incorrect. Refer to Section 3 Lesson 1.

Previous Page 2 of 3 Next Summary

Test: Section 3 Quiz


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

Section 3 Quiz
(Answer all questions in this section)
11. Which of the following SQL DML commands can be used inside a PL/SQL block?
Mark for Review
(1) Points
INSERT and UPDATE only.
INSERT, UPDATE, and DELETE only.
INSERT, UPDATE, DELETE, and MERGE. (*)
UPDATE and DELETE only.

Correct

12. Assume there are 5 employees in Department 10. What happens when the following
Mark for Review
statement is executed?
(1) Points

UPDATE employees
SET salary=salary*1.1;
No rows are modified because you did not specify "WHERE department_id=10"
A TOO_MANY_ROWS exception is raised.
All employees get a 10% salary increase. (*)
An error message is displayed because you must use the INTO clause to hold the
new salary.
Correct

13. Employee_id 999 does not exist. What will happen when the following code is
Mark for Review
executed? (1) Points
DECLARE
employee_id employees.employee_id%TYPE := 999;
BEGIN
UPDATE employees SET salary = salary * 1.1
WHERE employee_id = employee_id;
END;
An exception is raised because the UPDATE statement did not modify any rows.
Every employee row is updated. (*)
No rows are updated but the block completes successfully.
An exception is raised because you cannot give a variable the same name as a
table column.
Correct

14. How many transactions are in the following block?


Mark for
(1)Review
Points
BEGIN
INSERT INTO countries (country_id, country_name)
VALUES ('XA', 'Xanadu');
INSERT INTO countries (country_id, country_name)
VALUES ('NV', 'Neverland');
UPDATE countries SET country_name='Deutchland'
WHERE country_id='DE';
UPDATE countries SET region_id=1
WHERE country_name LIKE '%stan';
END;

How many transactions are shown above?


Four; each DML is a separate transaction
It depends on how many rows are updated - there will be a separate transaction
for each row.
One (*)
Two; both the INSERTs are one transaction and both the UPDATEs are a second

transaction.
Correct

15. Which of the following best describes a database transaction?


Mark for Review
(1) Points
A SELECT statement based on a join of two or more database tables
A single SQL statement that updates multiple rows of a table
A related set of SQL DML statements which must be executed either completely or
not at all (*)
All the DML statements in a single PL/SQL block

Correct

Previous Page 3 of 3 Summary

Test: Semester 1 Midterm Exam


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

Section 1

(Answer all questions in this section)

1.Procedural constructs give you better control of your SQL statements and their execution.
Mark for Review
True or False?
(1) Points

True (*)

False

Correct

2.Which of the following can be done using PL/SQL?


Mark for Review
(1) Points

Manage database tasks such as security

Create custom reports

Retrieve and modify data in Oracle database tables

Create complex applications

All of these can be done (*)

Correct

3.What are the characteristics of an anonymous block? (Choose two.)


Mark for Review
(1) Points

(Choose all correct answers)

Unnamed (*)
Can be declared as procedures or as functions

Compiled each time the code is executed (*)

Stored in the database

Correct

4.In a PL/SQL block, which of the following should not be followed by a semicolon?
Mark for Review
(1) Points

All SQL statements

All PL/SQL statements

END

DECLARE (*)

Correct

5.Which lines of code will correctly display the message "The cat sat on the mat"? (Choose
Mark for Review
two.) (1) Points

(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');

Correct

Page 1 of 10 Next Summary


Your browser does not support JavaScript. Please turn on JavaScript to use the features of this
web page.

Test: Semester 1 Midterm Exam


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

1529962878748 1 Y Y 1843475966

Section 1

(Answer all questions in this section)

6. Which statements are mandatory in a PL/SQL block? (Choose two.)


Mark for Review
(1) Points

(Choose all correct answers)

EXCEPTION

BEGIN (*)

DECLARE

END; (*)

Correct

7. Nonprocedural languages allow the programmer to produce a result when a series of


Mark for Review
steps are followed. True or False?
(1) Points

True

False (*)
Correct

8. The P in PL/SQL stands for:


Mark for Review
(1) Points

Proprietary

Processing

Primary

Procedural (*)

Correct

Section 2

(Answer all questions in this section)

9. Which of these are PL/SQL data types? (Choose three.) Mark for Review
(1) Points

(Choose all correct answers)

LOB (*)

Composite (*)

Delimiter

Scalar (*)

Identifier

Correct
10.A datatype specifies and restricts the possible data values that can be assigned to a
Mark for Review
variable. True or False?
(1) Points

True (*)

False

Correct

Previous Page 2 of 10 Next Summary

Test: Semester 1 Midterm Exam


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

1529962878748 2 Y Y 1843475966

Section 2

(Answer all questions in this section)

11.A variable defined in an outer block is global to the outer block and local to the inner
Mark for Review
block. True or False?
(1) Points

True

False (*)

Correct

12.If a variable definition is not found in an inner block where it is being referenced, where
Mark for Review
does it look for it?
(1) Points

This will result in an error.

It looks upward in the parent blocks. (*)

It downward in any other inner blocks.

Correct

13.If an outer block is labeled, the inner block must be labeled also. True or False?
Mark for Review
(1) Points

True

False (*)

Correct

14.Which of the following are valid identifiers? (Choose two.)


Mark for Review
(1) Points

(Choose all correct answers)

completion_%

students_street_address (*)

Full Name

#hours

v_code (*)

Correct

15.Which statements about lexical units are true? (Choose two.)


Mark for Review
(1) Points

(Choose all correct answers)

They are the building blocks of every PL/SQL program (*)

They are sequences of characters including letters, digits, tabs, returns and symbols
(*)

They are optional but can make a PL/SQL block execute faster

They are named objects stored in the database

Correct

est: Semester 1 Midterm Exam


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

1529962878748 3 Y Y 1843475966

Section 2

(Answer all questions in this section)

16.Which of the following statements about implicit conversions is NOT true?


Mark for Review
(1) Points

Code containing implicit conversions is harder to read and understand.

Code containing implicit conversions typically runs faster than code containing
explicit conversions. (*)

Code containing implicit conversions may not work in the future if Oracle changes
the conversion rules.

Correct

17.If today's date is 14th June 2007, which statement will correctly convert today's date to
Mark for Review
the value: June 14, 2007 ?
(1) Points
TO_CHAR(sysdate, 'Month DD, YYYY') (*)

TO_DATE(sysdate)

TO_DATE(sysdate,'Month DD, YYYY')

TO_CHAR(sysdate)

Correct

18.PL/SQL can implicitly convert a CHAR to a NUMBER, provided the CHAR contains a
Mark for Review
numeric value, for example '123'. True or False?
(1) Points

True (*)

False

Correct

19.The TO_CHAR function is used for explicit data type conversions. True or False?
Mark for Review

(1) Points

True (*)

False

Correct

20.Code is easier to read if you declare one identifier per line. True or False?
Mark for Review
(1) Points

True (*)

False
Correct

Test: Semester 1 Midterm Exam


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

1529962878748 4 Y Y 1843475966

Section 2

(Answer all questions in this section)

21.If you are using the %TYPE attribute, you can avoid hard coding the:
Mark for Review
(1) Points

Column name

Data type (*)

Table name

Constraint

Correct

22.Examine the following code:


Mark for Review
(1) Points
DECLARE
v_first_name varchar2 (30);
v_salary number (10);
BEGIN
SELECT first_name, salary
INTO v_first_name, v_salary
FROM employees
WHERE last_name = 'King';
END;

Which programming guideline would improve this code?

Use upper and lower case consistently.

Use a suitable naming convention for variables.


Indent the code to make it more readable. (*)

Correct

23.Which good programming practice guideline would make this code easier to read?
Mark for Review
(1) Points
DECLARE
v_sal NUMBER(8,2);
BEGIN

SELECT salary INTO


FROM employees v_sal employee_id = 100;
WHERE
UPDATE employees SET salary = v_sal;
END;

Indenting each level of code (*)

Using a consistent naming convention for variables

Declaring variables using %TYPE

Avoiding implicit data type conversions

Correct

24.Is the following variable declaration correct or not?


Mark for Review
(1) Points
DECLARE
test NUMBER(5);

Correct. (*)

Not correct.

Correct

25.Which of the following are required when declaring a variable? (Choose two.)
Mark for Review
(1) Points

(Choose all correct answers)


CONSTANT

NOT NULL

Identifier name (*)

Data type (*)

Correct

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

1529962878748 5 Y Y 1843475966

Section 2
(Answer all questions in this section)
26.When a variable is defined using the NOT NULL keywords, the variable must contain a
Mark for Review
value. True or False?
(1) Points

True (*)
False

Correct

Section 3
(Answer all questions in this section)
27.How many DML statements can be included in a single transaction?
Mark for Review
(1) Points
None. A transaction cannot include DML statements.
As many as needed (*)
A maximum of four DML statements
Only one

Incorrect. Refer to Section 3 Lesson 4.

28.The following anonymous block of code is run:


Mark for Review
(1) Points
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?


Two rows are inserted. (*)
No data is inserted and an error occurs.
One record of data is inserted.
No data is inserted.

Correct

29.Which SQL statement can NOT use an implicit cursor?


Mark for Review
(1) Points
An UPDATE statement

A DELETE statement
A SELECT statement that returns multiple rows (*)
A SELECT statement that returns one row

Correct

30.There are three employees in department 90. What will be displayed when the following
Mark for Review
code is executed?
(1) Points
DECLARE
v_open CHAR(3) := 'NO';
BEGIN
UPDATE employees SET job_id = 'ST_CLERK'
WHERE department_id = 90;
IF SQL%FOUND THEN
v_open := 'YES';
END IF;
DBMS_OUTPUT.PUT_LINE(v_open || ' ' || SQL%ROWCOUNT);
END;

YES 1
Nothing will be displayed. The block will fail because you cannot use implicit cursor
attributes directly in a call to DBMS_OUTPUT.PUT_LINE.
YES 3 (*)
NO 3

Correct

Previous Page 6 of 10 Next Summary

Test: Semester 1 Midterm Exam


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

1529962878748 6 Y Y 1843475966

Section 3
(Answer all questions in this section)

31.Assume there are 5 employees in Department 10. What happens when the following
Mark for Review
statement is executed?
(1) Points

UPDATE employees
SET salary=salary*1.1;

No rows are modified because you did not specify "WHERE department_id=10"

An error message is displayed because you must use the INTO clause to hold the
new salary.

All employees get a 10% salary increase. (*)

A TOO_MANY_ROWS exception is raised.

Correct

32.When INSERTing a row, the NULL keyword can be included in the VALUES (....) list. True
Mark for Review
or False?
(1) Points

True (*)

False

Correct

33.You want to modify existing rows in a table. Which of the following are NOT needed in
Mark for Review
your SQL statement?
(1) Points

The name of the column(s) you want to modify.

The name of the table.

A new value for the column you want to modify (this can be an expression or a
subquery).

An UPDATE clause.
A MODIFY clause. (*)

Correct

34.Which one of these SQL statements can be directly included in a PL/SQL executable
Mark for Review
block?
(1) Points

SELECT salary FROM employees


WHERE department_id=60;

DELETE FROM employees


WHERE department_id=60;

(*)
DROP TABLE locations;

CREATE TABLE new_emps (last_name VARCHAR2(10), first_name VARCHAR2(10));

Correct

35.Which one of these SQL statements can be directly included in a PL/SQL executable
Mark for Review
block?
(1) Points

SELECT * FROM DUAL;

IF... THEN...;

INSERT INTO...; (*)

SHOW USER;

Incorrect. Refer to Section 3 Lesson 2.

Previous Page 7 of 10 Next Summary


Your browser does not support JavaScript. Please turn on JavaScript to use the features of this
web page.

Test: Semester 1 Midterm Exam


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

1529962878748 7 Y Y 1843475966

Section 3

(Answer all questions in this section)

36.When used in a PL/SQL block, which SQL statement must return exactly one row?
Mark for Review
(1) Points

MERGE

UPDATE

SELECT (*)

DELETE

INSERT

Correct

Section 4

(Answer all questions in this section)

37.Look at the following code fragment:


Mark for Review
(1) Points
i := 2;
WHILE i < 3 LOOP
i := 4;
DBMS_OUTPUT.PUT_LINE('The counter is: ' || i);
END LOOP;

How many lines of output will be displayed?

One line (*)

No lines

The block will fail because you cannot use DBMS_OUTPUT.PUT_LINE inside a loop.

Two lines

Incorrect. Refer to Section 4 Lesson 4.

38.Which statement best describes when a FOR loop should be used?


Mark for Review
(1) Points

When the controlling condition must be evaluated at the start of each iteration

When the number of iterations is known (*)

When testing the value in a Boolean variable

Correct

39.Which statement best describes when a WHILE loop shouild be used?


Mark for Review
(1) Points

When testing whether a variable is null

When assigning a value to a Boolean variable

When repeating a sequence of statements until the controlling condition is no longer


true (*)

When the number of iterations is known

Correct
40.You can use a control structure to change the logical flow of the execution of SQL
Mark for Review
statements. True or False?
(1) Points

True (*)

False

Incorrect. Refer to Section 4 Lesson 1.

Previous Page 8 of 10 Next Summary

Your browser does not support JavaScript. Please turn on JavaScript to use the features of this
web page.

Test: Semester 1 Midterm Exam


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

1529962878748 8 Y Y 1843475966

Section 4

(Answer all questions in this section)

41.Name three types of control structures in PL/SQL. (Choose three)


Mark for Review
(1) Points

(Choose all correct answers)

SELECT statements

LOOP statements (*)


IF statements (*)

EXCEPTIONS

CASE statements (*)

Correct

42.What is wrong with the following trivial IF statement:


Mark for Review
(1) Points
IF (v_job='President')
THEN v_salary := 10000;

ELSE is missing

IF and THEN must be on the same line: IF (v_job='President') THEN ...

END IF; is missing (*)

The condition should be coded: IF (v_job := 'President')

Correct

43.What type of control structures are repetition statements that enable you to execute
statements in a PLSQL block repeatedly? Mark for Review
(1) Points

Loops (*)

CASE expressions

IF statements

CASE statements

Correct

44.What will be the value of variable c after the following code is executed?
Mark for Review
(1) Points
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := NULL;
c NUMBER;
BEGIN
IF a AND b THEN c := 2;
ELSIF a OR b THEN c := 0;
ELSE c := 1;
END IF;
END;

0 (*)

Null

Correct

45.What will be displayed when the following block is executed?


Mark for Review
(1) Points
DECLARE
v_age1 NUMBER(3);
v_age2 NUMBER(3);
v_message VARCHAR2(20);
BEGIN
CASE
WHEN v_age1 = v_age2 THEN v_message := 'Equal';
WHEN v_age1 <> v_age2 THEN v_message := 'Unequal';
ELSE v_message := 'Undefined';
END CASE;
DBMS_OUTPUT.PUT_LINE(v_message);
END;

Undefined (*)

Nothing will be displayed because V_MESSAGE is set to NULL.

Unequal

Equal

Correct

Previous Page 9 of 10 Next Summary


Your browser does not support JavaScript. Please turn on JavaScript to use the features of this
web page.

Test: Semester 1 Midterm Exam


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

1529962878748 9 Y Y 1843475966

Section 4

(Answer all questions in this section)

46.When coding two nested loops, both loops must be of the same type. For example, you
Mark for Review
cannot code a FOR loop inside a WHILE loop. True or False?
(1) Points

True

False (*)

Correct

47.Which one of these statements about using nested loops is true?


Mark for Review
(1) Points

The outer loop must be labeled if you want to exit the outer loop from within the
inner loop. (*)

The outer loop must be labeled, but the inner loop need not be labeled.

Both loops can have the same label.

All the loops must be labeled.

Correct
48.Which one of these tasks is best done using a LOOP statement?
Mark for Review
(1) Points

Fetching and displaying an employee's last name from the database

Calculating and displaying the sum of all integers from 1 to 100 (*)

Assigning a letter grade to a numerical score

Testing if a condition is true, false, or null

Correct

49.Examine the following block:


Mark for Review
(1) Points
DECLARE
v_counter PLS_INTEGER := 1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(v_counter);
v_counter := v_counter + 1;
EXIT WHEN v_counter = 5;
END LOOP;
END;

What is the last value of V_COUNTER that is displayed?

This is an infinite loop; the loop will never finish.

4 (*)

Correct

50.Which one of these is NOT a kind of loop?


Mark for Review
(1) Points

ASCENDING loop (*)


Basic loop

FOR loop

WHILE loop

Correct

Previous Page 10 of 10 Summary

Your browser does not support JavaScript. Please turn on JavaScript to use the features of this
web page.

Вам также может понравиться