Reading problems and finding of others help us realize what we did wrong and to find some peculiar stuff.
Try this code:
CREATE OR REPLACE
PACKAGE my_pkg
as
procedure p;
end my_pkg;
/
CREATE OR REPLACE
package body my_pkg
as
g_global number;
procedure private( l_parameter in number )
is
begin
dbms_output.put_line( 'My Parameter value was ' || l_parameter );
g_global := 42;
dbms_output.put_line( 'My Parameter value is now ' || l_parameter );
end private;
procedure p
is
l_priv number;
begin
g_global := 55;
private(g_global);
g_global := 55;
l_priv:=g_global;
private(l_priv);
g_global := 55;
private(g_global+0);
end p;
end my_pkg;
begin
my_pkg.p;
end;
Qual é o Server output?
What is the Server output?
My Parameter value was 55 My Parameter value is now 42 (!!!!!!!) My Parameter value was 55 My Parameter value is now 55 My Parameter value was 55 My Parameter value is now 55
Pois é! Os valores em IN são passados por referencia, daí que passar variaveis globais tem este efeito.
Soluções possiveis:
-não usar variáveis globais
-passar para variavel local e depois usar isso na chamada
-somar 0 e assim a referencia é uma variavel interna
Yeap! The IN parameters are passed by reference (memory pointer) and so the global variables have this effect!
Possible solutions:
-Do not use global variables
-pass the value to an local variable
-add 0 and so the reference is to an "internal" variable
No comments:
Post a Comment
Os comentários são moderados.
The comments are moderated.