ORA-01427: single-row subquery returns more than one row tips
Oracle Error Tips by Donald Burleson(S. Karam)
The Oracle docs note this on the
single-row subquery returns more than one row
The outer query must use one of the keywords ANY, ALL, IN, or NOT IN to
specify values to compare because the subquery returned more than one
Use ANY, ALL, IN, or NOT IN to specify which values to compare or reword
the query so only one row is retrieved.
Oracle Server and PL/SQL User Forum, Adam Wilbur received an ORA-01427 error
code and received this information:
Posted by 'Adam Wilbur' on April 21, 2001 at 20:37:00 EST:
Here's what I am trying to do...
UPDATE TABLEA SET TABLEA.COLUMN1 =
(select TABLEB.COLUMN1 FROM TABLEA, TABLEB
WHERE TABLEB.COLUMN2 = 'String Value'
AND TABLEA.COLUMN3 = TABLEB.COLUMN3
AND TABLEA.COLUIMN4 = TABLEB.COLUMN4
AND TABLEB.VALUENAME = 'String Value');
This query returns multiple rows, all of which I need to update in TABLEA.
How do I do this without getting ORA-01427 error?
Dmytro offered this advice to resolve ORA-01427:
Try to add and rownum=1 to your subquery conditions if you DO NOT care
about the value from the list or DO sure that they are the same.
Single Row Subquery
A single row subquery returns only one row. It can be
used with the equal comparison operators (=,<,>,<>, etc).
5 where quantity = (select
Here, we get the order number for the order that
contains the max quantity value. The outer query can return multiply rows,
but the subquery can only return one row.
5 where quantity > (select
14 rows selected.
Here, we want the order numbers where the order quantity
is above the average quantity in the sales table. Notice that the subquery
returns one and only one row that used in the filter.
You may want to refer to these helpful links concerning
single and multi row subqueries, and tips on
rows while avoiding ORA-01427 by Don Burleson.