What are main difference between Stored Procedure and
Functions.
Answers were Sorted based on User's Feedback
Answer / guru
stored procedure : It is Pre Compiled Code(PCode) it is stored
in Database. we can reuse without compile.
Function: It need compile whenever it will run.
Is This Answer Correct ? | 15 Yes | 4 No |
The Main difference between stored procedure and Function
is SP's can return the value or not, but Functions should
return the value.
And We can use the function within the Queries, but sp's we
won't able to use it in the queries.
We can implicitely execute the sp's. But function's we
can't.
Is This Answer Correct ? | 11 Yes | 1 No |
Answer / abapdeveloper09
Adding to S. Elaiyaraja's responnse:
- Functions should have RETURN clause
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / hemanth
1) functions are used for computations where as procedures
can be used for performing business logic
2) functions MUST return a value, procedures need not be.
3) you can have DML(insert, update, delete) statements in a
function. But, you cannot call such a function in a SQL query..
eg: suppose, if u have a function that is updating a table..
you can't call that function in any sql query.
- select myFunction(field) from sometable;
will throw error.
4)We can call a function from a procedure, but it is not
possible to call a procedure from a function
Is This Answer Correct ? | 6 Yes | 4 No |
Answer / abhirup roy
In The above answers all the major differences have been disclosed, with one wrong information.
We can call a procedure from a function and vice-versa (as long as the function and procedure has same/similar scope).
In order to defend my point I am posting one small code below for reference.
DECLARE
PROCEDURE my_proc;
FUNCTION my_func RETURN NUMBER IS
BEGIN
my_proc;
RETURN -003;
END my_func;
PROCEDURE my_proc IS
BEGIN
DBMS_OUTPUT.PUT_LINE('22');
END my_proc;
BEGIN -- main
DBMS_OUTPUT.PUT_LINE(my_func);
END;
-- IT WILL WORK FOR EVERY OCCURRENCE --
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / preethi
another important difference between procedure and function
is inside procedure we can use DML statements but inside the
function only select can be used not delete and update.
Is This Answer Correct ? | 4 Yes | 4 No |
Is oracle a relational database?
How can return max date row A b c d e 1 2 1-mar-09 5 10 1 2 10-mar-09 5 10 Only using oracle predefined function. Not user defined. Output:-- A b c d e 1 2 10-mar-09 5 10
What is a procedure in oracle?
Can we convert a date to char in oracle and if so, what would be the syntax?
How to put more than 1000 values into an oracle in clause?
How to convert the date format from dd/mm/yyyy to mm/dd/yyyy. (for eg). 22/05/2008 to 05/22/2008. when u use to_char(), it tells the month is invalid. how to resolve this problem.tel with eg.
What are internal user account in oracle?
Explain what are the advantages of views?
what are the disadvantages of hierarchial database over RDBMS?
What is object data modeling?
How to call a trigger inside a stored procedure?Give an example.
How can we manage the gap in a primary key column created by a sequence? Ex:a company has empno as primary key generated by a sequence and some employees leaves in between.What is the best way to manage this gap?