Exact fetch return more than requested number of rows

Posted on 2006-06-13
Last Modified: 2008-01-09
I have the following PL/SQL code which I am trying to test by copying and pasting it next to the SQL prompt. I want to obtain all the distinct termcodes from three years up to the value in end_term.

set serveroutput on size 9999999999999999;


end_term varchar2(8);
term varchar2(8);


end_term := '200601';

select distinct termcode into term from student where termcode between to_char(to_number(end_term)-300) and end_term;


However, I obtain the following error:

ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 10

How do I fix it?
Question by:geeta_m9
  • 2
LVL 25

Accepted Solution

jrb1 earned 150 total points
ID: 16897293
You need to use a cursor to return multiple rows:

set serveroutput on size 9999999999999999;

   end_term varchar2(8);
   term varchar2(8);
   cursor c1 is
          select distinct termcode
          from student
          where termcode between to_char(to_number(end_term)-300) and end_term;

   end_term := '200601';

   for v_row in c1 loop
   end loop;


Author Comment

ID: 16897372
When I execute your query, I get the following error:

ERROR at line 14:
ORA-06550: line 14, column 30:
PLS-00302: component 'TERM' must be declared
ORA-06550: line 14, column 3:
PL/SQL: Statement ignored
LVL 29

Assisted Solution

MikeOM_DBA earned 100 total points
ID: 16897470

Fix typo:

Author Comment

ID: 16897595
It works now, thanks!

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Download OAB 0x8004010f An object cannot be found 12 99
Update from TABLE-A to TABLE-B 5 48
What's wrong with this T-SQL Foreign Key? 7 46
Mysql Left Join Case 10 55
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question