【问题标题】:Oracle 11 pl/sql read values from a CSV file to a temp tableOracle 11 pl/sql 从 CSV 文件读取值到临时表
【发布时间】:2017-08-18 18:45:55
【问题描述】:

我需要使用 CSV 文件中的值更新现有表中的值。匹配仅适用于原始 CSV 文件。使用现有的加载过程,我需要读取的值不会被解析。我在 x 列中有两个内容不同的 CSV 文件。在将第二个加载到DB之前,我想根据文件2中的数据更新DB中的值,列x,以便仍然可以匹配。如何简单地将 CSV 文件 2 与 utl 文件读取到临时表中?

【问题讨论】:

  • 你可以使用 SQL*Loader

标签: csv plsql oracle11g temp-tables import-from-csv


【解决方案1】:

要在 plsql 中读取文件,您应该执行以下步骤, 1.您应该创建一个objet目录。一个

create directory dir_tmp as ‘c:\temp’;
grant read, write on directory dir_tmp to user;

2.阅读。

create or replace procedure reading is
v_file utl_file.file_type;
v_line varchar2(1024);
begin
v_file := utl_file.fopen (‘DIR_TMP’, ‘test_utl_file.txt’,‘r’);
loop
utl_file.get_line (v_file, v_line);
dbms_output.put_line (v_line);
end loop;
utl_file.fclose(v_file);

exception
when no_data_found then
dbms_output.put_line (‘End file’);
end;
/

3.- 有几个异常有用的ea。

utl_file.invalid_operation
utl_file.access_denied

腐蚀

【讨论】:

  • 只是给以后看到这个的任何人的注释,因为我浪费了一些时间试图完成这项工作而没有意识到:您只能使用运行 oracle 的机器本地的目录和文件.希望这可以帮助那里的人。