Oracle Database: Program with PL/SQL — Question 69
Which two blocks of code execute successfully?
Answer options
- A. DECLARE TYPE tab_type IS TABLE OF NUMBER; my_tab tab_type; BEGIN my_tab (1) :=1; END;
- B. DECLARE TYPE tab_type IS TABLE OF NUMBER; my_tab tab_type := tab_type(2); BEGIN my_tab(1) :=55; END;
- C. DECLARE TYPE tab_type IS TABLE OF NUMBER; my_tab tab_type; BEGIN my_tab. EXTEND (2); my_tab (1) := 55; END;
- D. DECLARE TYPE tab_type IS TABLE OF NUMBER; my_tab tab_type; BEGIN my_tab := tab_type (); my_tab (1) := 55; END;
- E. DECLARE TYPE tab_type IS TABLE OF NUMBER my_tab tab_type := tab_type (2, NULL, 50); BEGIN my_tab.EXTEND (3, 2);
Correct answer: B, D
Explanation
Options B and D are correct because they properly initialize the collection before accessing its elements. Option A fails because it attempts to assign a value to an uninitialized element, while C encounters an issue trying to extend the collection without having initialized it first. Option E has a syntax error due to a missing semicolon after the type declaration.