PL / SQL关联数组验证索引是否存在

时间:2013-12-03 13:30:59

标签: arrays plsql plsqldeveloper

我有这个关联数组3-d

type v_arr_class is table of varchar2(255) index by varchar2(255);
type v_arr_component is table of v_arr_class index by varchar2(255);
type v_arr_property is table of v_arr_component index by varchar2(255);

v_arr_local_rec v_arr_property;

我需要验证索引是否存在

if(v_arr_local_rec('class')('component')('property') exist) then

do this... 

end if

找不到关联数组的信息。

提前感谢。

1 个答案:

答案 0 :(得分:6)

您必须执行3次存在测试,以确保不会触发NO_DATA_FOUND错误:

SQL> DECLARE
  2     TYPE t_arr_class IS TABLE OF VARCHAR2(255) INDEX BY VARCHAR2(255);
  3     TYPE t_arr_component IS TABLE OF t_arr_class INDEX BY VARCHAR2(255);
  4     TYPE t_arr_property IS TABLE OF t_arr_component INDEX BY VARCHAR2(255);
  5     v_arr_local_rec t_arr_property;
  6  BEGIN
  7     IF v_arr_local_rec.EXISTS('class')
  8        AND v_arr_local_rec('class').EXISTS('component')
  9        AND v_arr_local_rec('class')('component').EXISTS('property')
 10     THEN
 11        dbms_output.put_line('true');
 12     ELSE
 13        dbms_output.put_line('false');
 14     END IF;
 15  END;
 16  /

false

PL/SQL procedure successfully completed