Using utl_file package, we can create files if we follow these steps;
As we think we had folder like C:/utl;
1-
alter system set utl_file_dir='C:/utl' scope=spfile;
2-
shutdown immediate
3-
startup
4- test as;
declare
f1 utl_file.file_type;
begin
f1:=utl_file.fopen('C:\utl','test.dat','W');
utl_file.put_line(f1,'memocan');
utl_file.fclose(f1);
end;
ALTERNATIVE – The Preferred Solve
At this solution we do NOT need database shutdown and startup, so as TOM says,
” you don’t need to shutdown the database and restart to add a directory to the list of available
directories for reading/writing. utl_file_dir is not dynamic, directories are. “
Firstly specify directory with;
CREATE OR REPLACE DIRECTORY utl_file_dir AS 'C:/my_utl_file'
Unless shutdown and startup we can use these piece of test code to create our file;
declare
f1 utl_file.file_type;
begin
f1:=utl_file.fopen('UTL_FILE_DIR','test.dat','W');
utl_file.put_line(f1,'memocan');
utl_file.fclose(f1);
end;
Note that you should use ‘UTL_FILE_DIR’ uppercase and also your ‘C:/my_utl_file’ path should be avaible.