Monday, July 13, 2009

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

SOLUTION 1:
the main reason for this error is records get duplicated on the table .So the inner query returns the duplicated values.to rectify this use the following query and this problem get resolved.
here is the solution if and only if you want to delete the duplicate records from the table


DELETE FROM TABLE_NAME A where rowid not in (select max(rowid) from TABLE_NAME B
where A.COLUMN_NAME=B.COLUMN_NAME)

In This QUERY you will replace the TABLE_NAME in to your table name and the COLUMN_NAME into your column name ,where the column datas gets repeated.

SOLUTION 2:
if the inner query returns the duplicated value if you group it on the outer query using the follwing keywords it will rectified.

KEWORDS:ANY, ALL, IN, or NOT IN

Example:

1.SELECT book_name FROM library WHERE book_name IN (SELECT book_name from stores where author_name='dennis ritchie')

2.SELECT book_name FROM library WHERE book_name = ANY (SELECT book_name from stores where author_name='dennis ritchie')

3.SELECT book_name FROM library WHERE book_name = ALL (SELECT book_name from stores where author_name='dennis ritchie')

4.SELECT book_name FROM library WHERE book_name NOT IN (SELECT book_name from stores where author_name='dennis ritchie')


thanks,
A.T.J

No comments:

Post a Comment