Principle of Programming Language

Q. : What is the difference between procedure and function? Explain with suitable example

Ans:

1. Procedure may or may not return value where as function should return one value.
2. Procedure can performs one or more tasks where as function performs a specific task.
3. we can call functions in select statement where as procedure we cant.
4. We can call Stored Procedure within function but we can not call function within stored procedure. 5.A FUNCTION must be part of an executable statement, as it cannot be executed independently where as procedure represents an independent executable statement.
5. Function can be called form SQL statement where as procedure can not be called from the SQL statement.
6. Function are normally used for computation where as procedure are normally used for executing business logic.
7. Stored procedure supports deferred name resolution where as function wont support.
8. Stored procedure returns always integer value by default zero. whrer as function returns type could be scalar or table or table value. 10.Stored procedure is precompiled execution plan where as function are not.