We help IT Professionals succeed at work.
Get Started

Need help on plsql varray

sam_2012
sam_2012 asked
on
121 Views
Last Modified: 2020-02-24
Hi Team ,

iam running the below program on oracle varray . I need to print the current element , previous element in the dbms_output statement. But i get the below error  when i run the program

Error starting at line 2 in command:
declare
type v_numvarr  is varray(10) of number;
l_numvarr v_numvarr;
cnt simple_integer:=1;
begin

l_numvarr :=v_numvarr();
l_numvarr.extend;
l_numvarr(1):=10;
l_numvarr.extend;
l_numvarr(2):=20;
l_numvarr.extend(8);
l_numvarr(3):=30;
l_numvarr(4):=40;
l_numvarr(5):=50;
l_numvarr(6):=60;
l_numvarr(7):=70;
l_numvarr(8):=80;
l_numvarr(9):=90;
l_numvarr(10):=100;
-- l_numvarr(11):=110 this will cause an error , because we are accessing invalid index  position , the maximum numbe is 10 , we are accessing 11
dbms_output.put_line ('The total size of the array is: '||l_numvarr.limit);

/*
for i in l_numvarr.first..l_numvarr.last
loop
dbms_output.put_line ('The element at index position ('||i||') is:' || l_numvarr(i));
end loop;
*/

l_numvarr.trim;

for i in l_numvarr.first..l_numvarr.last
loop

dbms_output.put_line ('The element at index position ('||i||') is:' || l_numvarr(i) ||l_numvarr(l_numvarr(l_numvarr.prior(i))) );

end loop;

/*
l_numvarr.trim(2);


for i in l_numvarr.first..l_numvarr.last
loop

dbms_output.put_line ('The element at index position ('||i||') is:' || l_numvarr(i));

end loop;*/
end;
Error report:
ORA-06502: PL/SQL: numeric or value error: NULL index table key value
ORA-06512: at line 36
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    
*Action:





--- Program


declare
type v_numvarr  is varray(10) of number;
l_numvarr v_numvarr;
cnt simple_integer:=1;
begin

l_numvarr :=v_numvarr();
l_numvarr.extend;
l_numvarr(1):=10;
l_numvarr.extend;
l_numvarr(2):=20;
l_numvarr.extend(8);
l_numvarr(3):=30;
l_numvarr(4):=40;
l_numvarr(5):=50;
l_numvarr(6):=60;
l_numvarr(7):=70;
l_numvarr(8):=80;
l_numvarr(9):=90;
l_numvarr(10):=100;
-- l_numvarr(11):=110 this will cause an error , because we are accessing invalid index  position , the maximum numbe is 10 , we are accessing 11
dbms_output.put_line ('The total size of the array is: '||l_numvarr.limit);

/*
for i in l_numvarr.first..l_numvarr.last
loop
dbms_output.put_line ('The element at index position ('||i||') is:' || l_numvarr(i));
end loop;
*/

l_numvarr.trim;

for i in l_numvarr.first..l_numvarr.last
loop

dbms_output.put_line ('The element at index position ('||i||') is:' || l_numvarr(i) ||  ' Previous element :'||   l_numvarr(l_numvarr(l_numvarr.prior(i))) );

end loop;

/*
l_numvarr.trim(2);


for i in l_numvarr.first..l_numvarr.last
loop

dbms_output.put_line ('The element at index position ('||i||') is:' || l_numvarr(i));

end loop;*/
end;
/
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE