Re: Are PL/SQL variable values runtime only?

  • From: Maxim Demenko <mdemenko@xxxxxxxxx>
  • To: rjoralist@xxxxxxxxxxxxxxxxxxxxx
  • Date: Wed, 22 Jul 2009 21:30:23 +0200

I would say, your expectation is false.
Assignments happens for sure at runtime, consider this simple example

SQL> create or replace procedure foo
 2  is
 3  n number := 1/0;
 4  begin
 5  null;
 6  end;
 7  /

Procedure created.

SQL> show error
No errors.


Aternatively, you can trace calls to your original bleah function and hopefully see in the tracefile access to the corresponding table, that should happen by every call. Deterministic functions can save you some fetches, but it is still runtime optimization.

Best regards

Maxim

Rich Jesse schrieb:
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@xxxxxxxxxxxxx
[mailto:oracle-l-bounce@xxxxxxxxxxxxx] 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;
/


--
//www.freelists.org/webpage/oracle-l





--
Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?

Aksel Peter Jørgensen

--
//www.freelists.org/webpage/oracle-l


Other related posts: