当前位置: 代码迷 >> Oracle开发 >> oracle 的dump_cvs过程导出数据到cvs报错,多谢
  详细解决方案

oracle 的dump_cvs过程导出数据到cvs报错,多谢

热度:89   发布时间:2016-04-24 07:19:26.0
oracle 的dump_cvs过程导出数据到cvs报错,谢谢!
在我本地执行这存储过程可以正常生成csv文件,拿到生产库上就报下面的错误:

执行dump_cvs过程报ora-04063:pakage body "SYS.UTL_FILE"有错误

ora-06508: PL/SQL: 无法找到正在调用:"SYS.UTL_FILE" 的程序单元

报错位置在l_output := utl_file.fopen(p_dir, p_filename, 'w',P_MAX_LINESIZE)

过程的代码如下:

create or replace procedure dump_csv(p_query in varchar2,

  p_dir in varchar2,
  p_filename in varchar2)
  AUTHID CURRENT_USER is
  l_output utl_file.file_type;
  l_theCursor integer default dbms_sql.open_cursor;
  l_columnValue varchar2(2000);
  l_status integer;
  l_colCnt number default 0;
  l_separator varchar2(10) default ' ';
  l_cnt number default 0;
  P_MAX_LINESIZE NUMBER := 320000;
  L_DESCTBL DBMS_SQL.DESC_TAB;
  p_separator varchar2(10) default ',';
begin
  l_output := utl_file.fopen(p_dir, p_filename, 'w',P_MAX_LINESIZE);

  dbms_sql.parse(l_theCursor, p_query, dbms_sql.native);
  DBMS_SQL.DESCRIBE_COLUMNS( L_THECURSOR, L_COLCNT, L_DESCTBL );
  FOR I IN 1 .. L_COLCNT LOOP
  UTL_FILE.PUT( L_OUTPUT, L_SEPARATOR ||'"'|| L_DESCTBL(I).COL_NAME||'"' );
  DBMS_SQL.DEFINE_COLUMN( L_THECURSOR, I, L_COLUMNVALUE, 4000 );
  L_SEPARATOR := ',';
  END LOOP;
  UTL_FILE.NEW_LINE( L_OUTPUT );

  for i in 1 .. 255 loop
  begin
  dbms_sql.define_column(l_theCursor, i, l_columnValue, 2000);
  l_colCnt := i;
  exception
  when others then
  if (sqlcode = -1007) then
  exit;
  else
  raise;
  end if;
  end;
  end loop;

  --dbms_sql.define_column(l_theCursor, 1, l_columnValue, 2000);

  l_status := dbms_sql.execute(l_theCursor);

  loop
  exit when(dbms_sql.fetch_rows(l_theCursor) <= 0);
  l_separator := '';
  for i in 1 .. l_colCnt loop
  DBMS_SQL.COLUMN_VALUE( L_THECURSOR, I, L_COLUMNVALUE );
  UTL_FILE.PUT( L_OUTPUT, L_SEPARATOR || '"' ||
  TRIM(BOTH ' ' FROM REPLACE(L_COLUMNVALUE,'"','""')) || '"');
  l_separator := p_separator;
  end loop;
  utl_file.new_line(l_output);
  l_cnt := l_cnt + 1;
  end loop;
  dbms_sql.close_cursor(l_theCursor);

  utl_file.fclose(l_output);
  --return l_cnt;
end dump_csv;


------解决方案--------------------
sqlplus / as sysdba进去
先查下
select * from dba_objects where object_name='UTL_FILE';

看下status字段有没有变成invalid。

如果是package或者package body 变成invalid,
ALTER PACKAGE UTL_FILE COMPILE;
试试看行不行。

如果是public synonym 变成invalid,
试试看
create or replace public synonym utl_file for utl_file;
  相关解决方案