If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > search storedprocedure to return multiple rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-12, 05:40
kannama kannama is offline
Registered User
 
Join Date: Feb 2012
Posts: 9
search storedprocedure to return multiple rows

Please, help us i want to fetch more than one returns of rows while searching a data from table.Here in this code. if only one row matches the condition given then it returns the output,else where it shows an error when multiple rows matches the condition.

create or replace procedure bank_search_test1
(
p_tablename in char,
p_searchname in char,
p_bankcode out char,
p_bankname out char,
p_distcode out number
)
as
v_tem varchar2(500);
begin
v_tem := 'select bankcode,bankname,dist_code from ' || p_tablename || ' where bankcode like ''%' ||
p_searchname || '%''';
execute immediate v_tem into p_bankcode, p_bankname,p_distcode;
end;

This is the error shown when multiple rows matches

Running "PENSIONS"."BANK_SEARCH_TEST1" ( P_TABLENAME = bank, P_SEARCHNAME = D ).
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "PENSIONS.BANK_SEARCH_TEST1", line 13
ORA-06512: at line 1
Reply With Quote
  #2 (permalink)  
Old 02-10-12, 10:04
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
>execute immediate v_tem into p_bankcode, p_bankname,p_distcode;
P_BANKCODE is a scalar variable which means it can contain only a single value
It can not hold the result set when more than 1 row is returned.
The same is true for the other variables in the "INTO" clause.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #3 (permalink)  
Old 02-10-12, 11:43
jayanta_deb jayanta_deb is offline
Registered User
 
Join Date: Jan 2004
Posts: 117
Try with Pl/Sql table with Object type for the out value/s.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On