2 Replies Latest reply: Dec 30, 2012 6:19 AM by Frank Kulash RSS

    Call by reference

    Oracle Maniac
      Hi All,

      IN parameters in oracle subprograms are known to be passed by reference. What all C i studied , would have implemented the code like .

      formal Parameter of procedure P1 :
      (par1 IN NUMBER) --oracle's representation

      Now , C representation -->(par1* int)
      .i.e. the par1 will be a pointer to the address of the actual parameter passed at invocation.




      Actual parameter while calling the procedure P1 :
      x:=111;--oracle's representation
      P1(x);--oracle's representation

      Now ,C representation
      x=10;
      P1(&x); ---


      Is this what it really does ?


      I may be totally wrong but its good to be wrong at times , regarding the below points .

      compiler's Job checking the syntactic & semantic references & creating a compiled code.
      Does the compiler create some sort of C related code ? since oracle is written in C .
        • 1. Re: Call by reference
          Stew Ashton
          Rahul  K wrote:
          IN parameters in oracle subprograms are known to be passed by reference
          Yes, IN parameters are passed by reference.

          OUT and IN OUT parameters are passed by value, unless you specify NOCOPY. If you specify NOCOPY, the parameters might be passed by reference. See
          http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/subprograms.htm#i4107
          Does the compiler create some sort of C related code ? since oracle is written in C .
          By default, the compiler creates PL/SQL bytecode that is executed by the PL/SQL interpreter engine.

          In 11GR2, you can ask the compiler to create C code. That is called "native" compilation. See
          http://docs.oracle.com/cd/E11882_01/server.112/e25513/initparams193.htm#REFRN10253

          Edited by: Stew Ashton on Dec 30, 2012 12:56 PM
          • 2. Re: Call by reference
            Frank Kulash
            Hi,
            Rahul  K wrote:
            Hi All,

            IN parameters in oracle subprograms are known to be passed by reference. What all C i studied , would have implemented the code like .

            formal Parameter of procedure P1 :
            (par1 IN NUMBER) --oracle's representation

            Now , C representation -->(par1* int)
            .i.e. the par1 will be a pointer to the address of the actual parameter passed at invocation.




            Actual parameter while calling the procedure P1 :
            x:=111;--oracle's representation
            P1(x);--oracle's representation

            Now ,C representation
            x=10;
            P1(&x); ---


            Is this what it really does ?
            I'm not sure I understand you, but I think you have it right. IN arguments in PL/SQL are passed by reference. A procedure such as p1 gets a pointer to the argument, not a copy of the value.
            The PL/SQL manual has a handy chart comparing parameter types
            I may be totally wrong but its good to be wrong at times , regarding the below points .

            compiler's Job checking the syntactic & semantic references & creating a compiled code.
            Does the compiler create some sort of C related code ? since oracle is written in C .
            If you use Native Compilation , then the compiled code may be C. (It's platform-dependent.)