2

Oracle SQL 開発者でクエリを実行するときに、クエリ パラメータを含むファイルをローカル マシンで読み取りたいと考えています。これまでウェブで見つけた例は不十分です。以下のコードを実行すると、「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;
4

2 に答える 2

4

UTL_FILEデータベースサーバーに保存されているファイルからのみデータを読み取ることができます。これは PL/SQL コードであるため、データベース サーバー上で実行され、データベース サーバー上の Oracle プロセスで使用できるリソースにのみアクセスできます。

于 2011-06-06T15:27:53.317 に答える
0

"I want to read a file on my local machine that contains query parameters when I execute a query in 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 ftp or a manual process involving something like 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.

于 2011-06-06T18:41:42.830 に答える