我正在运行一个导入文件的函数,我收到以下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行,正好在下面的循环中。它看起来像我可能需要初始化收集“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;
答案 0 :(得分:2)
看起来更像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;