difference between functions and stored procedures [message #97682] |
Fri, 08 November 2002 13:27  |
saleema
Messages: 1 Registered: November 2002
|
Junior Member |
|
|
hi.
could anyone tell me what is the differance between a function and procedure in ORACLE and if I would use functions instead of procedures would it affect theperfromance as comapred to using stored procedures.
|
|
|
Re: difference between functions and stored procedures [message #97689 is a reply to message #97682] |
Wed, 13 November 2002 11:02   |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
functions return a value (or record or pl/sql table or whatever) and procedures dont. Both functions and procedures support in, in/out and out parameters.
Whether you use a function or procedure is often just a matter of programming style. Functions have the advantage of being able to be imbedded in a larger statement. e.g.
x := lower(trim(lpad(v1, 'x', 3)));
If you wanted to set a value you would likely use a procedure:
set_emp_sal('John', 1000);
If you wanted to get the value, you would typically use a function:
x := get_emp_sal('John');
|
|
|
|
|
|
|
|
Re: difference between functions and stored procedures [message #98259 is a reply to message #97689] |
Tue, 01 June 2004 23:29   |
muralidhar
Messages: 13 Registered: September 2002
|
Junior Member |
|
|
Stored Procedure :supports deffered name resoultion 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 deffered name resolution. Stored procedure returns always integer value by default zero. where as function return type could be scalar or table or table values(SQL Server).Stored Procedure is pre compiled exuction plan where as functions are not.
|
|
|
|
functions and storedprocedure [message #98385 is a reply to message #98245] |
Sun, 05 September 2004 23:05   |
sasikumar
Messages: 1 Registered: September 2004
|
Junior Member |
|
|
Hi,
Functions and storedprocedure :
1.We can call the functions in sql statements (select max(sal) from emp). where as sp is not so
2.Function do not return the images,text whereas sp returns all.
Have a nice day!
by
Sasikumar.R
|
|
|
Re: difference between functions and stored procedures [message #98440 is a reply to message #97689] |
Sun, 10 October 2004 22:28   |
sriharik
Messages: 1 Registered: October 2004
|
Junior Member |
|
|
Hi,
Please give more information and examples if u have any to find the exact difference between the functions and stored procdures.On the basis of perfomance with one is good.please if u know any links where i can find the exact complete diffrences list of both of them.I am very thank full to u guys...
Thanks,
Srihari.k
|
|
|
|
|
|
Re: difference between functions and stored procedures [message #98530 is a reply to message #97689] |
Fri, 17 December 2004 00:17   |
jagadish
Messages: 4 Registered: April 2004
|
Junior Member |
|
|
Difference bw functions and procedures:
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) function parameters are always IN, no OUT is possible
|
|
|
|
Re: difference between triggers and procedures [message #98585 is a reply to message #98517] |
Mon, 17 January 2005 18:49   |
paramasivam
Messages: 1 Registered: January 2005
|
Junior Member |
|
|
function - it perform some calculation and one value must be return by function.
after compiling the named function, one object is created in your data base.
you can use this function is any DML statements
procedure
it performs fome action. it may or may not return values.
you cann't use this function in any DML statement.
but it is possible to call this named procedure from any oracle developer tools like forms, reprots,
|
|
|
|
Re: difference between functions and stored procedures [message #211286 is a reply to message #211216] |
Wed, 27 December 2006 16:06  |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
1. A function can have return statement where as a procedure cannot have a return statement.
>> A function always has a return value. The "value" have be one of many things including pl/sql tables, ref cursors etc.
2. A procedure can be executed separately from SQL and also can be invoked from some other procedures or functions where as a function can only be invoked from a function or a procedure.
>> A function can be called from anonomous pl/sql - the return value needs somewhere to go...
exec dbms_output.put_line(my_funct());
3. A function can be used in DML where as a procedure cannot be invoked from a DML.
>> Triggers can call functions. procedures can't be called directly in sql statements. Procedures can be called from simple wrapper functions.
4. We cannot use DDL in a function where as in procedure it is possible using dynamic SQL package.
>> dml can be used in functions and procedures
5. A procedure can be either stored procedure or an anonymous where as a function cannot be anonymous.
>> anonomous pl/sql is not usually refered to as a procedure in Oracle.
6. We cannot use a Transaction control language in a function where as in Procedures we can use TCL.
>> Not true in general. (in any case, a wrapper function can call procedures so anything a procedure and do a function can do)
7. Functions can also have IN and OUT parameters.
>> yes
8. Functions are used for computations where as procedures can be used for performing business logic.
>> functions and procedures can be used for whatever you choose.
|
|
|