求助高手:
在pl/sql中我只要使用utl_file内置程序包读写文件,就会报错:原程序:
declare
l_input varchar2(100);
l_file utl_file.file_type;
begin
l_input := '&字符';
l_file := utl_file.fopen('SMYDIR','sample.txt','w');
utl_file.put(l_file,l_input);
utl_file.fclose(l_file);
end;
/错误信息:
declare
*
ERROR 位于第 1 行:
ORA-06510: PL/SQL: 无法处理的用户自定义异常事件
ORA-06512: 在"SYS.UTL_FILE", line 120
ORA-06512: 在"SYS.UTL_FILE", line 204
ORA-06512: 在line 6

解决方案 »

  1.   

    utl_file内置程序包只能运行在数据库服务端。utl_file_dir制定为*
      

  2.   

    我试了,Oracle9.0不行,但9.2可以.都是在服务器上操作,不知道什么原因!!!
      

  3.   

    在oracle9.2上,使用目录名可以访问,但在9.0上就不能使用目录名,报错:目录或文件不存在,或者是用户无法处理自定义错误。要想在9.0上使用UTL_FILE,则应在..pfile/init.ora里最后添加一选项utl_file_dir=*。此参数的意思是可以读取服务器上的任何目录。这样,你就可以使用路径直接用了
      

  4.   

    utl_file_dir=*
    设置了也还是报错呢?
    楼主解决了吗?
      

  5.   

    第一步:以管理员用户登陆
    如: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了。