0% found this document useful (0 votes)
238 views21 pages

Oracle 1-4,6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
238 views21 pages

Oracle 1-4,6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

1.

A program which specifies a list of operations to be performed sequentially to


achieve the desired result can be called:
nondeclarative
declarative
procedural (*)
low level
Correct
(1/1) Points
2. PL/SQL extends SQL by including all of the following except:
constants
reusable program units
nonprocedural constructs (*)
variables
conditional statements
Correct
(1/1) Points
3. Third-generation programming languages include all except _____ and _____.
(Choose all correct answers)
MySQL (*)
Java
SQL (*)
C++
PL/SQL
Correct
(1/1) Points
4. Which of the following statements is true?
You can embed SQL statements within PL/SQL code. (*)
You can embed PL/SQL statements within SQL code.
None of these are correct.
You can embed procedural constructs within SQL code.
Correct
(1/1) Points
5. Which of the following statements about PL/SQL and SQL is true?
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. (*)
PL/SQL and SQL are both ANSI-compliant.
Correct
6. Which of the following statements about exception handling in PL/SQL is
false?
None of these are false (*)
You can prepare for application exceptions by creating exception handlers.
Exception handling code tells your program what to do when an error is
encountered.
You can prepare for database exceptions by creating exception handlers.
All of these are false
Correct
(1/1) Points
7. Procedural constructs give you better control of your SQL statements and
their execution. True or False?
True (*)
False
Correct
(1/1) Points
8. Comparing PL/SQL with other languages such as C and Java, which of the
following statements is true?
PL/SQL is easier to learn and more efficient (*)
PL/SQL is easier to learn and does not require an Oracle database or tool
PL/SQL is harder to learn
PL/SQL is easier to learn but less efficient
Incorrect. Refer to Section 1 Lesson 2.
(0/1) Points
9. You can create a Web site application written entirely in PL/SQL. True or False?
True
False (*)
Correct
(1/1) Points
10. Which of the following can be done using PL/SQL?
Manage database tasks such as security
All of these can be done (*)
Create custom reports
Retrieve and modify data in Oracle database tables
Create complex applications
Correct
11. In a PL/SQL block, which of the following should not be followed by a
semicolon?
DECLARE (*)
All SQL statements
All PL/SQL statements
END
Correct
(1/1) Points
12. How can you display results to check that a PL/SQL block is working
correctly?
Use DBMS_OUTPUT.PUT_LINE (*)
Use an Exception section
You don't need to do anything, the results will display automatically.
Write a C or Java program to display the results
Correct
(1/1) Points
13. Which lines of code will correctly display the message "Hello World" ?
(Choose two.)
(Choose all correct answers)
DBMS_OUTPUT.PUT_LINE('Hello' || 'World');
DBMS_OUTPUT.PUT_LINE('Hello World'); (*)
DBMS_OUTPUT('Hello World');
DBMS_OUTPUT.PUT_LINE('Hello' || ' ' || 'World'); (*)
Correct
(1/1) Points
14. Errors are handled in the Exception part of the PL/SQL block. True or False?
True (*)
False
Correct
(1/1) Points
15. Which sections of a PL/SQL block are optional?
Executable only
Exception only
Declaration and Exception (*)
Declaration and Executable
Correct
1. Examine the following code:
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?

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


Use a suitable naming convention for variables.
Use upper and lower case consistently.
Correct
(1/1) Points
2. Which of these are examples of good programming practice? (Choose three.)
(Choose all correct answers)
Use a clear and consistent naming convention for variables. (*)
Declare two variables on each line of code.
Declare variables with the same names as table columns.
Use a NOT NULL constraint when a variable must have a value (*)
Do not rely on implicit data type conversions. (*)
Correct
(1/1) Points
3. Which of the following are PL/SQL data types? (Choose three.)
(Choose all correct answers)
Composite (*)
Scalar (*)
Delimiter
Large Objects (LOB) (*)
Lexical
Correct
(1/1) Points
4. A Scalar data type holds a(n) ____ value.
Large
Single (*)
image
Multi
Correct
(1/1) Points
5. Code is easier to read if you declare one identifier per line. True or False?
True (*)
False
Correct

Test: PL/SQL Section 2 Quiz

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

Section 2
(Answer all questions in this section)
6. Which of the following is NOT a character data type?
LONG
CHAR
VARCHAR2
BOOLEAN (*)
Correct
(1/1) Points
7. Is the following variable declaration correct or not?
DECLARE
test NUMBER(5);

Correct. (*)
Not correct.
Incorrect. Refer to Section 2 Lesson 1.
(0/1) Points
8. When a variable is defined using the NOT NULL keywords, the variable must
contain a value. True or False?
True (*)
False
Correct
(1/1) Points
9. What characters must enclose non-numeric literal values?
Single quotes: ' ' (*)
Double quotes: " "
Parentheses: ()
Correct
(1/1) Points
10. Delimiters are _____ that have special meaning to the Oracle database.
symbols (*)
identifiers
variables
Correct
(1/1) Points
Previous Page 2 of 3 Next

11. A variable defined in an outer block is global to the outer block and local to
the inner block. True or False?
True
False (*)
Incorrect. Refer to Section 2 Lesson 6.
(0/1) Points
12. If a variable is defined with the same name in both an inner and outer block,
and referenced in the outer block, it will reference the ___________ block value of
the variable.
Inner
Neither - can't define a variable with the same name in both blocks
Outer (*)
Incorrect. Refer to Section 2 Lesson 6.
(0/1) Points
13. The LENGTH and ROUND functions can be used in PL/SQL statements. True
or False?
True (*)
False
Correct
(1/1) Points
14. The implicit data type conversion at Point A may not work correctly. Why not?
DECLARE
v_mydate DATE;
BEGIN
V_MYDATE := '29-Feb-2004'; -- Point A
END;

Oracle cannot implicitly convert a character string to a date, even if the string
contains a valid date value (*)
There are only 28 days in February
If the database language is not English, 'Feb' has no meaning.
V_MYDATE has been entered in uppercase
Correct
(1/1) Points
15. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of:
Explicit conversion functions (*)
Implicit conversion functions
Character functions
Operators
Correct
1. Which SQL statement can NOT use an implicit cursor?
A SELECT statement that returns multiple rows (*)
An UPDATE statement
A SELECT statement that returns one row
A DELETE statement
Correct
(1/1) Points
2. Employee_id 999 does not exist. What will happen when the following code is
executed?
DECLARE
employee_id employees.employee_id%TYPE := 999;
BEGIN
UPDATE employees
SET salary = salary * 1.1
WHERE employee_id = employee_id;
END;

Every employee row is updated. (*)


An exception is raised because the UPDATE statement did not modify any rows.
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
(1/1) Points
3. There are three employees in department 90. What will be displayed when the
following code is executed?
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;

NO 3
YES 3 (*)
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.
Correct
(1/1) Points
4. A variable is declared as:
DECLARE
v_holdit employees.last_name%TYPE;
BEGIN ...

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

SELECT last_name
INTO v_holdit
FROM employees
WHERE employee_id=100; (*)
SELECT salary
INTO v_holdit
FROM employees
WHERE employee_id=100;
SELECT last_name
INTO v_holdit
FROM employees;
SELECT *
INTO v_holdit
FROM employees;
Incorrect. Refer to Section 3 Lesson 2.
(0/1) Points
5. Which of the following is NOT a valid guideline for retrieving data in PL/SQL?
Specify the same number of variables in the INTO clause as database columns in
the SELECT clause.
Do NOT use a WHERE clause in SELECT statements. (*)
Where possible, declare variables using the %TYPE attribute.
Terminate the SQL statement with a semicolon (;)
Correct
6. Which one of these SQL statements can be directly included in a PL/SQL
executable block?
UPDATE employees
SET last_name='Smith'; (*)
DROP TABLE employees;
DESCRIBE employees;
SELECT last_name FROM employees
WHERE employee_id=100;
Correct
(1/1) Points
7. Does PL/SQL allow you to have a variable with the same name as a database
column?
Yes (*)
No
Correct
(1/1) Points
8. Which one of these SQL statements can be directly included in a PL/SQL
executable block?
SELECT salary FROM employees
WHERE department_id=60;
DROP TABLE locations;
CREATE TABLE new_emps (last_name VARCHAR2(10), first_name VARCHAR2(10));
DELETE FROM employees
WHERE department_id=60; (*)
Correct
(1/1) Points
9. Which of the following best describes a database transaction?
A related set of SQL DML statements which must be executed either completely
or not at all (*)
A single SQL statement that updates multiple rows of a table
A SELECT statement based on a join of two or more database tables
All the DML statements in a single PL/SQL block
Correct
(1/1) Points
10. Examine the following code: BEGIN
INSERT INTO animals VALUES ('aa','aardvarks');
SAVEPOINT sp_1;
INSERT INTO animals VALUES ('bb','big birds');
SAVEPOINT sp_2;
ROLLBACK TO sp_1;
INSERT INTO animals VALUES ('cc','cool cats');
COMMIT;
END;
Which row(s) will be in the ANIMALS table after this block is executed?
aardvaarks and cool cats (*)
cool cats
aardvaarks, big birds and cool cats
big birds and cool cats
Correct
11. You want to modify existing rows in a table. Which of the following are NOT
needed in your SQL statement?
A MODIFY clause. (*)
A new value for the column you want to modify (this can be an expression or a
subquery).
The name of the table.
The name of the column(s) you want to modify.
An UPDATE clause.
Correct
(1/1) Points
12. The MERGE statement will INSERT or DELETE rows in a target table based on
matching values in a source table. True or False?
True
False (*)
Incorrect. Refer to Section 3 Lesson 1.
(0/1) Points
13. What is wrong with the following statement?
MERGE INTO emps e
USING new_emps ne
ON (e.employee_id = ne.employee_id)
WHEN MATCHED
THEN UPDATE
SET ne.salary = e.salary
WHEN NOT MATCHED
THEN INSERT VALUES
(ne.employee_id, ne.first_name, ne.last_name, .... ne.salary, ....);

The UPDATE clause must include the target table name: UPDATE emps SET ....
The SET clause is trying to update the source table from the target table. (*)
The INSERT clause must include a column list as well as a list of column values.
Nothing is wrong, the statement will execute correctly.
Incorrect. Refer to Section 3 Lesson 1.
(0/1) Points
14. Which of the following will delete all employees who work in the Sales
department?
DELETE FROM employees
WHERE department_id =
SELECT department_id
FROM departments
WHERE department_name = 'Sales';
DELETE FROM employees
WHERE department_id =
(SELECT department_id
FROM departments
WHERE department_name = 'Sales'); (*)
DELETE (SELECT department_id
FROM departments
WHERE department_name = 'Sales')
FROM employees;
DELETE FROM employees e, departments d
WHERE e.department_id = d.department_id
AND department_name = 'Sales';
Correct
(1/1) Points
15. What will happen when the following statement is executed?
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 modify more than one column in a
single UPDATE statement.
All employees in department 50 have their salary changed to 5000 and their
commission percentage set to NULL. (*)
The statement fails because you cannot use NULL in the SET clause.
Correct
1. 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
WHEN v_grade IN ('A', 'B') THEN v_result := 'Very Good';
WHEN v_grade IN ('E','F') THEN v_result := 'Poor';
ELSE v_result := 'In Between';
END CASE;
DBMS_OUTPUT.PUT_LINE(v_result);
END;

Very Good
In Between (*)
Poor
Null
Correct
(1/1) Points
2. Look at the following code:
DECLARE
x BOOLEAN := FALSE;
y BOOLEAN := FALSE;
z BOOLEAN ;
BEGIN
z := (x OR NOT y);
-- Line A
....
END;
What is the value of Z at Line A?

True (*)
NULL
An error will occur because you cannot combine two Boolean variables using
"NOT".
False
Correct
(1/1) Points
3. 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;

Low Paid
The code will fail and return an unhandled exception error to the host
environment (*)
High Paid
Null
Correct
(1/1) Points
4. What will be displayed when the following block is executed?
DECLARE
x NUMBER(6) := 0 ;
BEGIN
FOR i IN 1..10 LOOP
FOR j IN 1..5 LOOP
x := x+1 ;
END LOOP;
END LOOP;
DBMS_OUTPUT.PUT_LINE(x);
END;

50 (*)
5
10
15
Correct
(1/1) Points
5. What statement allows you to exit the inner loop at Point A in the following
block?
DECLARE
v_outer_done CHAR(3) := 'NO';
v_inner_done CHAR(3) := 'NO';
BEGIN
LOOP -- outer loop
...
LOOP -- inner loop
...
v_inner_done := 'YES';
... -- Point A
...
END LOOP;
...
EXIT;
...
END LOOP;
END;

EXIT << inner loop>>

WHEN v_inner_done = YES EXIT;


EXIT WHEN v_inner_done = 'YES'; (*)
EXIT AT v_inner_done = 'YES';
Correct
6.
…BEGIN
<< Outer_loop >>
LOOP v_counter := v_counter+1;
EXIT WHEN v_counter>10;
<< Inner_loop >>
LOOP
...
EXIT Outer_loop WHEN v_total_done = 'YES';
-- Leave both loops
EXIT WHEN v_inner_done = 'YES';
-- Leave inner loop only
...
END LOOP Inner_loop;
...
END LOOP Outer_loop;
END;

In this code it is valid for each loop to have it's own EXIT statement. True or
False?

True (*)
False
Correct
(1/1) Points
7. What will be displayed when this block is executed?
DECLARE
v_count NUMBER := 10;
v_result NUMBER;
BEGIN
LOOP
v_count := v_count - 1;
EXIT WHEN v_count < 5;
v_result := v_count * 2;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_result);
END;

NULL
12
10 (*)
8
Correct
(1/1) Points
8. Look at this code:
DECLARE
v_bool BOOLEAN := TRUE;
v_date DATE;
BEGIN
LOOP
EXIT WHEN v_bool;
SELECT SYSDATE INTO v_date FROM dual;
END LOOP;
END;

How many times will the SELECT statement execute?


Once
Twice
Never (the SELECT will not execute at all) (*)
An infinite number of times because the EXIT condition will never be true
Correct
(1/1) Points
9. Examine the following code::
DECLARE
v_count NUMBER := 0;
v_string VARCHAR2(20);
BEGIN
LOOP
v_string := v_string || 'x';
IF LENGTH(v_string) > 10 THEN
EXIT;
END IF;
v_count := v_count + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_count);
END;

What will be displayed when this block is executed?


9
xxxxxxxxxxx
10 (*)
11
Correct
(1/1) Points
10. What will be displayed when this block is executed? DECLARE
v_birthdate DATE;
BEGIN
IF v_birthdate < '01-Jan-2000'
THEN
DBMS_OUTPUT.PUT_LINE(' Born in the 20th century ');
ELSE
DBMS_OUTPUT.PUT_LINE(' Born in the 21st century ');
END IF;
END;

Born in the 21st century (*)


Exception raised because no date given
Born in the 20th century
Correct
11. Which one of the following is correct syntax for an IF statement?
IF condition THEN
statement1;
statement2;
END IF; (*)
IF condition THEN DO
statement1;
statement2;
END IF;
IF condition THEN
statement1;
AND statement2;
END IF;
IF condition THEN
statement1;
statement2;
ENDIF;
Correct
(1/1) Points
12. What is wrong with the following trivial IF statement:
IF (v_job='President')
THEN v_salary := 10000;

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


ELSE is missing
IF and THEN must be on the same line: IF (v_job='President') THEN ...
END IF; is missing (*)
Correct
(1/1) Points
13. Which statement best describes when a FOR loop should be used?
When we want to exit from the loop when a Boolean variable becomes FALSE.
When the statements inside the loop must execute at least once.
When an EXIT WHEN statement must be coded.
When an implicitly declared counter must increase by 1 in each iteration of the
loop. (*)
Correct
(1/1) Points
14. In a FOR loop, an explicitly declared counter is automatically incremented by
1 for each iteration of the loop. True or False?
True
False (*)
Incorrect. Refer to Section 4 Lesson 4.
(0/1) Points
15. You should use a WHILE loop when the number of iterations of the loop is
known in advance. True or False?
True
False (*)
Correct
1. Which of these PL/SQL data structures could store a complete copy of the
employees table, i.e., 20 complete table rows?
An INDEX BY table
A record
An INDEX BY table of records (*)
An explicit cursor based on SELECT * FROM employees;
Correct
(1/1) Points
2. An INDEX BY TABLE type can only have one data field. True or False?
True (*)
False
Incorrect. Refer to Section 6 Lesson 2.
(0/1) Points
3. An INDEX BY TABLE primary key cannot be negative. True or False?
True
False (*)
Incorrect. Refer to Section 6 Lesson 2.
(0/1) Points
4. In an INDEX BY table of records the record can be _______________________.
Either one. (*)
a user-defined record
%ROWTYPE
Incorrect. Refer to Section 6 Lesson 2.
(0/1) Points
5. What is the largest number of elements (i.e., records) that an INDEX BY table
of records can contain?
Many millions of records because a BINARY_INTEGER or PLS_INTEGER can have a
very large value (*)
100
32767
None of these.
4096
Correct
6. Identify the valid collection types:
(Choose all correct answers)
INDEX BY VIEW
INDEX BY TABLE OF ROWS
INDEX BY TABLE OF RECORDS (*)
INDEX BY TABLE (*)
Correct
(1/1) Points
7. An INDEX BY TABLE must have a primary key. True or False?
True (*)
False
Correct
(1/1) Points
8. Which of these PL/SQL data structures can NOT store a collection?
A PL/SQL record (*)
An INDEX BY table of records
An INDEX BY table indexed by BINARY_INTEGER
An INDEX BY table indexed by PLS_INTEGER
Correct
(1/1) Points
9. To declare an INDEX BY table, we must first declare a type and then declare a
collection variable of that type. True or False?
True (*)
False
Correct
(1/1) Points
10. Which of the following methods can be used to reference elements of an
INDEX BY table? (Choose three.)
(Choose all correct answers)
EXISTS (*)
COUNT (*)
FIRST (*)
PREVIOUS
DROP
Correct
11. Consider the following code:
DECLARE
TYPE dept_info_type IS RECORD
(department_id departments.department_id%TYPE,
department_name departments.department_name%TYPE);
TYPE emp_dept_type IS RECORD
(first_name employees.first_name%TYPE,
last_name employees.last_name%TYPE),
dept_info dept_info_type);

v_emp_dept_rec emp_dept_type;

How many fields can be addressed in v_emp_dept_rec?

four (*)
one
two
three
Correct
(1/1) Points
12. Which of the following statements about user-defined PL/SQL records is NOT
true?
It must contain one or more components, but all the components must have
scalar datatypes. (*)
It is not the same as a row in a database table.
It can be defined as NOT NULL.
It can be used as an OUT parameter in a package procedure.
It can be a component of another PL/SQL record.
Correct
(1/1) Points
13. You can store a whole record in a single variable using %ROWTYPE or by
creating your own record structure as a type and then declaring a variable of
that type. True or False?
True (*)
False
Correct
(1/1) Points
14. Which of the following will successfully create a record type containing two
fields, and a record variable of that type?
TYPE person_type IS RECORD
(l_name VARCHAR2(20),gender CHAR(1));
person_rec person_type; (*)
TYPE person_type IS (l_name VARCHAR2(20),gender CHAR(1));
person_rec TYPE person_type;
TYPE person_type IS (l_name VARCHAR2(20), gender CHAR(1));
person_rec person_type;
TYPE person_type IS RECORD
(l_name VARCHAR2(20), gender CHAR(1));
person_rec TYPE person_type;
Correct
(1/1) Points
15. You can use %ROWTYPE with tables and views. True or False?
True (*)
False
Correct

You might also like