oracle 如何在 SQL Developer 中读取本地文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6254256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:53:04  来源:igfitidea点击:

how do I read a local file in SQL Developer?

oracleinputplsqloracle-sqldeveloperutl-file

提问by user786149

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:

当我在 Oracle SQL developer 中执行查询时,我想读取本地机器上包含查询参数的文件。到目前为止,我在网上找到的例子是不够的。当我执行以下代码时,我不断收到“ORA-29283:无效文件操作”错误:

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;

回答by Justin Cave

UTL_FILEcan 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.

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

回答by APC

"I want to read a file on my local machine that contains query parameters when I execute a query in Oracle SQL developer."

“当我在 Oracle SQL developer 中执行查询时,我想在我的本地机器上读取一个包含查询参数的文件。”

This seems an unusual - I was going to say 'peculiar' -architectural decision. Where do these values comne from? Why do thay have to be stored in a file? How often do they change?

这似乎是一个不寻常的 - 我要说的是“特殊的” - 架构决定。这些价值观从何而来?为什么必须将它们存储在文件中?他们多久更换一次?

It is going to be very difficult to expose the contents of a local PC file to a remote database server (i.e. we're talking automating it with ftpor a manual process involving something like WinSCP).

将本地 PC 文件的内容暴露给远程数据库服务器将是非常困难的(即,我们正在谈论ftp使用诸如 WinSCP 之类的东西将其自动化或手动过程)。

On the other hand, it could be quite simple to apply some query parameters to a query; for instance by using SYS_CONTEXT and namespaces. But I need to know more details before I can provide an alternative solution.

另一方面,将一些查询参数应用于查询可能非常简单;例如通过使用 SYS_CONTEXT 和命名空间。但在提供替代解决方案之前,我需要了解更多细节。