我必须创建包含三个程序的程序包,这些程序会将另一个函数的结果写入文件。函数 get_cursor(...) return sys_refcursor 如下所示:
function get_cursor(
tabname in varchar2,
cols in array_t,
vals in array_t,
rels in array_t )
return sys_refcursor
is
cur sys_refcursor;
where_statement varchar2(1000);
tmp varchar2(1000);
begin
if cols.last != 0 then
where_statement := 'WHERE ' || cols(1) || ' ' || rels(1) || ' ';
if (rels(1) = 'in' or rels(1) = 'not in') then
where_statement := where_statement || trim(both '''' from vals(1));
elsif (utils.is_number(vals(1)) = 'N' and substr( vals(1), 1, 8 ) != 'TO_DATE(') then
where_statement := where_statement || '''' || vals(1) || '''';
else
where_statement := where_statement || vals(1);
end if;
for i in 2..cols.last
loop
where_statement := where_statement || ' AND ' || cols(i) || ' ' || rels(i) || ' ';
if (rels(i) = 'in' or rels(i) = 'not in') then
where_statement := where_statement || trim(both '''' from vals(i));
elsif ( utils.is_number(vals(i)) = 'N' and substr( vals(i), 1, 8 ) != 'TO_DATE(') then
where_statement := where_statement || '''' || vals(i) || '''';
else
where_statement := where_statement || vals(i);
end if;
end loop;
end if;
open cur for 'SELECT * FROM ' || tabname || ' ' || where_statement;
return cur;
end get_cursor;
它是否正常工作并不重要,它会返回一些东西,我必须将它写入过程中的文件,该过程将采用与 get_cursor 采用 + 路径和文件名相同的参数:
procedure txt_export(
tabname in varchar2,
cols in array_t,
vals in array_t,
rels in array_t,
path in varchar2,
file_name in varchar2)
is
l_file utl_file.file_type;
tmp_file_name varchar2(4000) := file_name;
begin
if (tmp_file_name like '%.txt') then
l_file := utl_file.fopen(path, tmp_file_name, 'w');
elsif (tmp_file_name not like '%.txt') then
tmp_file_name := tmp_file_name || '.txt';
l_file := utl_file.fopen(path, tmp_file_name, 'w');
end if;
/*
run function get_cursor(tabname, cols, vals, rels) and write result to the file .txt
*/
utl_file.fclose(l_file);
end;
请帮我解决这个问题。对不起我的英语:)
问候!