【问题标题】:NULL assigning to associative arrayNULL 分配给关联数组
【发布时间】:2020-12-04 07:01:27
【问题描述】:

我想将 NULL 分配给关联数组。我该怎么做?

TYPE t_test IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
l_arr t_test;
l_arr:=NULL-- Which is giving error.

【问题讨论】:

  • 关联数组不能为空;您的意思是要清空它,还是将特定位置指定为空?
  • 我想清空它。或者,如果我想将特定位置分配为空,那我该怎么做呢?

标签: oracle plsql collections associative-array


【解决方案1】:

我想清空它。

使用delete collection method

l_arr.delete;

或者如果我想将特定位置分配为null,那我也可以怎么做呢?

只需将 null 分配给该位置:

l_arr(2) := null;

您还可以删除特定位置:

l_arr.delete(1);

两者的演示:

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.

【讨论】:

    猜你喜欢
    • 2010-12-21
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    相关资源
    最近更新 更多