Solved

Urgent:exact fetch returns more than requested number of rows

Posted on 2007-11-19
8
1,674 Views
Last Modified: 2013-12-19
hi
i am using this query in my function in oracle
---
BEGIN
   cursor c1 is
   select decode(operation,'MinFinal',test_id), decode(operation,'Final',test_id) into testid1,testid2
   from test.test_data_v7
   where operation in ('MinFinal','Final')
   and (pf = 1 or pf = 4) and serial = '' || in_serialno || '';

when i run the function i get this error
ORA-01422: exact fetch returns more than requested number of rows
do i need to use cursor then? this query is supposed to return 2 records if match found.
i
0
Comment
Question by:samir25
  • 3
  • 3
  • 2
8 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 20310987
Remove this line:

into testid1,testid2
0
 
LVL 1

Author Comment

by:samir25
ID: 20310990
then how do i refer it..can u explian me more thanks
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 20310993
firstly, please paste your full code for a better understanding.

From the above, if you have more than one record returned in the select then either you should have bulk collect or you should use a cursor and iterate through the two records to fetch them into variable as shown below.

declare

   cursor c1 is
   select decode(operation,'MinFinal',test_id) test_id1, decode(operation,'Final',test_id) test_id2    from test.test_data_v7
   where operation in ('MinFinal','Final')
   and (pf = 1 or pf = 4) and serial = '' || in_serialno || '';

test_id1 varchar2(10); -- use number if test_id1 is number data type, also note i have used 10
test_id2 varchar2(10); -- use number if test_id1 is number data type

BEGIN

for a in c1
loop

    dbms_output.put_line('id1:'||test_id1);
    dbms_output.put_line('id2:'||test_id2);
    -- the above will just the variables fetched.. just do whatever processing you want
    -- there instead of printing them.

end loop;
end;
/
   
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 42

Expert Comment

by:dqmq
ID: 20311022
>then how do i refer it..can u explian me more thanks

Open the cursor, then fetch from the cursor into the variables.  Usually, you do it inside a loop because of the multiple rows.

0
 
LVL 1

Author Comment

by:samir25
ID: 20311089
here is what i did
CREATE OR REPLACE FUNCTION FORMAT(in_serialno varchar2)
RETURN LINES_TABLE PIPELINED IS
  cursor c1 is
   select decode(operation,'MinFinal',test_id) test_id1, decode(operation,'Final',test_id) test_id2    from test.test_data_v7
   where operation in ('MinFinal','Final')
   and (pf = 1 or pf = 4) and serial = '' || in_serialno || '';
some variables.....
...
..
BEGIN
 for r1 in c1
loop
   dbms_output.put_line('testid ' || r1.testID1);
   dbms_output.put_line('testid ' || r1.testID2);
end loop;
...
..
end;

no test id is outputted..why is this so?
0
 
LVL 1

Author Comment

by:samir25
ID: 20311098
btw i run it as
select * from table(FORMAT('2322503'))
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 20311137
you should do

SQL> SET serveroutput on   -- to see the output on screen.

I am not sure what you are trying to do. if you need more info. on pipelined functions, then refer to http://www.oracle-base.com/articles/9i/PipelinedTableFunctions9i.php

Thanks
0
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 250 total points
ID: 20311140
if you want non pipelined version of code.. it is something like the below :

CREATE OR REPLACE FUNCTION FORMAT(in_serialno varchar2)
RETURN LINES_TABLE IS
  cursor c1 is
   select decode(operation,'MinFinal',test_id) test_id1, decode(operation,'Final',test_id) test_id2    from test.test_data_v7
   where operation in ('MinFinal','Final')
   and (pf = 1 or pf = 4) and serial = '' || in_serialno || '';
v_tab LINES_TABLE := LINES_TABLE();
...
..
BEGIN
 for r1 in c1
loop
--   dbms_output.put_line('testid ' || r1.testID1);
--   dbms_output.put_line('testid ' || r1.testID2);
   v_tab.extend;
   v_tab(v_tab.last) := r1.test_id1;
   v_tab.extend;
   v_tab(v_tab.last) := r1.test_id2;
end loop;
return v_tab;
end;
/
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

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