What is Difference between StoredProcedure and function?
Answers were Sorted based on User's Feedback
Answer / shankar
FUNCTION always return a value where as PROCEDURE may or
may not return value.
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / ganesh sial
1. Function is mainly used in the case where it must
return a value. Where as a procedure may or may not return
a value or may return more than one value using the OUT
parameter.
Â
2. Function can be called from SQL statements where as
procedure can not be called from the sql statements
3. Functions are normally used for computations where as
procedures are normally used for executing business logic.
4. You can have DML (insert,update, delete) statements in a
function. But, you cannot call such a function in a SQL
query.
5. Function returns 1 value only. Procedure can return
multiple values (max 1024).
6.Stored Procedure: supports deferred name resolution.
Example while writing a stored procedure that uses table
named tabl1 and tabl2 etc..but actually not exists in
database is allowed only in during creation but runtime
throws error Function wont support deferred name
resolution.
7.Stored procedure returns always integer value by default
zero. where as function return type could be scalar or
table or table values
8. Stored procedure is precompiled execution plan where as
functions are not.
Â
9.A procedure may modify an object where a function can
only return a value The RETURN statement immediately
completes the execution of a subprogram and returns control
to the caller.
2. Function -
1) Have to return a single value to the calling program
2) Can call functions in sql statements
3) Cannot return images
.
Procedures -
1) Do not return any value except assigning values to OUT
variables
2) Cannot call procedures in sql statements
3) Can return images
Is This Answer Correct ? | 1 Yes | 0 No |
We can use a function in the select query, but Procedure we
can't use in select query. But the function created with out
parameter, we can't use in select statement. Only in
parameter, we can use.
Is This Answer Correct ? | 1 Yes | 1 No |
What are the types of join in sql?
Does sql view stored data?
What is trigger price?
What does where 1/2 mean in sql?
i have a table like this. cityno cityname mails 1 BANGALORE 8KM 2 HSR LAYOUT 20KM 3 MEJISTIC 30KM 4 JAYADEVA 55KM 5 ITPL 80KM 6 HEBBAL 115KM I HAVE DATA LIKE THIS I WANT O/P LIKE THIS DISTANCE NO.OFCITY 0-50KM 3 51-100KM 2 101-150KM 4 AND SO ON pls give me answer. i want urgent
How to fetch records from a partitioned table?
How to delete same emp id in sql query for exmaple in emp table emp id, empname, emp address. for example emp id =5, repeated in two times in rows same id how to delete same empid please any one of the write query send in my id
Can function return multiple values in sql?
What are the operators used in select statements?
What is prepared statement in sql?
What are the different set operators available in sql?
What is database sql?