Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem using cursor in stored procedure...

766896Jun 14 2010 — edited Jun 14 2010
Hi,
I am using oracle 10g.I had written a procedure which returns me list of telephone nos selected based on selection criteria.My procedure is working but its taking time.I am using a query which returns me list of rows.The count of row is very much.so each time it execute the query in loop, and it takes time.I want to use cursor so that at one time it will be executed and those records will be checked instead of executing the query everytime....

The query which is used is :
select * from abc where x = SUBSTR(ni_array(i),1,3) and b= SUBSTR(ni_array(i),4,6) ;

Please take this in cursor if possible...i had used it in my procedure below in for loop....I will be thankful to you in this regard.
The procedure is below:

create or replace PROCEDURE "OM_GET_SELECTED_TEL" (
ni_array IN ty_npa_id,
reqquantity IN NUMBER,
available OUT ty_tel_no
)
AS


begin


declare
available ty_tel_no:= ty_tel_no();
output VARCHAR2 (400);
k number(3):= 1;


BEGIN





FOR i IN 1 .. ni_array.COUNT
LOOP
FOR j IN
(SELECT tel_no,
CASE
WHEN REGEXP_LIKE (tel_no, '(\d)\1\1\1$')
THEN 'condition 1 fullfilled'
WHEN REGEXP_LIKE (tel_no, '(\d)\1(\d)\2$')
THEN 'condition 2 fullfilled'
WHEN REGEXP_LIKE (tel_no,
'\d(\d)\1\1$|(\d)\2\2\d$'
)
THEN 'condition 3 fullfilled'
ELSE 'condition 4 fullfilled'
END condition
FROM (select * from abc where x = SUBSTR(ni_array(i),1,3) and b= SUBSTR(ni_array(i),4,6) ) order by condition)
LOOP
output := j.condition;
available.extend();

IF (output = 'condition 1 fullfilled')
THEN


available(k) := j.tel_no;
k := k+1;
--availableinvids := j.tel_no;
DBMS_OUTPUT.put_line ('selected nos which satisfy condition 1:' || j.tel_no);
ELSIF (output = 'condition 2 fullfilled')
THEN
available(k) := j.tel_no;
k := k+1;
--availableinvids := j.tel_no;
DBMS_OUTPUT.put_line ('selected nos which satisfy condition 2:' || j.tel_no);
ELSIF (output = 'condition 3 fullfilled')
THEN
available(k) := j.tel_no;
k := k+1;
--availableinvids := j.tel_no;
DBMS_OUTPUT.put_line ('selected nos which satisfy condition 3:' || j.tel_no);
ELSE
available(k) := j.tel_no;
k := k+1;
DBMS_OUTPUT.put_line ('selected nos which dont satisfy condition :' || j.tel_no);


END IF;
EXIT WHEN k = reqquantity + 1 ;
END LOOP;
EXIT WHEN k = reqquantity + 1 ;
END LOOP;



end;
END;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2010
Added on Jun 14 2010
1 comment
599 views