Home » SQL & PL/SQL » SQL & PL/SQL » variables in packages
variables in packages [message #230170] Wed, 11 April 2007 02:22 Go to next message
khushi2000
Messages: 29
Registered: April 2007
Junior Member
Hi,

Need to know the difference between the 2 options:-

1) a varible declared inside a package specification
2)a variable declared inside a package body but outside a procedure/function.

I am able to access the variable outside the package in both the cases.Please Clarify.

Thanks,
Khushi
Re: variables in packages [message #230187 is a reply to message #230170] Wed, 11 April 2007 03:01 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
SQL> create package p as
  2  global_variable1 integer := 1;
  3  end;
  4  /

Package created.

SQL> create package body p as 
  2  global_variable2 integer := 2;
  3  end;
  4  /

Package body created.

SQL> set autoprint on
SQL> var v number
SQL> exec :v := p.global_variable1;

PL/SQL procedure successfully completed.


         V
----------
         1

SQL> exec :v := p.global_variable2;
BEGIN :v := p.global_variable2; END;

              *
ERROR at line 1:
ORA-06550: line 1, column 15:
PLS-00302: component 'GLOBAL_VARIABLE2' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

Regards
Michel
Re: variables in packages [message #230211 is a reply to message #230170] Wed, 11 April 2007 04:04 Go to previous message
khushi2000
Messages: 29
Registered: April 2007
Junior Member
Oh OK..Thanks.
Khushi
Previous Topic: how to get rows of a table as columns
Next Topic: Compiling in native and have FOR statment return compiled with errors
Goto Forum:
  


Current Time: Sun Dec 04 06:54:15 CST 2016

Total time taken to generate the page: 0.17123 seconds