Link to home
Start Free TrialLog in
Avatar of geeta_m9
geeta_m9

asked on

Exact fetch return more than requested number of rows

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?
ASKER CERTIFIED SOLUTION
Avatar of jrb1
jrb1
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of geeta_m9
geeta_m9

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It works now, thanks!