转 UTL_FILE Throws ORA-29284 Or ORA-29283 When Attempting To READ File

APPLIES TO:

PL/SQL - Version 9.2.0.8 and later
Information in this document applies to any platform.
*** Checked for relevance on 26th Dec 2018 ***

SYMPTOMS

1. Error occurs only when reading a file using UTL_FILE. 
 
 
ERROR at line x:
ORA-29284: file read error
ORA-06512: at line x 
 
Where x can be any line number. 
 
 
2. Truss file shows a block of file is read and subsequent blocks cannot be read or corrupted because of NLS (ORA_NLS10) settings.  
 
For example truss file can show one or several of the following symptoms during or after the first read of block size of 1024: 
 
 
file read error 
file write error 
internal error 
invalid maximum line size 
invalid file name 
directory access denied 
invalid offset specified for seek 
file remove operation failed 
file rename operation failed 
A stream error occurred during compression or uncompression. 
A data error occurred during compression or uncompression. 
invalid mime header tag 
invalid encoded string 
The compressed representation is too big
 
 
3. Incorrect Directory path at Database and OS. 
 
4. Incorrect file format.  i.e., Integrity of the file is the being read or write.  

CHANGES

- New application using UTL_FILE to read file. 
- Existing application roll over after parameter change. 
- Changes in environment (.profile file or spfile or init files or APPS environment) affecting NLS related settings change. 

CAUSE

Conflict with the ORA_NLS10 settings.  These changes are hard to detect when there's a .profile file or spfile or init files or APPS environment are involved.  Session level settings do not have any impact on UTL_FILE because UTL_FILE is a server side package.  Truss files can pickup the actual settings used but still it does not show what character set was actually used when the Listener was originally started or when the Database was originally started.  
 
ORA_NLS10 setting is often a cause for ORA-29283 error, and that the error may very well be intermittent due to dynamic effect of ORA_NLS10.
 
Bug 6748861 (Not a Bug), Bug 9322463 (Not a Bug) and Bug 6164955 (APPS) - Incorrect ORA_NLS10 environment setting.  
 
Additional details on how to generate a truss can be found in the MOS Document  Note 28588.1  Using Truss/Trace on Unix.

SOLUTION

1. When making changes to the ORA_NLS10 environment variable, be it to set or unset.  It has to be consistent at Database (DB) and Listener level.  NLS level settings changed using ALTER SYSTEM are not effective for UTL_FILE.   UTL_FILE spawns the settings from the DB and the listener when it was originally started.  Changes at initialization file (spfile or init) are effective when the DB is bounced and listener is restarted.  
 
a. The Database (DB) must be stopped and restarted after the change. 
 
b. The Oracle listener must be stopped and restarted after the change. 
 
If you are not sure about the current ORA_NLS10 or if there are any inconsistency between the time of when the listener was originally started.  Unset the ORA_NLS10 at listener level.  
 
 
- Depending on your OS: unset ORA_NLS10 (or) export ORA_NLS10= 
 
- echo $ORA_NLS10; -- it should not give any value 
 
- lsnrctl stop <listener name>
 
- lsnrctl start <listener name>
 
 
Mostly issues raise when there are inconsistent ORA_NLS10 language setting.  
 
c. The Application must be stopped and restarted after the change. 
 
To ensure that all process are using the same settings.  
 
2. It is our understanding that DIRECTORY at DB and OS are having correct settings because the write or read file error can also occur because of incorrect directory settings.  If not, please check and make sure the DIRECTORY settings are fine.   
 
 
For example: 
 
SQL> create directory TESTDIR as '/testcases/3-1596154591sr';
 
SQL> grant read,write on directory TESTDIR to public;
 
 
 
Where TESTDIR is the DIRECTORY name used in the Application or PL/SQL object which tries to read/write from a physical and existing directory on the same server with the required permissions at OS level.  
 
OS level having 777 permissions to read and write to that particular directory. 
 
 
For example: 
 
chmod 777 /testcases/3-1596154591sr
 
 
3. If the problem still persists, please recreate the UTL_FILE packages.  This exercise is to make sure that the package itself is flawless.  Sometimes such error occurs if the packages are incomplete. 
 
You would need to run the following scripts: 
 
utlfile.sql (UTL_FILE package header) 
prvtfile.plb (UTL_FILE package body) 
 
Scripts can be found in the $ORACLE_HOME/rdbms/admin directory. 
 
 
SQL> @?/rdbms/admin/utlfile.sql
 
Package created.
Grant succeeded.
Synonym created.
 
SQL> @?/rdbms/admin/prvtfile.plb
Library created.
Package body created.
No errors. 
 
 
Check validity and time of the package: 
 
 
SQL> select OWNER, OBJECT_NAME, OBJECT_TYPE, LAST_DDL_TIME, STATUS from DBA_OBJECTS where OBJECT_NAME like 'UTL_FILE';
 
 
 
Internal documented behavior - Bug 5260543 (Not a bug):
 
Oracle 10g has some improvements over Oracle 9i and does not invalidate objects unnecessarily.
 
Last_ddl_time is found to be changed under the following conditions:
 
i) When the source of the procedure changes.
(or)
ii) The settings of following parameters change from original creation time: plsql_optimize_level, plsql_code_type, plsql_debug, nls_length_semantics, plsql_warnings, plsql_ccflags, plsql_compiler_flags.
 
This is an expected behaviour and not a bug
 
In any case, if you issue an explicit "ALTER PACKAGE UTL_FILE COMPILE;" the timestamp will change.
 
4. File that is being read or written is really important.  If the file format is incorrect then UTL_FILE cannot read or write to it.  UTL_FILE using R mode can only read ASCII files with valid line terminators.  The file is opened with no size parameter in mode R meaning it is opened as an ASCII format rather than binary file.  Therefore the line size limit is still 1024. If there is a line longer than this it will fail with 'file read error'.  In those cases, adding line size parameter to FOPEN call will help.  ASCII files are read into a buffer until a new line is retrieved and the default buffer size is 1024.  If the file is being read as binary then opening it as binary means new lines are no longer relevant.  If the file is in BINARY format then using UTL_FILE.GET_RAW with RB mode will help.  Reference Oracle MySupport Article <>
 
For Customers, using Oracle Applications products.  Any settings at APPS/FND level (ATG/EBS 11i or 12.0.x) are supported by that Product group - 510 Oracle Application Object Library, Component: CONCURRENT PROCESSING (CP), Subcomponent: CCREQ.  And ATG - APPS EBS group may check on the setup of APPLPTMP/FND_FILE using the UTL_FILE.   This article is only a general recommendation.  A separate Service Request (SR) needs to be created with that group.  
原文地址:https://www.cnblogs.com/feiyun8616/p/10627489.html