我有一个CSV文件,其中有2,000,000条记录插入到一个表(blob列)中。我试图创建以下块:
DECLARE
v_doc BLOB;
v_file_content CLOB;
zip_files as_zip.file_list;
BEGIN
--Get file corresponding to process in progress
SELECT
file_content
INTO v_doc
FROM
int_dat_journals_cv027_files
WHERE
file_name = 'in_gl_journals_20230322101527_v3.zip' -->This value is dynamic
AND id_proceso_oic = '1'; -->This value is dynamic
--Get Files from .zip file
zip_files := as_zip.get_file_list(v_doc);
--Iterate each file from .zip file
FOR i IN zip_files.first()..zip_files.last LOOP
--convert blob file to clob
SELECT
blob_to_clob_fn(as_zip.get_file(v_doc, zip_files(i)))
INTO v_file_content
FROM
dual;
--dbms_output.put_line(v_file_content);
--iterate and split line by line by chr(10), for example:'a,b,c,,,f,g'
FOR linea IN (
SELECT
TRIM(column_value) l
FROM
dual,
xmltable ( ( '"'
|| replace(v_file_content, CHR(10), '","')
|| '"' ) )
) LOOP
dbms_output.put_line(linea.l);
END LOOP;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('ERROR: ' || sqlerrm);
dbms_output.put_line(dbms_utility.format_error_backtrace);
END;
我需要特别优化这个部分,以便能够处理数百万条记录:
FOR line IN(select TRIM(column_value)l DESDE dual,xmltable(('"'||replace(v_file_content,CHR(10),'",“')||“))LOOP dbms_output.put_line(line.l);末端回路;
如何进行优化?
1条答案
按热度按时间bn31dyow1#
你不需要这样做。你可以尝试使用csv作为外部表。或者,如果你想索引它,或者有效地使用它,你必须复制数据到另一个表。
如果文件位置在此处,则为csv_dir/yourfile.csv