Search code examples
sqloracle-databaseplsqlplsql-package

If we have out parameter in plsql procedure and return in function.Then why we use procedure instead of function?


If we have only Out parameter in our PLSQL procedure.Then can we use function instead of procedure as function is also able to return the value. And if we still using procedure then we use this instead of function.

I hope I am able to convey the right question which I want to ask?


Solution

  • Some important difference between both are as following:

    Function:

    • It can be called from the SQL statement (SELECT, UPDATE, DELETE)
    • Can return only one value
    • DML operations are not allowed in it
    • Best for selecting the value for some common complex logic.

    Procedure:

    • It cannot be called from the SQL statement. You must need the PL/SQL block to call it.
    • Can return multiple values (OUT parameters)
    • All DML operations are allowed within procedures.
    • Best for doing some complex logic and updating the table data accordingly.