UTL_FILE.FOPEN in the UTL_FILE package provided by Oracle is responsible for opening a file.
UTL_FILE.FOPEN (location in varchar2, filename in varchar2, open_mode in varchar2) return FILE_TYPE;
Location is the path parameter,
FILENAME is the file name,
OPEN_MODE is the open mode, 'R' is the read text, 'w' is the write text, and 'A' is the additional text. The parameter is case-insensitive. If 'A' is specified but the file does not exist, it is created with 'W', and 'w' has the overwriting function;
The location cannot be simply specified as a path such as 'd: \ temp. You need to create a DIRECTORY variable and pay the permission (you must Log On As a dba ):
SQL code
- Create Or ReplaceDirectory D_OUTPUTAs 'D: \ TEMP';
- Grant Read, WriteOnDirectory D_OUTPUTToTestdb;
- GRANT EXECUTE ONUtl_fileTOTestdb;
Then you can use the UTL_FILE package to create a file.
SQL code
- V_FILE UTL_FILE.FILE_TYPE;
- V_FILE: = UTL_FILE.FOPEN ('D _ output','Data.txt','W');
You can create data.txt on the database server's D: \ temp.