Friday, December 20, 2013

ORA-01422: exact fetch returns more than requested number of rows

Scenario:
ORA-01422: exact fetch returns more than requested number of rows

Solution:  This is an Error related to Cursor Variables. when we are Declaring Cursor variables and then we are trying to Insert Values INTO these variables from PL/SQL Select Statements. while Retrieving the Value from Select Statement at a time is more than one value then it will Throw the below error.

Example:

BEGIN
SELECT A.XYZ
INTO l_XYZ
FROM XYZ_TABLE_LOG A
WHERE
A.XYZ IN ((SELECT MAX(A.XYZ) FROM XYZ_TABLE_LOG A) where TEXT='SAMPLE')

Error:

ORA-01422: exact fetch returns more than requested number of rows

So here The Values Retrieving from the Select Statement Returning More than one value. so The Cursor Variable is Throwing an Error.

Select MAX(A.XYZ) from XYZ_TABLE_LOG A where TEXT='SAMPLE'
342
342

so here the max value is 342. but it returns Two Values, becuase it is selecting based on TEXT='SAMPLE' in where Clause. so Remove one Value from Table XYZ_TABLE_LOG.

Please investigate why we are getting 2 values As a MAX value. then Issue will be resolved.

Thanks,
Anilkumar.

No comments:

Post a Comment