Monday, April 19, 2010

ORA-01427: single-row subquery returns more than one row

I faced today, "ORA-01427:sub-query returns more than one row" error. The problem is easy to identify:This error is raised, when a sub-query returns more than one row to an Equality or in-Equality operator. The reason being there are restrictions on the legal comparison operators (Screen -1).


For any comparison operator listed in the table shown below, the sub-query must return single row (in other words, the sub-query, must be a single-row sub-query, otherwise it will fail)
Single-row Sub-query Operators
Symbol Meaning
= equal
> greater than
>= greater than or equal
< less than
<= less than or equal
<> not equal
!= not equal

The operators in the following table can use multiple-row sub-queries:
Multiple-row Sub-query Operators
Symbol Meaning
IN equal to any member in a list
NOT IN not equal to any member in a list
ANY returns rows that match any value on a list
ALL returns rows that match all the values in a list

There are several approaches to resolve this, most popular one being changing the inequality operator to a multiple-row operators (say, if the operator is "=" than change it "IN", "ANY", "ALL", so that it does not matter if multiple rows are returned.).
However, I found that if you use inline views, you can retain inequality operator as shown below in (Screen -2)
Note: In order to get consistent result, use the sub-query based on primary key. The above method is based on unique key

1 comment:

Unknown said...

Hi ,
Greetings from Application Plus Technologies !!
We are providing training with certification for the below skill set ,
*Oracle SQL
* Advance SQL
*PLSQL
*Advance PLSQL
* EBS Technical
* Fusion technical
If you are looking for training contact us
WhatsApp No : 8108735227 / 7499992939
Official Email : nida.k@applplus .com