CREATE OR REPLACE PACKAGE yearly_list IS
TYPE list1 IS TABLE OF VARCHAR2 (20) INDEX BY PLS_INTEGER;
FUNCTION init_list1 RETURN list1;
END yearly_list;
/
CREATE OR REPLACE PACKAGE BODY yearly_list IS
FUNCTION init_list1 RETURN list1 IS
create_list list1;
BEGIN
create_list(1) := 'Jan';
create_list(3) := 'Feb';
create_list(6) := 'Mar';
create_list(8) := 'Apr';
RETURN create_list;
END init_list1;
END yearly_list;
/
DECLARE
--v_yrl yearly_list.create_list(); --ERROR --line2
v_yrl yearly_list.list1 := yearly_list.init_list1(); --CORRECT
location NUMBER := 1;
BEGIN
WHILE location IS NOT NULL LOOP
DBMS_OUTPUT.PUT_LINE(v_yrl(location) || ' ' || v_yrl.NEXT(location));
--location := v_yrl.NEXT; --ERROR --line7
-- PLS-00306: wrong number or types of arguments in call to 'NEXT'
location := v_yrl.NEXT(location); --CORRECT
END LOOP;
END;
/
Line 2, 6 and 7. Correct code should look like this
DECLARE
v_yrl yearly_list.list1 := yearly_list.init_list1();
location NUMBER := 1;
BEGIN
WHILE location IS NOT NULL LOOP
DBMS_OUTPUT.PUT_LINE(v_yrl(location));
location := v_yrl.NEXT(location);
END LOOP;
END;
Line 2 is wrong because new variable requires type for itself. Line 7 is wrong since collection attribute next requires as input parameter the index of existing element from which we want to find next one like this array.next(curr_index).
Line 3 is fine. Line 2 needs a lot of fixing, but I suspect this question has more issues in it.
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
pmeyer
1 year, 8 months agoAngelos_ang
2 years, 4 months agoRakeshpro
2 years, 4 months agoRakeshpro
2 years, 4 months agoRakeshpro
2 years, 4 months agochrishillinger
2 years, 5 months agoBenjmaz
4 years agosudhirdavim
4 years, 1 month agoCosminCof
4 years, 2 months agojcamt
4 years, 3 months agoDmitryPDN
5 years agoyurijk
5 years agoorakell
5 years, 2 months ago