Adsense Ad

Tuesday 23 May 2017

Oracle: ORA-01422 Error Message

ORA-01422 Error Message

Learn the cause and how to resolve the ORA-01422 error message in Oracle.

Description

When you encounter an ORA-01422 error, the following error message will appear:
  • ORA-01422: exact fetch returns more than requested number of rows

Cause

You tried to execute a SELECT INTO statement and more than one row was returned.

Resolution

The option(s) to resolve this Oracle error are:

Option #1

Rewrite your SELECT INTO statement so that only one row is returned.

Option #2

Replace your SELECT INTO statement with a cursor.
For example, if you tried to execute the following SQL statement:
SELECT supplier_id
INTO cnumber
FROM suppliers
WHERE supplier_name = 'IBM';
And there was more than one record in the suppliers table with the supplier_name of IBM, you would receive the ORA-01422 error message.
In this case, it might be more prudent to create a cursor and retrieve each row if you are unsure of how many records you might retrieve.

No comments: