Skip to Main Content
  • Questions
  • Is there a way to close the cursor after reading it?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Verina.

Asked: September 29, 2022 - 12:06 pm UTC

Last updated: October 13, 2022 - 12:33 pm UTC

Version: oracle database 12.2 c

Viewed 10K+ times! This question is

You Asked

working with oracle sql and oracle service bus. I have a problem with closing the connection. An example of a simple procedure I use is the following :

create or replace procedure getempdata(
  v_id in number,
  q out sys_refcursor
)
as
begin
  open q for select * from employees where id = v_id;
end;


I need a way to close the cursor after getting the data from it. But if I use close Q; , I can't read the data returned in service bus adapter . The question is : Is there a way to close the cursor (for memory management) from service bus after reading it? And if there is not, Is there a way to do so from the procedure with returning the data as output?

and Chris said...

It's up to the client to close the cursor after fetching all the necessary data from it. Exactly how you do this depends on the language and framework you're using.

I'm unclear when/where you're trying to close the cursor and what your service bus is. If you need further help please provide details of which languages you're using and a complete example that's causing problems.

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Verina, October 11, 2022 - 9:23 am UTC

The service bus project I use consists of a database adapter calling a stored procedure (plsql) and a rest binding component that creates webservice interface for the database adapter.
I need to close the cursor after reading it from the database adapter of the servicebus.
Chris Saxon
October 11, 2022 - 2:27 pm UTC

Check the documentation for whatever your database adapter is to find out how to close cursors with it.

Question to Verina - CLOSE statement

J. Laurindo Chiappa, October 13, 2022 - 12:31 pm UTC

Hello - what about https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1606716582692 , where the REF CURSOR is directly CLOSED , treating the REF CURSOR as an explicit cursor , would it suffice for your needs ?
Chris Saxon
October 13, 2022 - 12:33 pm UTC

Thanks for digging that out

Obs....

J. Laurindo Chiappa, October 13, 2022 - 12:53 pm UTC

Just an observation : I think that the technique in my previous comment will NOT work to you (as I understand, the ref cursor will be "consumed" by an External program (not written in PL/SQL and External to the database), thus the REF CURSOR must be in OPEN state to allow it, ad in this way only the "External" consumer could close it, but look and see, and later tell us the results...

Regards,

Chiappa

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library