Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Urgent:exact fetch returns more than requested number of rows

Posted on 2007-11-19
8
Medium Priority
?
1,713 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
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 how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses

885 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