Adsense Ad

Tuesday, 23 May 2017

Oracle: ORA-01427 Error Message

ORA-01427 Error Message

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

Description

When you encounter an ORA-01427 error, the following error message will appear:
  • ORA-01427: single-row subquery returns more than one row

Cause

You tried to execute a SQL statement that contained a SQL subquery that returns more than one row.

Resolution

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

Option #1

Rewrite your query so that the subquery only returns one row.

Option #2

Change your query to use one of the following with your subquery results:
  • ANY
  • ALL
  • IN
  • NOT IN
For example, if you tried to execute the following SQL statement:
SELECT *
FROM orders
WHERE supplier_id = (SELECT supplier_id
                     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 following message:
Oracle PLSQL
The most common way to correct this SQL statement is to use the IN condition as follows:
SELECT *
FROM orders
WHERE supplier_id IN (SELECT supplier_id
                      FROM suppliers
                      WHERE supplier_name = 'IBM');

No comments: