Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exact fetch return more than requested number of rows

Posted on 2006-06-13
4
Medium Priority
?
2,837 Views
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;

declare

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

begin

end_term := '200601';

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

end;

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?
0
Comment
Question by:geeta_m9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 25

Accepted Solution

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

set serveroutput on size 9999999999999999;

declare
   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;

begin
   end_term := '200601';

   for v_row in c1 loop
      dbms_output.put_line(v_row.term);
   end loop;
end;
/

0
 

Author Comment

by:geeta_m9
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
0
 
LVL 29

Assisted Solution

by:MikeOM_DBA
MikeOM_DBA earned 400 total points
ID: 16897470


Fix typo:
...
      dbms_output.put_line(v_row.termcode);
...
0
 

Author Comment

by:geeta_m9
ID: 16897595
It works now, thanks!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

610 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