Re: Are PL/SQL variable values runtime only?

From: Adam Musch <ahmusch_at_gmail.com>
Date: Wed, 22 Jul 2009 14:29:05 -0500
Message-ID: <516d05a0907221229r7a373022m6c3b46a4b358e69e_at_mail.gmail.com>



Declarations of the format

variable_name variable_type := some_value_of_type;

are simply a coding convention to avoid having to:

declare
  variable1 number;
  variable2 number;
begin
  variable1 := 0;
  variable2 := 1;
. . .

Nothing gets assigned at compile time because the code doesn't get executed at compile time. I don't think it's possible to do what you seem to be asking for -- store the value of something as it existed at compile time and return it when asked. I'd argue something more tabular is called for if you want to store data at some snapshot in time.

On Wed, Jul 22, 2009 at 2:10 PM, Rich
Jesse<rjoralist_at_society.servebeer.com> wrote:
> Hi Ric,
>
> I'm not questioning the scope of the variable, but the timing of the
> evaluation of the "my_pkg.my_value" function.
>
> Contrast this example with my original:
>
> CREATE OR REPLACE PROCEDURE new_bleah AS
>    v_test VARCHAR2(50);
> BEGIN
>    v_test := my_pkg.my_value('ABC');
>    DBMS_OUTPUT.PUT_LINE(v_test);
> END new_bleah;
> /
>
> This function clearly sets the value of "v_test" at runtime.
>
> However, the original "bleah" function also sets the value of "v_test" at
> runtime, even though the assignment is in the DECLARE (variable) section and
> not in the BEGIN (code) section.  I would have expected it to happen at
> compile time.
>
> Hopefully that's a little clearer explanation?
>
> Thanks!
> Rich
>
>
>> Hi Rich,
>>
>> The short answer is yes.  The life of a variable is only within the
>> block that it's defined. You can create variables in a package header
>> that have a more global like life span.  Although I'm not sure I totally
>> understand what you are asking so maybe I'm off the mark here.
>>
>> I think this is covered in the scoping rules of the PL/SQL guide.
>>
>> Ric Van Dyke
>>
>>
>> -----Original Message-----
>> From: oracle-l-bounce_at_freelists.org
>> [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Rich Jesse
>>
>> CREATE OR REPLACE PROCEDURE bleah AS
>>     v_test VARCHAR2(50) := my_pkg.my_value('ABC');
>> BEGIN
>>     DBMS_OUTPUT.PUT_LINE(v_test);
>> END bleah;
>> /
>
>
> --
> http://www.freelists.org/webpage/oracle-l
>
>
>

-- 
Adam Musch
ahmusch_at_gmail.com
--
http://www.freelists.org/webpage/oracle-l
Received on Wed Jul 22 2009 - 14:29:05 CDT

Original text of this message