Cursor out of scope

Posted on 2004-04-30
Last Modified: 2008-02-01
FUNCTION  match_cit_feature
     (seq_id_in IN gcg_bioseq.seq_id%TYPE,
      pub_id_in IN gcg_publication.pub_id%TYPE)
  RETURN gcg_feature.feat_id%TYPE
cursor c_pub is  select feat_id ,pub_id  from gcg_feature_pub
  where feat_id in (select feat_id from gcg_feature where seq_id = seq_id_in  );
  local_feat_id number(15);
  local_pub_id number(15);
For i in  c_pub loop
if c_pub.pub_id = pub_id_in then
return c_pub.feat_id;
return null;
end if;
end loop;
  end match_cit_feature;
For the above set of code i get the error

-------- -----------------------------------------------------------------
14/1     PL/SQL: Statement ignored
14/10    PLS-00225: subprogram or cursor 'C_PUB' reference is out of scope
What does out of scope error mean
Question by:nandini22
LVL 44

Expert Comment

ID: 10958422
the real cause of the error 14/10  is the first error 14/1  which suggests that there is a problem in your FUNCTION declaration.

I would suggest that you should check the PL/SQL syntax for declaring a FUNCTION as a 'Stored Procedure'. It has been about 7 yeears since I used ORACLE, so I can't give you the corect syntax, but my guess is that there is an error in the FUNCTION declaration.  

The 14/10 error is then due to the fact that you cannot declare a cursor outside of the definition of either a valid FUNCTION or a valid STORED PROCEDURE.

LVL 22

Accepted Solution

Helena Marková earned 125 total points
ID: 10958611
I think that this will work:

For rec in  c_pub loop
if rec.pub_id = pub_id_in then
 return rec.feat_id;
 return null;
end if;
end loop;

Author Comment

ID: 10959194
Thanks Henka it works ,but I have another problem that when there are no rows selected by the cursor the exception to return a null is not being raised.

Assisted Solution

Elena-S earned 125 total points
ID: 10960695
It is not considered an exception to return null from a function.  If you would like to treat it as exception, you need to raise exception explicitly.  For example,

if some_value is null then
   raise_application_error(-20000, 'Your error message goes here');
end if;

You can find detailed description of this procedure in Oracle help available on-line.

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL 2014 AG in-place upgrade to SQL 2016 2 74
SQL BACKUP - 2008 R2 8 70
Server configuration for MS Access - SQL Server app 8 68
free version of MSSQL for over 10GB DB 19 59
In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now