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

Home -> Community -> Usenet -> c.d.o.server -> Re: Global Variable passed as IN parameters, bug or feature?

Re: Global Variable passed as IN parameters, bug or feature?

From: Michel Cadot <micadot{at}altern{dot}org>
Date: Tue, 29 Nov 2005 18:10:35 +0100
Message-ID: <438c8b8b$0$16217$626a14ce@news.free.fr>

"Ziad" <zarabo_at_gmail.com> a écrit dans le message de news: 1133279290.658326.61000_at_g44g2000cwa.googlegroups.com...
| Hi Guys,
| I have a strange thing happening related to global variables, and I
| want to know whether this is a bug or a feature. I am using Oracle
| 10g.
| I have this package.
| create or replace package test
| is
| a number:=1; -- global variable
|
| procedure pass_a;
|
| end test;
| /
|
| create or replace package body test
| is
|
| procedure print_a (p_a in number)
| is
| begin
| a:=2;
| dbms_output.put_line(p_a);
| end print_a;
|
| procedure pass_a
| is
| begin
| print_a(a);
| end pass_a;
| end test;
| /
|
| When I call test.pass_a from sqlplus, the procedure should call
| print_a(a). "a" at this time is equal to 1, so basically, I am passing
| 1 to the print_a. In print_a, I change the global variable 'a' to 2
| before I issue the dbms_output. Note, I am changing the global
| variable and not the IN parameter p_a. p_a should still be equal to 1.
| To my surprise, the dbms_output prints 2 and not 1.
| This means, changing the global variable that was passed to the
| procedure actually changes the local variable itself.
| Is this correct? Is it a feature, or a bug?
| Thanks.
|

Because IN parameters are passed by reference and not by value. If you want to pass it by value declare it as IN OUT parameter.

Regards
Michel Cadot Received on Tue Nov 29 2005 - 11:10:35 CST

Original text of this message

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