Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB   


 

 

 


 

 

 

 
 

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

Oracle Error Tips by Burleson Consulting

 

Oracle docs note this about ORA-01422:

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

Cause: The number specified in exact fetch is less than the rows returned.

Action: Rewrite the query or change number of rows requested

There is additional information on MOSC concerning ORA-01422. 

If you are using Oracle Enterprise 9.2-10.1 you may be receiving ORA-01422 without knowing it. Though Oracle 8.1.7 will vividly return ORA-01422, Oracle 9i and higher can return incorrect results instead of the ORA-01422 error message. 

This hidden ORA-01422 error can happen when you attempt to select without using a function, and an incorrect number of rows is returned.  For example:

SQL> SELECT n, pk FROM qq_ofir;

N PK
---------- ----------
111 1
222 2
333 3
333 4
555 5
666 6

6 rows selected.

ORA-01422 can also return incorrect results when one row is returned when you attempt to select through a function.  For example, the rows of 333 that are duplicate are coded in such a way that ORA-01422 should have been thrown, but the incorrect results are returned instead. 

SQL> SELECT n, qq_get_pk(n) FROM qq_ofir;

N QQ_GET_PK(N)
---------- ------------
111 111
Cause
Bug 3830942

According to this, the ORA-01422 returning invalid results due to a bug.  When a function is called, the SQL statement finishes executing and though ORA-01422 goes to the client program, the error message is suppressed in the OCI layer so that you can only see a message that briefly discusses that the program has been abnormally ended, but you see no ORA-01422 error.

Because this problem with not seeing the ORA-01422 message is a part of a bug, the solution is to a workaround to get the stored function to raise a user defined exception using the coding of an exception handler that will do something such as the following:

EXCEPTION
WHEN TOO_MANY_ROWS THEN
RAISE_APPLICATION_ERROR(-20001,'Exact Fetch Returned Too many Rows');

This function can then be used to SELECT with the exception handling added rows which will contain the correct results. 

SQL> SELECT n, qq_get_pk(n) FROM qq_ofir;
ERROR:
ORA-20001: Exact Fetch Returned Too many Rows
ORA-06512: at "SCOTT.QQ_GET_PK", line 12

no rows selected


You may also be interested in this community troubleshooting from Oracle Forums:

Question:

I continue to receive this ORA-01422 message whenever I get to this stage in the process:

UPDATE TT_FERMS
SET assigned_system_id = 2
WHERE ferm_bank = 3
RETURNING ( SPAC_ASSIGN_FERMS.xfer_seq + 1 ), SPAC_ASSIGN_FERMS.xfer_seq
+ 1 INTO SPAC_ASSIGN_FERMS.xfer_seq, SPAC_ASSIGN_FERMS.xfer_seq;


ERROR:ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "BREW_SCHED.SPAC_ASSIGN_FERMS", line 959

 

Answer:

There are several options to resolve ORA-01422, which take some time to figure out which option is appropriate for you.  Here are some things you may want to try:

  • This is most likely signifying that you have updated multiple rows.  Because of this, Oracle throws the ORA-01422 error because it is not able to return the variables in simple variables.  To remedy this, try BULK COLLECT in a table such as the below:

SQL> declare
2 type num_tab is table of number;
3 empno_tab num_tab;
4 begin
5 update emp set ename = ename
6 returning empno bulk collect into empno_tab;
7 for i in 1..empno_tab.count loop
8 dbms_output.put_line('updated empno '||empno_tab(i));
9 end loop;
10 end;
11 /
updated empno 7839
updated empno 7698
updated empno 7782
updated empno 7566
updated empno 7788
updated empno 7902
updated empno 7369
updated empno 7499
updated empno 7521
updated empno 7654
updated empno 7844
updated empno 7876
updated empno 7900
updated empno 7934

PL/SQL procedure successfully completed.

  • You may want to declare SPAC_ASSIGN_FERMS.xfer_seq because a table may be needed if multiple rows are being updated.
  • If, from update, you are trying to return two values, you should consider defining my_tab
  • Try using a table of a record with two fields, and the record with two fields itself. (NOTE: as of 9.2.0.6, you are not able to use composite targets and returning clauses together. However, returning to collections is allowed.)

 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2012 

All rights reserved.

Oracle © is the registered trademark of Oracle Corporation.


 

  
 

 
 
 
 
Oracle performance tuning software
 
 

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books