如何在SQL Developer中读取本地文件? [英] how do I read a local file in SQL Developer?

查看:351
本文介绍了如何在SQL Developer中读取本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Oracle SQL Developer中执行查询时,我想在本地计算机上读取一个包含查询参数的文件.到目前为止,我在网上发现的示例还不够.执行以下代码时,我不断收到"ORA-29283:无效的文件操作"错误:

I want to read a file on my local machine that contains query parameters when I execute a query in Oracle SQL developer. The examples that I've found on the web so far are inadequate. I keep getting "ORA-29283: invalid file operation" errors when I execute the below code:

CREATE DIRECTORY SAMPLEDATA2 AS 'C:';
GRANT READ, WRITE ON DIRECTORY SAMPLEDATA2 TO PUBLIC;


declare
f utl_file.file_type;
s varchar2(200);
c number := 0;

BEGIN

f := utl_file.fopen('SAMPLEDATA2','sample2.txt','R');
loop
    utl_file.get_line(f,s);
    dbms_output.put_line(s);
    c := c + 1;
end loop;

exception
    when NO_DATA_FOUND then
        utl_file.fclose(f);
        dbms_output.put_line('Number of lines: ' || c);
end;

推荐答案

UTL_FILE只能从数据库服务器上存储的文件中读取数据.由于它是PL/SQL代码,因此它在数据库服务器上运行,并且只能访问数据库服务器上Oracle进程可用的资源.

UTL_FILE can only read data from files that are stored on the database server. Since it is PL/SQL code, it runs on the database server and only has access to the resources that are available to the Oracle process on the database server.

这篇关于如何在SQL Developer中读取本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆