Error
Error Code: ORA-29287

Oracle Error ORA-29287: Invalid Line Size

📦 Oracle Database
📋

Description

The ORA-29287 error in Oracle Database indicates that an invalid maximum line size value was specified when using a procedure or function that handles text input/output. This error typically arises when the `maxlinesize` parameter is out of the allowed range.
💬

Error Message

ORA-29287: invalid maximum line size
🔍

Known Causes

3 known causes
⚠️
Out-of-Range Value
The `maxlinesize` parameter was set to a value outside the permitted range of 1 to 32767. ⚠
⚠️
Incorrect Parameter Type
The `maxlinesize` parameter was passed as the wrong data type (e.g., string instead of number). 💻
⚠️
Missing Parameter
A function or procedure requiring the `maxlinesize` parameter was called without providing a value. ⚠
🛠️

Solutions

3 solutions available

1. Adjust UTL_FILE_DIR Parameter easy

Temporarily or permanently configure the UTL_FILE_DIR parameter to allow file operations.

1
Check the current value of UTL_FILE_DIR. This parameter specifies the directories from which PL/SQL can read and write files. If it's not set or doesn't include the directory you're trying to access, you'll get ORA-29287.
SHOW PARAMETER UTL_FILE_DIR;
2
Option 1 (Quick Fix - For testing/development): Set UTL_FILE_DIR to '*' to allow access to all directories. **Caution:** This is insecure and should only be used in non-production environments.
ALTER SYSTEM SET UTL_FILE_DIR = '*' SCOPE=BOTH;
3
Option 2 (Recommended - Production): Specify the exact directory where your file operations are occurring. Replace '/path/to/your/directory' with the actual directory.
ALTER SYSTEM SET UTL_FILE_DIR = '/path/to/your/directory' SCOPE=BOTH;
4
If you need to allow multiple directories, separate them with commas. For example: '/dir1,/dir2,/dir3'.
ALTER SYSTEM SET UTL_FILE_DIR = '/path/to/dir1,/path/to/dir2' SCOPE=BOTH;
5
For the changes to take effect without a full instance restart, you might need to re-initialize the UTL_FILE package or restart the listener and instance if the parameter was initially unset or changed significantly. However, SCOPE=BOTH usually applies dynamically.
N/A

2. Utilize Oracle Directory Objects medium

Create and use Oracle Directory Objects for more secure and manageable file access.

1
Create an Oracle Directory Object that points to the file system directory you want to use. Replace 'MY_FILES_DIR' with a descriptive name and '/path/to/your/directory' with the actual path.
CREATE OR REPLACE DIRECTORY MY_FILES_DIR AS '/path/to/your/directory';
GRANT READ, WRITE ON DIRECTORY MY_FILES_DIR TO your_user_or_role;
2
Modify your PL/SQL code to use the newly created Directory Object instead of hardcoding the file path.
DECLARE
  file_handle UTL_FILE.FILE_TYPE;
BEGIN
  file_handle := UTL_FILE.FOPEN('MY_FILES_DIR', 'my_output.txt', 'W');
  UTL_FILE.PUT_LINE(file_handle, 'This is a test.');
  UTL_FILE.FCLOSE(file_handle);
END;
/
3
Ensure the Oracle database OS user has read/write permissions on the physical directory specified in the Oracle Directory Object.
N/A

3. Verify File Path and Permissions easy

Confirm the file path is correct and the Oracle OS user has necessary permissions.

1
Double-check the file path specified in your `UTL_FILE.FOPEN` or `UTL_FILE.IS_OPEN` calls. Typos are a common cause of this error.
N/A
2
On the operating system where the Oracle database is running, verify that the directory exists and that the Oracle database OS user has read and write permissions for that directory. The Oracle OS user typically starts with 'oracle' or the name of the user that installed Oracle.
Example on Linux/Unix:
ls -ld /path/to/your/directory
chown oracle:oinstall /path/to/your/directory
chmod 755 /path/to/your/directory
3
If using Oracle Directory Objects, ensure the `GRANT READ, WRITE ON DIRECTORY ...` statement has been executed for the user running the PL/SQL code.
SELECT * FROM ALL_DIRECTORIES WHERE DIRECTORY_NAME = 'YOUR_DIRECTORY_NAME';
SELECT * FROM ALL_TAB_PRIVS WHERE TABLE_NAME = 'YOUR_DIRECTORY_NAME' AND GRANTEE = 'YOUR_USER';