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

avatar image

OracleApprender
771 73 75 79

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

5 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

avatar image

Andrew Mobbs
1.6k 3 5

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

avatar 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, 2014 at 10:00 AM

avatar image

nrenyadav
1

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

The most important difference between procedure and a function is: procedure is compiled only once. Function is compiled every time you call it. So basically stored procedure is more efficient than function. Both function and procedure return a value. As mentioned above, package is like a container for function and stored procedure. It is like a way to define API. Once you define your Package, you can access it from outside just alike any API.

more ▼

answered Oct 03, 2014 at 10:03 AM

avatar image

Metmuler
1

Metmuler

I understand that you say if my function and procedure are within a package I can call/access them from anywhere. Does this mean now even on Java I can just access it?

Dec 04, 2014 at 01:02 PM CzaRose
(comments are locked)
10|1200 characters needed characters left

Check the difference between Storeprocedure and function On stackoverflow site with samples

more ▼

answered Dec 04, 2014 at 01:51 PM

avatar image

ecomma
470 18 22 26

(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

SQL Server Central

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

Topics:

x426
x33
x30
x25

asked: Jan 05, 2010 at 11:41 AM

Seen: 39307 times

Last Updated: Dec 04, 2014 at 01:51 PM

Copyright 2016 Redgate Software. Privacy Policy