Search code examples
sqloracle-databasefunctionsql-function

How to call an Oracle Function with multi out parameters


Possible Duplicate:
CALLING A STORED PROCEDURE IN TOAD

I am given a function in Oracle as i have shown below.However i could not make it run.

FUNCTION GetAdres (pCif        NUMBER,
                    pAddressno NUMBER DEFAULT 0,
                   pAdrSerino NUMBER ,
                    pRAdres      OUT T_ADRES%ROWTYPE,
                   pErrCode      OUT NUMBER,
                   pErrMes      OUT VARCHAR2
                     )

Solution

  • Think you should use a Procedure, not a Function

    An Oracle function can return one -and only one- value, with another syntax.

    CREATE FUNCTION GetAdres(parameter1  IN NUMBER, parameter2 IN NUMBER) 
       RETURN NUMBER
    

    In fact, you can have OUT parameters in an Oracle Function (my bad), but you need a unique return type anyway.

    But

    You can perfectly use multiple OUT parameters in an Oracle procedure...

    So

    Solution1 (and I would go for this one)

    Use a procedure instead of a function

    Solution2

    Create a custom type and use it as the return type.

    create a custom type
    CREATE TYPE my_type as object
        (Adres      VARCHAR2(100), 
         ErrCode    NUMBER,
         ErrMes     VARCHAR2(250));
    
    
    CREATE FUNCTION GetAdres (pCif        NUMBER,
                        pAddressno NUMBER DEFAULT 0,
                       pAdrSerino NUMBER)
      RETURN my_type;