x

Difference between a FUNCTION, PROCEDURE and PACKAGE in Oracle ?

I need the differences bettwen a FUNCTION, PROCEDURE and PACKAGE in Oracle. Which one is better to use in most of the times ? Thank you.

more ▼

asked Jan 05, 2010 at 11:41 AM in Default

OracleApprender gravatar image

OracleApprender
771 69 73 75

(comments are locked)
10|1200 characters needed characters left

3 answers: sort voted first

Functions return a value, procedures don't, otherwise they're identical.

A Package is a container that may have many functions and procedures within it. It provides useful capabilities such as scoping, interface definition and modular development.

It's generally advisable to put your procedures and functions into packages with well designed interfaces.

more ▼

answered Jan 05, 2010 at 11:46 AM

Andrew Mobbs gravatar image

Andrew Mobbs
1.5k 1 3

Procedures can return values via OUT params.
Jan 05, 2010 at 12:24 PM HillbillyToad
True, but that's not quite the same as a function returning a value. Since functions guarantee a return value in a standard way, they can be part of an expression, whereas procedures can't. e.g. SELECT sqrt(x) + sqrt(y) FROM dual;
Jan 06, 2010 at 06:26 AM Andrew Mobbs
So other than the return values there is no difference in between Functions and Procedures. I mean in point of performance.
Jan 06, 2010 at 06:52 AM OracleApprender
There's no intrinsic difference in performance, a single call to a function is just as fast as a single call to a procedure. However because functions can be used in expressions, they can be used to write poorly performing queries. For example, a function can be put in a WHERE clause, which may cause it to be evaluated many times. That isn't a performance issue with the function, the problem is in how it is being used.
Jan 06, 2010 at 08:00 AM Andrew Mobbs
(comments are locked)
10|1200 characters needed characters left

Package: A Collection of related variables,cursor,procedure,and functions Package will support oops features like encaplution and data hiding and function overloading(8.0), to declare package in 2 steps 1.package specification 2.package body SubPrograms: A set of pl/sql statements is stored in database and used to perform a task; there are 2 types of subprograms 1.Procedures 2.Functions Procedure:A subprogram type perform a task and will not return value. and used to perform dml operations on database Function:A subprogram type perform a task and may or may not return value,but it will return only one value.

more ▼

answered Nov 25, 2010 at 02:32 AM

Anil kumar gravatar image

Anil kumar
1

(comments are locked)
10|1200 characters needed characters left
-procedures accept 'in,out,inout' mode of parameter while function use 'in' mode. -procedure may or not return one or more value but function return a value. -procedure can not user return keyword but in function we use return keyword. -procedure can not execute in select statement but function can execute in select statement. -we can perform commit operation in procedure but in funtion we can not perform commit operation(using pragma autonomous_transaction we can perform commit operation). -package is collection of procedure,function,cursor which follow oop concept like encapsulation,data hiding.
more ▼

answered Jun 25 at 10:00 AM

nrenyadav gravatar image

nrenyadav
1

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x378
x27
x24
x19

asked: Jan 05, 2010 at 11:41 AM

Seen: 18389 times

Last Updated: Jun 25 at 10:00 AM