Open once youve created the directory
Following are some examples:
• In Windows:
Working with Oracle Directories
Prior to Oracle9i Database Release 2, whenever you opened a file, you needed to specify the location of the file, as in the preceding examples. Such a hardcoding of values is always to be avoided, however. What if the location of the accounts data changes? How many programs will you have to fix to make sure everyone is looking in the right place? How many times will you have to make such changes?
CONSTANT VARCHAR2(30) := '/accts/data';
...
file_id := UTL_FILE.fopen (accts_pkg.c_data_location, 'trans.dat', 'R');
END;
Reading and Writing Files | | | 931 |
---|
Here are some things to keep in mind about directories and UTL_FILE:
• The Oracle database does not validate the location you provide when you specify the name of a directory. It simply associates that string with the named database object.
• Once you’ve created the directory, you can grant specific users permission to work with it as follows:
GRANT READ ON DIRECTORY development_dir TO senior_developer;
Before you can read or write a file, you must open it. The UTL_FILE.FOPEN function opens the specified file and returns a file handle you can then use to manipulate the file.
Here’s the header for the function:
932 | | |
---|