Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Redeclaration of Global variables...

RE: Redeclaration of Global variables...

From: William B Ferguson <wbfergus_at_usgs.gov>
Date: Thu, 16 Mar 2006 08:23:13 -0700
Message-ID: <OF1334198A.6BE8478C-ON07257133.0053C03C@usgs.gov>


While it's slightly different, it's probably related to the fact that packages can have multiple declarations of the same procedure/function using different parameters, so the same (named) procedure/function can receive different kinds of parameters and run without breaking. Steven Fuerstein (I think I spelled it correctly), has a few examples in his book "Programming with Packages", in the section about overloading packages.



Bill Ferguson
U.S. Geological Survey - Minerals Information Team PO Box 25046, MS-750
Denver, Colorado 80225
Voice (303)236-8747 ext. 321 Fax (303)236-4208  

From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Manu Sankar
Sent: Thursday, March 16, 2006 7:12 AM
To: Oracle-L_at_freelists.org
Subject: Re: Redeclaration of Global variables...

my question is why isnt this being caught at compile-time/run-time ?

On 3/16/06, rjamya <rjamya_at_gmail.com> wrote:

question ... why would you declare same variable twice in the same scope anyways ...?? It is a bad programming practice ...

Raj

On 3/16/06, Manu Sankar <manusankar_at_gmail.com> wrote:
> Hi,
>
> While redeclaration of variables is not allowed in anonymous blocks,
> the same is being allowed in Package specs.
>
> What could be the reason behind it ?
>
> Following script can give you a test case
>
> declare
> g_num number(2):=10;
> g_num varchar2(10):='test';
> begin
> dbms_output.put_line('g_num is '||g_num);
> end;
> /
>
> You will hit the error
>
> PLS-00371: at most one declaration for 'G_NUM' is permitted in the
> declaration section
>
>
> Try this
>
> create package glb_test as
> g_num number:=10;
> g_num varchar2(10):='test';
> end;
> /
>
> exec dbms_output.put_line('G_num is '||glb_test.g_num);
>
> You dont hit any error though g_num has been declared twice....
>
>
> Thanks
> -Manu
>
>
>

--
----------------------------------------------
Got RAC? 





--
http://www.freelists.org/webpage/oracle-l
Received on Thu Mar 16 2006 - 09:23:13 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US