Oracle 10G Directory的使用
    
              首先介绍两个 术语:目录(directory),UTL_FILE包,在使用ORACLE 的使用我们可以通过DBMS_OUTUT包 来将信息输出到 显示器,但是不能进行磁盘的IO操作,但是我们可以通过UTL_FILE来进行磁盘的IO操作,但是 UTL_FILE必须 使用自己信任的目录 就是DIRECTORY,在10G 中可以使用UTL_FILE_DIR来设置 信任的目录,这个参数 是一个静态参数 所以修改的时候需要使用 alter system set.  scope=spfile然后充气数据库才可以起效, 推荐使用 create DIRECTORY 方便管理
 
             几个数据字典: DBA_DIRECTORIES,ALL_DIRECTORIES
 
            
SQL>     select * from dba_directories;

OWNER                                                    DIRECTORY_NAME                                 DIRECTORY_PATH
------------------------------ ------------------------------ ----------------------------------------------------------------------                                                    ----------------------------------------------------------------------------------------------------------------------
SYS                                                        WORK_DIR                                             /ade/srvasan_SHIP_solx86_060204.010_B/oracle/ work
SYS                                                        DATA_PUMP_DIR                                    /seconddisk/root/oracle/product/10.2.0/db_1/admin/orcl/dpdump/
SYS                                                        ADMIN_DIR                                            /ade/srvasan_SHIP_solx86_060204.010_B/oracle/md/admin

SQL> ! ls /thirddisk/root/utl_dir

SQL> create directory dir_1 as '/thirddisk/root/utl_dir/dir_1';

Directory created.

SQL>     select * from dba_directories;

OWNER                                                    DIRECTORY_NAME                                 DIRECTORY_PATH
------------------------------ ------------------------------ ----------------------------------------------------------------------                                                    ----------------------------------------------------------------------------------------------------------------------
SYS                                                        DIR_1                                                    /thirddisk/root/utl_dir/dir_1
SYS                                                        WORK_DIR                                             /ade/srvasan_SHIP_solx86_060204.010_B/oracle/ work
SYS                                                        DATA_PUMP_DIR                                    /seconddisk/root/oracle/product/10.2.0/db_1/admin/orcl/dpdump/
SYS                                                        ADMIN_DIR                                            /ade/srvasan_SHIP_solx86_060204.010_B/oracle/md/admin
分配 目录dir_1的权限给 scott
SQL> grant read,write on directory dir_1 to scott;

Grant succeeded.
下面进入scott/tiger
演示 对 目录DIR_1 进行IO操作
脚本:
SQL> l
    1     declare
    2         filehandler utl_file.file_type;
    3     begin
    4         filehandler:=utl_file.fopen( 'DIR_1', 'text.txt', 'w');
    5         utl_file.put_line(filehandler, 'fadsfadfdfa');
    6         utl_file.fclose(filehandler);
    7* end;
SQL> /
执行 出错误
SQL> /
declare
*
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 475
ORA-29283: invalid file operation
ORA-06512: at line 4
我们上面的 create directory不会 创建OS 文件 只是在 数据字典添加了数据
所以 需要手动添加文件 DIR_1 ,注意OS文件的读写全蝎
就可以执行成功了
注意:
        utl_file.fopen()里面"DIR_1"需要大写 因为 DBA_DIRECTORIES里面记录的都是大写的