第一步:以管理员用户登陆
如:conn sys/password@sid as sysdba
第二步:设置可操作目录
需要指定utl_file包可以操作的目录。在oracle 10g以前,可以用以下方法:
1、alter system set utl_file_dir=e:\utl scope=spfile;
2、在init.ora文件中,配置如下:
utl_file=e:\utl或者utl_file_dir=e:\utl
在oracle 10g中建议用以下方法配置:create directory utl as e:\utl;
参见oracle online:
in the past, accessible directories for the utl_file functions were specified in the initialization file using the utl_file_dir parameter. however, utl_file_dir access is not recommended. it is recommended that you use the create directory feature, which replaces utl_file_dir. directory objects offer more flexibility and granular control to the utl_file application administrator, can be maintained dynamically (that is, without shutting down the database), and are consistent with other oracle tools. create directory privilege is granted only to sys and system by default.
第三步:授权给指定用户,以便执行utl_file
grant execute on utl_file to scott;
第四步:conn scott/tiger
就可以正常使用utl_file了。