UTL_FILE:无法创建新文件 [英] UTL_FILE: Could not create a new file
本文介绍了UTL_FILE:无法创建新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在ly代码中使用此语句来创建/打开à文件:如果尚不存在则创建它/如果已经存在则将其打开.
I'm using this statement in ly code to create/open à file: create it if does not exist yet/open it if already exists.
w_file_handle := utl_file.fopen ('SAUV_DIR',
'sauv_tab_tbrcs_params.txt' ,
'W') ;
该文件尚不存在,但无法创建.
The file doesn't exist yet but it couldn't be created.
我收到此错误:
SQL> @MyScript.sql
declare
*
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 14
如果尚不存在创建文件的任何想法?
Any ideas to create the file if doesn't exist yet?
推荐答案
您可以引用此代码在目录中创建文件.
You can refer this code to create a file in your directory.
我使用以下代码创建了一个tt.sql文件.我检查了我的工作目录是否为"BDUMP".
I created a tt.sql file with the below code. I checked that i have a working directory 'BDUMP`.
目录检查:
SQL> SELECT DIRECTORY_NAME , DIRECTORY_PATH FROM DBA_DIRECTORIES WHERE DIRECTORY_NAME = 'BDUMP';
DIRECTORY_NAME DIRECTORY_PATH
------------------------------ ---------------
BDUMP /home/fil_test/
更改目录权限.默认情况下,它仅对他人具有读取和执行权限.
Change directory permission. By default it has only Read and execute permission for others.
terminal$ chmod 777 fil_test
阻止:
DECLARE
fHandle UTL_FILE.FILE_TYPE;
BEGIN
fHandle := UTL_FILE.FOPEN ('BDUMP', 'test_file', 'w');
UTL_FILE.PUT (fHandle, 'This is the first line');
UTL_FILE.PUT (fHandle, 'This is the second line');
UTL_FILE.PUT_LINE (fHandle, 'This is the third line');
UTL_FILE.FCLOSE (fHandle);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE (
'Exception: SQLCODE=' || SQLCODE || ' SQLERRM=' || SQLERRM);
RAISE;
END;
/
执行:
SQL> @tt.sql
PL/SQL procedure successfully completed.
然后我看到创建的文件:
And i See the file created:
terminal$ ls -lrt test_file*
-rw-r----- 1 oracle dba 68 Oct 24 14:49 test_file
这篇关于UTL_FILE:无法创建新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文