Oracle ref cursor fetch hangs if it contains 1 single record

2.3k views Asked by At

I have a weird problem right now that if a ref cursor returned from a stored procedure that has only 1 record in it, the fetch operation will hang and freeze. The stored procedure execution was really fast, just the fetching process hangs. If the ref cursor has more than 1 record, then everything is fine. Does anyone have similar issues before?

The Oracle server is 11g running on Linus. The client is Windows Server 2003. I'm testing this using the generic Oracle sqlplus tool on the Windows Server.

Any help and comments would be greatly appreciated. thanks.

2

There are 2 answers

0
Gary Myers On

When you say hangs, what do you mean ?

If the session is still active in the database (status in V$SESSION), then it is probably waiting on some event (eg SQL*Net from client means it is waiting for the client to do something).

It may be that the query is taking a long time to find that there aren't any more rows. Consider a table of 10,000,000 rows with no indexes. The query may full scan the table and find the first row matches the criteria. It still has to scan the next 9,999,999 rows to find that they don't. That can take a while.

0
Rajesh Chamarthi On

Since you are saying that the process hangs, Is there a chance that your cursor does a "select for Update" instead of "Select " ? Since you are saying that the fetch of multiple records does not cause this error, that might not be the case.

Can you show us the code (or a reproducible small test/sample) for your select and the fetch.

Also, you can check the v$locked_objects using the following query and giving in your table name(s) to see if the object in question is being locked. Again, unless your current query has "for update" this fetch should not hang.

select do.* 
  from v$locked_objects vo,
       dba_objects      do
  where vo.object_id = do.object_id
    and vo.object_name = '<your_table_name>'