PL/SQL - Can function have OUT, IN OUT parameter ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • richasaraf
    New Member
    • Aug 2005
    • 23

    PL/SQL - Can function have OUT, IN OUT parameter ?

    Hi guys,
    Can someone help me...
    I want to know... can we have OUT, IN OUT parameters in function? :confused:
    And can we use it in select statement ?

    Thanks a lot !
    Take Care

    Richa :)
  • rsankpal
    New Member
    • Jul 2006
    • 2

    #2
    Yes, we have in-out parameter in function. we can use it in select statement.
    we can have more than one OUT parameter in function.But to execute this unction all this function in anonomous block and use dbms_output.put _line :)
    Last edited by rsankpal; Jul 27 '06, 06:27 AM.

    Comment

    • Mahesh_Bote
      New Member
      • Jul 2006
      • 26

      #3
      [code=oracle]

      Create Function Addition
      (
      @Num1 Int,
      @Num2 Int
      )
      Returns Int
      As
      Begin
      Return(@Num1 + @Num2)
      End

      Select DBO.Addition(3, 5)

      O/P
      ------------
      8

      [/code]


      we have create one function which accepts two parameters and will return one value in place of its name. thus, the fucntions which accepts parameters, these are inputs and what fucntion return, is output.

      Mahesh
      :) :) :)

      Comment

      • vijil
        New Member
        • Jul 2006
        • 14

        #4
        Hai richasaraf ,
        U can create function only in in mode.but u can create procedure in 3 ways(in,out,in out)

        Comment

        • sreepathi
          New Member
          • Aug 2006
          • 1

          #5
          hellow man
          u cant create a function that have morethan one out variable
          a function is that it gets any number of inputs and returns only one value
          A procedure can help u to satisfy ur needs .A procedure can have any number of in (input) variables and any number of out(return variable)variab les.
          A procedure can have variables that acts as both in and out variables

          [code=oracle]

          create or replace procedure pro_name(a in number,b ijn number,c out number,d out number,e in out number) is
          begin
          c:=a+b;
          d:=a-b;
          e:=a+b-e;
          end pro_name;


          this procedure can be called like this

          declare
          sum number;
          minus number;
          var1 number:=2;
          begin
          ------------
          pro_name(10,5,s um,minus,var1);
          -----------
          ---------
          -------------
          ----------
          end;

          [/code]

          here sum will be 15(10+5)
          minus will be 5(10-5)
          var1 will be 13(10+5-2)
          bye
          see u
          Last edited by amitpatel66; Dec 12 '07, 11:39 AM. Reason: code tags

          Comment

          • Alixandro Florian Cuevas
            New Member
            • Aug 2006
            • 3

            #6
            Dear Richa
            a function only return one value, only accep parameters IN not IN OUT or OUT.
            eg. Create or Replace Function Richa (var1 number, var2 in varchar2) Return Date, Varchar2 or number.

            example.
            [code=oracle]


            Create Or Replacr Function Telephone(Perso nID number) Return Varchar2 Is
            Cursor tel is
            Select tel_telefono telefono
            from tcli_telefono
            where tel_codcli = PersonID;
            --
            vTelefonos varchar2(500) Default null;
            vComa varchar2(1) := ',';
            --
            Begin
            For reg in tel loop
            vTelefonos := Reg.Telefono||v Coma||vTelefono s;
            --
            End Loop;
            Return( Rtrim(vTelefono s,','));
            End Telephone;

            [/code]
            Last edited by amitpatel66; Dec 12 '07, 11:41 AM. Reason: code tags

            Comment

            • dkarthick
              New Member
              • Sep 2006
              • 3

              #7
              a Function returns Exactly only one value. we canot use the OUT parameter in function.
              and also we can call a function from SQL prompt.

              for Example
              [code=oracle]


              CREATE OR REPLACE FUNCTION ADD(I NUMBER, J NUMBER)IS
              K NUMBER;
              BEGIN
              K:=I+J;
              RETURN(K);
              END ADD;


              --CALLING A FUNCTION:

              DECLARE
              N NUMBER;
              BEGIN
              N:=ADD(10,20);
              DBMS_OUTPUT.PUT _LINE('THE ADDITION OF TWO NUMBERIS :'||N);
              END;


              --OR


              SELECT ADD(10,20) FROM DUAL;
              [/code]
              Last edited by amitpatel66; Dec 12 '07, 11:43 AM. Reason: code tags

              Comment

              • saravanan120480
                New Member
                • Nov 2006
                • 2

                #8
                Originally posted by richasaraf
                Hi guys,
                Can someone help me...
                I want to know... can we have OUT, IN OUT parameters in function? :confused:
                And can we use it in select statement ?

                Thanks a lot !
                Take Care

                Richa :)

                hi
                function can have out arguments also. if the function has an out arguments then we can't use it in select or dml statments

                Comment

                • saravanan120480
                  New Member
                  • Nov 2006
                  • 2

                  #9
                  Originally posted by richasaraf
                  Hi guys,
                  Can someone help me...
                  I want to know... can we have OUT, IN OUT parameters in function? :confused:
                  And can we use it in select statement ?

                  Thanks a lot !
                  Take Care

                  Richa :)

                  hi
                  function can have out arguments also. if the function has an out arguments then we can't use it in select or dml statments

                  Thanks and Regards
                  saravanan p

                  Comment

                  • debasisdas
                    Recognized Expert Expert
                    • Dec 2006
                    • 8119

                    #10
                    Hi guys

                    We can use all the three parameter modes (IN,OUT, IN OUT ) in a function.

                    Please find the details regarding PL/SQL Function.

                    Comment

                    • Saii
                      Recognized Expert New Member
                      • Apr 2007
                      • 145

                      #11
                      yes, a function can have all three modes for parameters but underlying fact is that function should return only one value. So it is better to restrict the function parameter mode to IN, in case you want to have a functionality wherein you have an OUT parameter, use a procedure instead.

                      Comment

                      • rohitsharma1977
                        New Member
                        • Dec 2007
                        • 1

                        #12
                        Originally posted by richasaraf
                        Hi guys,
                        Can someone help me...
                        I want to know... can we have OUT, IN OUT parameters in function? :confused:
                        And can we use it in select statement ?

                        Thanks a lot !
                        Take Care

                        Richa :)
                        You can not use OUT parameters in function.

                        -Rohit

                        Comment

                        • amitpatel66
                          Recognized Expert Top Contributor
                          • Mar 2007
                          • 2358

                          #13
                          Originally posted by rohitsharma1977
                          You can not use OUT parameters in function.

                          -Rohit
                          We can use OUT MODE in function as well. CHeck this:

                          [code=oracle]

                          SQL> create or replace function add_num1(a IN NUMBER,b OUT NUMBER) RETURN NUMBER IS
                          2 BEGIN
                          3 dbms_output.put _line(a);
                          4 b:= a;
                          5 RETURN a;
                          6 END add_num1;
                          7 /

                          Function created.

                          SQL> var num1 number;

                          SQL> ed
                          Wrote file afiedt.buf

                          1 declare
                          2 ab number;
                          3 begin
                          4 ab:=add_num1(10 ,:num1);
                          5 dbms_output.put _line(:num1||', '||ab);
                          6* end;
                          SQL> /
                          10
                          10,10

                          PL/SQL procedure successfully completed.

                          [/code]

                          We cannot use this funciton from select statement:

                          [code=oracle]

                          SQL> select add_num1(10,:nu m1) from dual;
                          select add_num1(10,:nu m1) from dual
                          *
                          ERROR at line 1:
                          ORA-06572: Function ADD_NUM1 has out arguments

                          [/code]

                          Comment

                          • debasisdas
                            Recognized Expert Expert
                            • Dec 2006
                            • 8119

                            #14
                            You can use all the three modes in function .

                            find a related discussion here regarding function with IN OUT parameter.

                            Comment

                            Working...