OracleのPL/SQLでutl_fileを用いてのファイルの読み込みが上手くできずに困っています。やりたい内容は、DBサーバにあるテキストファイルを、PL/SQLのプロシージャで読み込んで内容を表示するというものです。
◆バージョン
OracleDB(11g)
◆OS
Linux CentOS release 6.8 (Final)
◆PL/SQLコード
/* -------------------------------------------------------------------*/
CREATE OR REPLACE
PROCEDURE TEST_20170826
IS
no NUMBER :=10;
read utl_file.file_type;
buf varchar2(1022);
BEGIN
no := no + 100;
DBMS_OUTPUT.PUT_LINE(no);
--Open file in 'Read Mode'
dbms_output.put_line('OK_1');
read := utl_file.fopen('/tmp/plsqltest-20170916/','test.txt','r');
dbms_output.put_line('OK_2');
loop
begin
-- read the file
utl_file.get_line(read,buf);
dbms_output.put_line('data: '||buf);
dbms_output.put_line('OK_3');
exception
-- end the loop when we come to the end of file
when no_data_found then
dbms_output.put_line('ER-0001 : Fail To Read The File');
exit;
end;
end loop;
-- file close
utl_file.fclose(read);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('ER-0000 : Other Exception');
END TEST_20170826;
/* -------------------------------------------------------------------*/
◆実行結果
Connecting to the database TESTUSR.
110
OK_1
ER-0000 : Other Exception
Process exited.
Disconnecting from the database TESTUSR.

回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2017/09/16 12:10