POSTS

Oracle - ORA-29282: invalid file ID, ORA-06512: at "SYS.UTL_FILE"

Problem:
Connecting to the database APPS_MANPOWER_PLUS_APPS.
ORA-29282: invalid file ID
ORA-06512: at “SYS.UTL_FILE”, line 878
ORA-06512: at “APPS_MANPOWER_PLUS.PKG_UPD_BULK”, line 421
ORA-06512: at line 6
-——————————————————————————-
Process exited.

, generated by:

(…) 
_  begin
    dbms_output.enable(null);
   
    dbms_output.put_line(RPAD(‘-’,80,‘-’));
    utl_file.put_line(lf, RPAD(‘-’,80,‘-’));
   
    l_logfile_name := ‘UPD_XXX’ || ‘_’ || to_char(sysdate, ‘YYYYMMDDHH24MISS’) || ‘.log’;____
    lf := utl_file.fopen(‘OPERATION_LOGS’, l_logfile_name, ‘W’);__
   
    dbms_output.put_line(‘BEGIN: PKG_UPD_BULK.UPD__XXX_‘);
    utl_file.put_line(lf, ‘BEGIN: PKG_UPD_BULK.UPD_
XXX’);_
(…) 

Cause:
Write in the file before first open it. The correct code should be:

(…) 
  begin
    dbms_output.enable(null);
   

    l_logfile_name := ‘UPD_XXX’ || ‘_’ || to_char(sysdate, ‘YYYYMMDDHH24MISS’) || ‘.log’;
    lf := utl_file.fopen(‘OPERATION_LOGS’, l_logfile_name, ‘W’);

_    dbms_output.put_line(RPAD(‘-’,80,‘-’));
    utl_file.put_line(lf, RPAD(‘-’,80,‘-’));
   
    dbms_output.put_line(‘BEGIN: PKG_UPD_BULK.UPD__XXX_‘);
    utl_file.put_line(lf, ‘BEGIN: PKG_UPD_BULK.UPD_
XXX’);_
(…)