x
login about faq Site discussion (meta-askssc)

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 '10 at 11:41 AM in Default

OracleApprender gravatar image

OracleApprender
763 53 67 73

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

2 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 '10 at 11:46 AM

Andrew Mobbs gravatar image

Andrew Mobbs
1.5k 1 3

Procedures can return values via OUT params.

Jan 05 '10 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 '10 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 '10 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 '10 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 '10 at 02:32 AM

Anil kumar gravatar image

Anil kumar
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.

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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x359
x25
x21
x12

asked: Jan 05 '10 at 11:41 AM

Seen: 12861 times

Last Updated: Jan 05 '10 at 11:41 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.