Home » Developer & Programmer » Forms » ORA-01422: exact fetch returns more than requested number of rows.
ORA-01422: exact fetch returns more than requested number of rows. [message #472123] Wed, 18 August 2010 23:19 Go to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
Dear,

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

I receive this error because i tried to introduce the below coding in a post query of the block.

begin
	select supplier_cd into :fin_ex_rev_head.vendor_code
	from fin_ex_rev_receipts 
	where receipt_date 
	between :keyblock.receipt_date 
	and :keyblock.to_date
	and receipt_no||to_char(receipt_date,'DDMMRRRR') not in 
(select      receipt_no||to_char(receipt_date,'DDMMRRRR') 			 from fin_ex_rev_head where receipt_no is not null)
	 order by invoice_no;

end;				


i know the query gives more data and i need that too. what shall i do in this situation.

Thanks is Advance.

Stalin Ephraim.
Re: ORA-01422: exact fetch returns more than requested number of rows. [message #472148 is a reply to message #472123] Thu, 19 August 2010 01:38 Go to previous messageGo to next message
orakam1808
Messages: 7
Registered: August 2010
Junior Member
Hi Stalin,
You can use Cursor if you want to return more than one rows. Select Into won't work here as it always returns one row.
Hope, this will help.

kam
Re: ORA-01422: exact fetch returns more than requested number of rows. [message #472151 is a reply to message #472148] Thu, 19 August 2010 01:48 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
Kam,

Cursor too tried, coz its a form level trigger similar to a procedure here we cannot return a value.

this is the error i receive:

In a procedure, RETURN statement cannot contain an expression

[Updated on: Thu, 19 August 2010 01:49]

Report message to a moderator

Re: ORA-01422: exact fetch returns more than requested number of rows. [message #472155 is a reply to message #472151] Thu, 19 August 2010 02:11 Go to previous messageGo to next message
cookiemonster
Messages: 13923
Registered: September 2008
Location: Rainy Manchester
Senior Member
What exactly do you want to do with values returned by this select?

Re: ORA-01422: exact fetch returns more than requested number of rows. [message #473003 is a reply to message #472155] Wed, 25 August 2010 06:12 Go to previous messageGo to next message
tamzidulamin
Messages: 132
Registered: October 2009
Location: Dhaka
Senior Member
A select statement returns three types result
i) Single Record
ii) Multiple Record
iii) No Record

So you have to think first, what will be your desire output of your select clause?
For multiple record return in pl/sql block, you must have to use a CURSOR.
Re: ORA-01422: exact fetch returns more than requested number of rows. [message #475571 is a reply to message #472123] Wed, 15 September 2010 15:38 Go to previous messageGo to next message
tasos
Messages: 3
Registered: September 2010
Junior Member
You can use cursors to solve this issue.

CREATE TABLE employee
(
emp_id,
first_name VARCHAR2(50),
salary FLOAT(126)
)

populated with many records (table can have a primary key etc.- out of scope)

If you try to execute the pl/sql below you should get an error

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


declare

name varchar2(40);
sal number;

begin

select salary into sal from
employee;
dbms_output.put_line(sal);

end;

This is because the sql query returns more than 1 rows. In order to get all records you could use cursors as shown below.

declare

cursor c1 is
select first_name, salary
from employee;

name varchar2(40);
sal number;
counter number;

begin

--find number of records
select count(emp_id) into counter
from employee;

open c1;
--print all
for i in 1..counter loop
fetch c1 into name,sal;
dbms_output.put_line(name||' '||sal);
end loop;
close c1;
end;

Results

Tasos 2000
Spyros 2500
Panos 5000
George 1200
Jenny 2300
Julia 9000
Mary 9000
Re: ORA-01422: exact fetch returns more than requested number of rows. [message #475572 is a reply to message #475571] Wed, 15 September 2010 15:58 Go to previous messageGo to next message
cookiemonster
Messages: 13923
Registered: September 2008
Location: Rainy Manchester
Senior Member
1) Can you please read the orafaq forum guide and follow it in future posts - especially the bit about formatting your posts.
2) Variables should be typed to their corresponding columns with %type.
3) If you're going to count records use count(*)
4) Counting records in this case is a complete waste of time. A cursor for loop will retrieve all records without you having to find out how many there are.

I'd rewrite your code like this:
BEGIN

  FOR rec IN (SELECT first_name, salary FROM employee) LOOP

    dbms_output.put_line(rec.first_name||' '||rec.salary);

  END LOOP;

END;
Re: ORA-01422: exact fetch returns more than requested number of rows. [message #475575 is a reply to message #475572] Wed, 15 September 2010 16:33 Go to previous messageGo to next message
tasos
Messages: 3
Registered: September 2010
Junior Member
so basically, I could have
name employee.first_name%type;
sal employee.salary%type;



I used count because I used the syntax
for i in 1..number. If for number I had 10 or 15 it would make only some loops based on this.
I am not sure if you can avoid this when using a cursor.

thanks

[Updated on: Wed, 15 September 2010 16:34]

Report message to a moderator

Re: ORA-01422: exact fetch returns more than requested number of rows. [message #475576 is a reply to message #475575] Wed, 15 September 2010 17:02 Go to previous messageGo to next message
cookiemonster
Messages: 13923
Registered: September 2008
Location: Rainy Manchester
Senior Member
And I don't understand why you think you would ever need to count?
Re: ORA-01422: exact fetch returns more than requested number of rows. [message #475577 is a reply to message #475575] Wed, 15 September 2010 17:06 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9095
Registered: November 2002
Location: California, USA
Senior Member
You can use an implicit cursor like Cookie Monster demonstrated, or when fetching from an explicit cursor, you can place a line after the fetch to exit when c1%notfound, as shown below. You do not need a count.

open c1;
loop
  fetch c1 into name,sal;
  exit when c1%notfound;
  dbms_output.put_line(name||' '||sal);
end loop;
close c1;

Re: ORA-01422: exact fetch returns more than requested number of rows. [message #475578 is a reply to message #475577] Wed, 15 September 2010 17:30 Go to previous message
tasos
Messages: 3
Registered: September 2010
Junior Member
No I don't need to use count(). That's wrong. I was just searching for a better solution. That's really good!!

Thanks a lot
Previous Topic: File Upload Show No Record
Next Topic: SHEET1 AND SHEET2 IN EXCEL
Goto Forum:
  


Current Time: Sun May 19 01:52:05 CDT 2024