Qus: What is the difference between Function and Stored procedure?
• A Stored Procedure is always used to perform a specific task.
• It can return zero, one or more value.
• It can have both input and output parameters.
• Exception handling can be done using a try-catch block.
• A function can be called from a Procedure.
2. By using a try-catch block, an exception can be handled in a Procedure. Whereas, you can’t use try-catch block in a Function to handle the exception.
3. You can’t utilize Procedures in a SELECT statement. But Function can be utilized in a SELECT statement.
4. The procedure allows as DML(INSERT/UPDATE/DELETE) as well as a SELECT statement in it. Whereas, Function allows only SELECT statement in it.
5. Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT statement. The function can be used in the SQL statements anywhere in SELECT/WHERE/HAVING syntax.