exact fetch returns more than requested number of rows

Problem :

empname VARCHAR2(200);
select ENAME into empname from emp where dept_id=20;

Reason : The above code returns the multiple rows , here the select into statements accepts only one row.


SELECT INTO statement will throw an error if it returns anything other than 1 row. If it returns 0 rows, you’ll get a no_data_found exception. If it returns more than 1 row, you’ll get a too_many_rowsexception. Unless you know that there will always be exactly 1 employee with a salary greater than 3000, you do not want a SELECT INTO statement here.

Solution: Change the select statement such that it will return only 1 row.

Visit Us On FacebookVisit Us On Google PlusVisit Us On Youtube