Solved

Oracle package global variable seen by procedures, error "PLS-00225: subprogram or cursor reference is out of scope"

Posted on 2013-07-01
2
719 Views
Last Modified: 2013-07-01
I'm trying to use a global variable within a package for all procedures to see that global variable.  I tried procedure A.variable_name  for global variable.  

Here is how I'm trying to use a global variable to pass variables within a package from one procedure A to procedure B but i get an error "PLS-00225: subprogram or cursor reference is out of scope"


CREATE OR REPLACE PACKAGE PKG_1
AS
   PROCEDURE A;

   PROCEDURE B;

END PKG_1;
/

CREATE OR REPLACE PACKAGE BODY PKG_1
AS
 PROCEDURE A
 IS
   
   CURSOR cur_A
   IS
 SELECT DISTINCT data
  FROM table_X;
   

 BEGIN
   
   OPEN cur_A;

   <<fetch_cur_A>>
   LOOP
      FETCH cur_A
       INTO rec_A;

      EXIT fetch_A WHEN cur_A%NOTFOUND;

        SELECT data
        INTO variable_name_A
        FROM table_A
        WHERE column_A = rec_A;

        IF variable_name_A is NOT NULL THEN

          B;  -- call procedure B

        END IF;

    END LOOP;

   CLOSE cur_A;

   END A;
 
  PROCEDURE B
   
   BEGIN
         
             SELECT x, y, z
               INTO v_x, v_y, v_z
             from table_Z
            WHERE column_P = (A.variable_name_A);  --using global variable by using                 --procedure_name.variable_name
                 
  END B;

END PKG_1;
0
Comment
Question by:talahi
2 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
You cannot use procedure A's variables outside procedure A.

Declare a global package variable.  Then use it.


CREATE OR REPLACE PACKAGE PKG_1
AS
   My_Global_variable    varchar2(100);

   PROCEDURE A;

   PROCEDURE B;

END PKG_1;
/

Open in new window

0
 

Author Closing Comment

by:talahi
Comment Utility
Thanks, saves me time from trying to make that work.  I'll try to OUT the variable from a and IN to B.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

744 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

17 Experts available now in Live!

Get 1:1 Help Now