【问题标题】:Receiving ORA-06531 Reference to uninitialized collection error接收 ORA-06531 引用未初始化的收集错误
【发布时间】:2015-02-18 17:37:59
【问题描述】:

我正在运行一个导入文件的函数,我收到以下 Oracle 错误:

ORA-06531:对未初始化集合的引用 ORA-06512:在“BANINST1.SZKPERT”,第 186 行

我已经阅读了我需要初始化集合以避免此错误的其他答案。但是,我不确定我需要初始化什么集合以及应该使用什么语法。下面是函数:

function f_get_pert_examinees (p_filename varchar2)
return baninst1.scf_pert_test_examinee_nt
pipelined 
is
lv_filename     CONSTANT varchar2(50) := p_filename;

lv_examinee_tab lt_download_tab_type;
lv_remote_data  clob;
lv_char         varchar2(1);
lv_eol          boolean := false;
lv_tablen       binary_integer;
lv_list         szkftpx.t_string_table;
type lt_field_tab_type is table of varchar2(50) index by binary_integer;
lv_field_tab    lt_field_tab_type;
type lt_remote_data_tab_type is table of clob index by binary_integer;
lv_remote_data_tab lt_remote_data_tab_type;
begin
  begin
  -- Connect to FTP site and get data from file.
  lv_connection := szkftpx.login(lv_site, lv_port, lv_user, lv_pass);
  szkftpx.ascii(p_conn => lv_connection);

  -- Get a list of files.
  szkftpx.nlst(p_conn  => lv_connection,
               p_dir   => './' || substr(lv_filename,1,20) || '*',
               p_list  => lv_list);

  -- Loop through the files.
  for file_index in 1..lv_list.count
  loop
    begin
      lv_remote_data_tab (file_index) 
        := szkftpx.get_remote_ascii_data (
             p_conn => lv_connection,
             p_file => lv_list(file_index));
    exception
      when others then null;
    end;
  end loop;

  szkftpx.logout(lv_connection);
exception
  when others then null;
end;

/* 这里是第 186 行,就在下面的 FOR 循环中。看起来我可能需要初始化集合“lv_examinee_tab”,但我不确定我应该如何或在代码中的何处执行此操作。 */

for file_index2 in 1..lv_list.count
loop
  if lv_remote_data_tab.exists (file_index2)
  then
    if dbms_lob.getlength(lv_remote_data_tab (file_index2)) > 0
    then
      -- Parse clob into collection.
      lv_examinee_tab := f_clob2tab (lv_remote_data_tab (file_index2));

      -- Loop through collection
      for i in 1..lv_examinee_tab.count
      loop
        lv_field_tab.delete;

        -- Parse each record in collection, putting comma-separated fields in field collection.
        declare
          lv_string        varchar2(2000):=replace(lv_examinee_tab(i),',',', '); 
        begin
          for r in
            (select regexp_substr(lv_string,'[^,]+',1,level) my_field   
               from dual   
            connect by level <= length(regexp_replace(lv_string,'[^,]+')) + 1)   
          loop
            lv_field_tab(lv_field_tab.count + 1) := trim(r.my_field);  
          end loop;
        end;

        if lv_field_tab(1) <> 'Last Modified'
        then
          -- Assemble field in a record and send back to caller.
          pipe row (baninst1.scf_pert_test_examinee(
                      lv_field_tab(1),
                      lv_field_tab(2),
                      lv_field_tab(3),
                      lv_field_tab(4),
                      lv_field_tab(5),
                      lv_field_tab(6),
                      lv_field_tab(7),
                      lv_field_tab(8),
                      lv_field_tab(9),
                      lv_field_tab(10),
                      lv_field_tab(11),
                      lv_field_tab(12),
                      lv_field_tab(13),
                      lv_field_tab(14),
                      lv_field_tab(15),
                      lv_field_tab(16),
                      lv_field_tab(17)));
        end if;
      end loop;
    end if;
  end if;
end loop;

end f_get_pert_examinees;

【问题讨论】:

    标签: oracle plsql


    【解决方案1】:

    看起来更像lv_list 未初始化。 由于exception when others then null;

    ,您不会首先收到错误消息

    你可以初始化它

    lv_list := szkftpx.t_string_table();
    

    为了创建一个空列表。但是,我认为您应该这样做:

    IF lv_list IS NOT NULL THEN
       for file_index2 in 1..lv_list.count loop
       ...
    END IF;
    

    【讨论】:

    • 我添加了初始化语句“lv_list := szkftpx.t_string_table();”正如您在我的函数中的第一个“开始”语句之后建议的那样。但是,for 循环“for file_index in 1..lv_list.count”不会执行循环内的语句,因为“lv_list.count”的值在 for 循环之前为零。
    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 2020-01-25
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 2021-07-16
    相关资源
    最近更新 更多