PLSQL
PLSQL
PLSQL
What wi
ll be displayed when this code is executed?
DECLARE
var_1 NUMBER;
BEGIN
var_1 := 4;
DECLARE
var_2 NUMBER;
BEGIN
var_2 := 'Unhappy'; -- Line B
var_1 := 8;
END;
var_1 := 12;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(var_1);
END; Mark for Review
(1) Points
Unhappy
12
4 (*)
Variable v_a is out of scope within the inner block and therefore cannot be refe
renced.
Correct
v_date_of_birth.outer
<<outer>>v_date_of_birth
<<outer.v_date_of_birth>>
outer.v_date_of_birth (*)
Correct
Oracle keeps trying to re-execute the statement which caused the exception.
The remaining statements in the executable section are not executed. Instead, Or
acle looks for an EXCEPTION section in the block. (*)
The remaining statements in the executable section of the block are executed.
Correct
True
False (*)
Correct
3,3
3,7
Null, 7 (*)
Null, 3
Correct
The exception is propagated to the outer block and the remaining executable stat
ements in the outer block are skipped. (*)
The exception is propagated to the outer block and the remaining executable stat
ements in the outer block are executed.
The outer block is bypassed and the exception is always propagated to the callin
g environment.
10
20
15 (*)
Nothing is displayed
Correct
At Line A, code:
v_myvar := 25;
It cannot be done because the outer block's v_myvar is out of scope at Line A.
Label the outer block and (at Line A) dot-prefix v_myvar with the block label.
(*)
It cannot be done because the outer block's v_myvar is in scope but not visible
at Line A.
1. To modify an existing row in a table, you can use the ________ statemen
t. Mark for Review
(1) Points
MODIFY
INSERT
ALTER
UPDATE (*)
Incorrect. Refer to Section 3 Lesson 1.
True
False (*)
Correct
Correct
True
False (*)
Correct
You cannot use inequality operators such as "<" and ">" inside a DELETE
statement.
Correct
The UPDATE clause must include the target table name: UPDATE emps SET ..
..
The INSERT clause must include a column list as well as a list of column
values.
The SET clause is trying to update the source table from the target tabl
e. (*)
An UPDATE clause.
A new value for the column you want to modify (this can be an expression
or a subquery).
No, you can only create one row at a time when using the VALUES clause.
(*)
Yes, you can list as many rows as you want, just remember to separate th
e rows with commas.
Correct
1. When used in a PL/SQL block, which SQL statement must return exactly on
e row? Mark for Review
(1) Points
INSERT
UPDATE
SELECT (*)
MERGE
DELETE
Correct
True
False (*)
Correct
Specify the same number of variables in the INTO clause as database colu
mns in the SELECT clause.
Correct
No
Yes (*)
Correct
The block will fail because the SELECT statement returns more than one r
ow.
The block will fail because the SELECT is trying to read two columns int
o three PL/SQL variables. (*)
The block will fail because V_LAST was declared before V_FIRST.
The block will execute successfully, and the V_SALARY variable will be s
et to NULL.
Correct
IF... THEN...;
SHOW USER;
The SELECT will fail because it does NOT return exactly one row.
The block will fail because variable V_SALARY was not declared.
The block will fail because no results are displayed to the user.
1. 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;
Mark for Review
(1) Points
NO 3
YES 1
YES 3 (*)
Nothing will be displayed. The block will fail because you cannot use im
plicit cursor attributes directly in a call to DBMS_OUTPUT.PUT_LINE.
Correct
SQL%COUNT
SQL%NUMBER
SQL%ROWCOUNT (*)
SQLROW%COUNT
Correct
An explicit cursor which must be declared and named by the PL/SQL progra
mmer.
Correct
An exception is raised because you cannot give a variable the same name
as a table column.
An exception is raised because the UPDATE statement did not modify any r
ows.
DML statements and SELECT statements which return a single row. (*)
COMMIT and ROLLBACK statements only.
1. How many transactions are in the following block?
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?
Mark for Review
(1) Points
Two; both the INSERTs are one transaction and both the UPDATEs are a sec
ond transaction.
It depends on how many rows are updated - there will be a separate trans
action for each row.
One (*)
One
Correct
cool cats
Correct
1. We want to execute one of three statements depending on whether the valu
e in V_VAR is 10, 20 or some other value. What should be coded at Line A?
IF v_var = 10 THEN
statement1;
-- Line A
statement2;
ELSE
statement3;
END IF;
Mark for Review
(1) Points
ELSIF v_var = 20
IF v_var = 20 THEN
IF...THEN...ELSE
IF...THEN...ELSIF...ELSE
CASE...WHEN...THEN
A loop. (*)
Correct
ELSE is missing
Incorrect. Refer to Section 4 Lesson 1.
child
teenager
adult (*)
adultteenagerchild
SELECT statements
EXCEPTIONS
IF statements (*)
Correct
6. 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;
Mark for Review
(1) Points
Correct
Correct
up
down
left (*)
null
Correct
Equal
Start
Nothing will be displayed. The block will fail because you cannot compar
e two null values.
Correct
Correct
True (*)
False
Correct
True
False (*)
True (*)
False
NULL
An error will occur because you cannot combine two Boolean variables usi
ng "NOT".
Correct
END;
END IF;
ENDCASE;
Correct
Correct
END; (*)
ENDIF;
END CASE;
ENDCASE;
Correct
Equal
Undefined (*)
Unequal
True
False (*)
NULL
Undefined
Adult Male
Junior Female
Other Value (*)
Correct
1. For which one of these tasks should you use a PL/SQL loop? Mark for
Review
(1) Points
Correct
A FOR loop.
A WHILE loop.
An infinite loop.
A nested loop.
Correct
3. 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?
Mark for Review
(1) Points
10 (*)
11
xxxxxxxxxxx
10 (*)
12
NULL
Correct
Once.
Twice.
An infinite number of times because the EXIT condition will never be tru
e
Correct
A loop (*)
A CASE statement
A Boolean variable.
Correct
Correct
None.
One only.
Two.
True
False (*)
One
Three
Four
The block will fail because you cannot change the value of i inside the
loop. (*)
Correct
01-MAY-07
31-DEC-07
4/30/2007 (*)
4/17/2007
Correct
True (*)
False
Correct
True
False (*)
Correct
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.
Correct
FOR i IN 10 .. 1 LOOP
FOR i IN 1 .. 10 BY -1 LOOP
Correct
No lines
Two lines
The block will fail because you cannot use DBMS_OUTPUT.PUT_LINE inside a
loop.
Correct
1. Which one of these statements about using nested loops is true?
Mark for Review
(1) Points
The outer loop must be labelled, but the inner loop need not be labelled
The outer loop must be labelled if you want to exit the outer loop from
within the inner loop (*)
Correct
Correct
LOOP
10
15
50 (*)
Correct
80
45 (*)
14
41
Correct
EXIT;
EXIT red;
EXIT <<blue>>;
Correct
1. How must you reference one field which is part of a PL/SQL record?
Mark for Review
(1) Points
field_name.record_name
record_name.field_name (*)
record_name(field_name)
field_name OF record_name
It cannot be done.
Correct
Correct
Four
Three (*)
None
Correct
Scalar
Record (*)
Cursor
Row
Correct
True
False (*)
Correct
%ISOPEN
%NOTFOUND
%FOUND (*)
%ROWCOUNT
Correct
Correct
1. A cursor FOR loop using a subquery can extensiv
ely shorten code length when compared to an explicit cursor declaration. True or
False? Mark for Review
(1) Points
True (*)
False
Correct
The OPEN, CLOSE, FETCH and EXIT from the loop are done automatically. (*
)
You can OPEN the same cursor twice at the same time.
emp_record.salary (*)
emp_cursor.salary
employees.salary
emp_record.employees.salary
TO_CHAR(salary)
Correct
Correct
6. What is the DISadvantage of using a cursor FOR loop wit
h a subquery? Mark for Review
(1) Points
Correct
Correct
1. The following cursor has been declared:
CURSOR emp_curs
(p_dept_id employees.department_id%TYPE,
p_job_id employees.job_id%TYPE) IS
SELECT * FROM employees
WHERE department_id = p_dept_id
AND job_id = p_job_id;
Which of the following will correctly open the cursor?
Mark for Review
(1) Points
OPEN emp_curs(20);
Correct
True (*)
False
Correct
v_deptid
100 / 2
Correct
Correct
When the cursor is declared as SELECT ... FOR UPDATE ...; (*)
Correct
Your session waits for 10 seconds, and then returns control to your bloc
k so that it can continue to execute. (*)
Your block fails because you should have coded: FOR UPDATE WAIT (10);
Correct
FOR LOCK
Correct
The server will wait until the locks have been released by the other use
r.
An Oracle server error occurs. (*)
Your rows will override the other users' lock and your block will execut
e successfully.
Correct
FOR UPDATE
In Block A, the program waits indefinitely until the rows are available.
In Block B, control is returned to your program after 5 seconds so that it can
do other work.
Correct
1. Which of the following is NOT allowed when using multiple cursors with
parameters? Mark for Review
(1) Points
You cannot OPEN more than one cursor at the same time.
Correct
It reads 1000 employee rows every time BIGEMP_CUR is OPENed, and then ig
nores 990 of them. (*)
It is using cursor FOR loops, which are less efficient than OPENing and
CLOSEing the cursors explicitly.
Correct
OPEN country_cur;
When two tables are related to each other (often by a foreign key) and w
e want to produce a multilevel report using data from both tables. (*)
Only one.
A maximum of three.
As many as you need, but only one of them can be open at any time.
Correct