【发布时间】:2018-03-19 10:44:41
【问题描述】:
我想使用 Oracle SQL 或 PL SQL 读取位于 FTP 或 SFTP 服务器上的 .csv 文件的数据。 我尝试了下面的代码,它显示了 SSH-2.0-OpenSSH_5.3 之类的输出,这意味着我希望已连接。
declare
c utl_tcp.connection; -- TCP/IP connection to the Web server
ret_val pls_integer;
BEGIN
c := utl_tcp.open_connection(remote_host => 'ftp.******.******.com'
,remote_port => 21
,charset => 'US7ASCII'
-- ,wallet_path => '****************'
-- ,wallet_password => '**********'
); -- open connection
-- ret_val := utl_tcp.write_line(c, 'GET / HTTP/1.0'); -- send HTTP request
ret_val := utl_tcp.write_line(c);
BEGIN
LOOP
dbms_output.put_line(utl_tcp.get_line(c, TRUE)); -- read result
END LOOP;
EXCEPTION
WHEN utl_tcp.end_of_input THEN
NULL; -- end of input
END;
utl_tcp.close_connection(c);
END;
/
有人可以帮助我了解如何打开和读取 SFTP/FTP 服务器中存在的 .csv 文件并将其加载到 Oracle DB 表中吗?
【问题讨论】:
-
如果您有相关设置,您可以使用
UTL_TCP和UTL_FILE的组合。阅读oracle-base.com/articles/misc/ftp-from-plsql 以获得解释。