Which statement is true about the execution of the PL/SQL block?

View the Exhibit to examine the PL/SQL block.

Which statement is true about the execution of the PL/SQL block?

View the Exhibit to examine the PL/SQL block.

Which statement is true about the execution of the PL/SQL block?

A.
It executes successfully and gives the desired output.

B.
It does not execute because the definition of type population is indexed by varchar2.

C.
It executes, and the string keys of an associative array are not stored in creation order, but in
sorted order.

D.
It does not execute because the value that is once assigned to the element of the associative
array cannot be changed.

Explanation:



Leave a Reply 15

Your email address will not be published. Required fields are marked *


Leonid

Leonid

I think the answer is “C”

The result of the execution is:
Population of Megalopolis is 1000000
Population of Midland is 750000
Population of Smallville is 2001

For an associative array indexed by string, the first and last elements are those with the lowest and highest key values, respectively. Key values are in sorted order

See http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#CIHECGHG
and http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#CHDEIDIC

:)

:)

Answer C

You are absolutely right Leonid. I checked the first link they give the Example 5.1 (which is exactly the exam question)

They explain it like this: “Example 5-1 defines a type of associative array indexed by string, declares a variable of that type, populates the variable with three elements, changes the value of one element, and prints the values (in sort order, not creation order).”

–the main thing being: and prints the values (in sort order, not creation order) => which is exactly what the c answer spcifies

DECLARE
— Associative array indexed by string:

TYPE population IS TABLE OF NUMBER — Associative array type
INDEX BY VARCHAR2(64); — indexed by string

city_population population; — Associative array variable
i VARCHAR2(64); — Scalar variable

BEGIN
— Add elements (key-value pairs) to associative array:

city_population(‘Smallville’) := 2000;
city_population(‘Midland’) := 750000;
city_population(‘Megalopolis’) := 1000000;

— Change value associated with key ‘Smallville’:

city_population(‘Smallville’) := 2001;

— Print associative array:

i := city_population.FIRST; — Get first element of array

WHILE i IS NOT NULL LOOP
DBMS_Output.PUT_LINE
(‘Population of ‘ || i || ‘ is ‘ || city_population(i));
i := city_population.NEXT(i); — Get next element of array
END LOOP;
END;
/

Result:

Population of Megalopolis is 1000000
Population of Midland is 750000
Population of Smallville is 2001

dumi

dumi

it is C, not A.

samkelo siyabonga ngubo

samkelo siyabonga ngubo

A

Alessandro Russo

Alessandro Russo

A And C so, it executes succesfully, gives the desired result but in sorted order. Nowhere is specified that the desired result should be in the defined order. isn’t it?

samkelo siyabonga ngubo

samkelo siyabonga ngubo

A,C

Karan

Karan

A and C

Population of megalopolisis1000000
Population of midlandis750000
Population of smallvileeis2001
Population of smallvilleis2000

Tom

Tom

It is A

because the terminology used in ‘C’ is ‘are not STORED in creation order but sorted order’

if this was written as ‘OUTPUT’ rather than stored then ‘C’ would also be correct.

Additionally, the question says ‘which statement’ so it possibly indicates that it is looking for one answer only

Exmr

Exmr

C
because: “Indexes are stored in sort order, not creation order.”