Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NULL assigning to associative array

I wanted to assign NULL to an associative array. How can I do it?

TYPE t_test IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
l_arr t_test;
l_arr:=NULL-- Which is giving error.
like image 259
TBose Avatar asked Oct 14 '25 18:10

TBose


1 Answers

I want to empty it.

Use the delete collection method:

l_arr.delete;

Or if I want to assign a particular position as null, in that can also how can I do it then?

Just assign null to that position:

l_arr(2) := null;

You can also delete a specific position:

l_arr.delete(1);

Demo of both:

declare
  type t_test is table of pls_integer index by pls_integer;
  l_arr t_test;

  procedure show(p_label varchar2) is
    l_idx pls_integer;
  begin
    dbms_output.new_line;
    dbms_output.put_line(p_label || ': count = ' || l_arr.count);
    l_idx := l_arr.first;
    while l_idx is not null loop
      dbms_output.put_line('  ' || l_idx || ' -> ' || l_arr(l_idx));
      l_idx := l_arr.next(l_idx);
    end loop;
  end show;
begin
  l_arr(1) := 1;
  l_arr(42) := 42;

  show('a');

  l_arr(2) := null;
  show('b');

  l_arr.delete(1);
  show('c');

  l_arr.delete;
  show('d');
end;
/
a: count = 2
  1 -> 1
  42 -> 42

b: count = 3
  1 -> 1
  2 -> 
  42 -> 42

c: count = 2
  2 -> 
  42 -> 42

d: count = 0


PL/SQL procedure successfully completed.
like image 156
Alex Poole Avatar answered Oct 18 '25 05:10

Alex Poole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!