Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming / Difference Between Procedures and Functions in Programming

Difference Between Procedures and Functions in Programming

January 26, 2011 Posted by Olivia

Procedures vs Functions in Programming

Procedures and Functions in programming, allow programmers to group instructions together in a single block and it can be called from various places within the program. The code becomes easier to understand and more compact. By performing the modifications in a single place, the whole code will get affected. With the help of functions and procedures; a linear and long code can be divided into independent sections. They provide more flexibility to the coding of various programming languages and databases.

What are functions?

Functions are capable of accepting parameters which are also known as arguments. They carry out the tasks according to these arguments or parameters and return values of given types. We can explain it better with the help of an example: A function accepts a string as a parameter and returns the first entry or record from a database. It takes into account the content for a specific field that begins with such characters.

The syntax of function is as follows:

CREATE OR REPLACE FUNCTION my_func

(p_name IN VARCHAR2 := ‘Jack’) return varchar2 as begin … end

What are procedures?

Procedures can accept the parameters or arguments and they carry out tasks as per these parameters. If a procedure accepts a string as a parameter and it gives out a list with records in database for which content of a specific field begin with such characters.

The syntax of procedures is as follows:

CREATE OR REPLACE PROCEDURE my_proc

(p_name IN VARCHAR2 := ‘Jack’) as begin … end

Mainly, there are two ways by which a parameter is passed in functions and procedures; by value or by reference. If parameter is passed by a value; the modification is affected within the function or procedure without affecting the actual value of it.

On the other hand, if the parameters are passed by references; the actual value of this parameter will be changed wherever it is called within the code as per the instructions.

Difference between procedures and functions

• When the parameter is passed into the procedure; it does not return any value whereas a function always returns a value.

• One of the major differences in both of them is that procedures are not used in databases whereas functions play an important role in returning values from a database.

• Procedures are capable of returning multiple values and the functions are able to return limited values.

• DML operations can be used in stored procedures; however, they are not possible in functions.

• Functions can return only one value and it is mandatory whereas procedures can return n or zero values.

• In functions, error handling cannot be done whereas it can be performed in stored procedures.

• Input and output parameters can be passed in procedures whereas in case of functions; only input parameters can be passed.

• Functions can be called from procedures whereas it is not possible to call a procedure from a function.

• Transaction management can be considered in procedures and it cannot be considered in case of functions.

Related posts:

Difference Between Java and C language Difference Between C and C++ Difference Between Objects and Classes Difference Between Java and JavaScript Difference Between Graph and Tree

Filed Under: Programming Tagged With: arguments, C, Function, function call, functions in programming, Java, linear code, long code, no procedural, Oracle, parameter passing, parameters, procedural call, Procedure, procedure call, procedures in programming, Programming languages, transaction management

About the Author: Olivia

Olivia is a Graduate in Electronic Engineering with HR, Training & Development background and has over 15 years of field experience.

Comments

  1. SourDove says

    November 4, 2015 at 2:17 am

    When you type, “When the parameter is passed into the procedure; it does not return any value whereas a function always returns a value,” do you mean the parameter does not return a value, or do you mean the procedure does not? It seems to mean the procedure because you are comparing procedures to functions, which may return a value, and because a parameter can’t return anything.

    In that case, this statement, “Procedures are capable of returning multiple values,” and this one, “Functions can return only one value and it is mandatory whereas procedures can return n or zero values” appear to contradict the first.

    Also, I use plenty of functions that return no value.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Phase Velocity and Group Velocity

What is the Difference Between Pedagogy Andragogy and Heutagogy

What is the Difference Between Pedagogy Andragogy and Heutagogy

Difference Between Chemical and Physical Reaction

Difference Between Chemical and Physical Reaction

Difference Between S Note and Action Memo

Difference Between S Note and Action Memo

Difference Between Google CDN and Akamai CDN

Latest Posts

  • What is the Difference Between Flakiness Index and Elongation Index
  • What is the Difference Between Salmonella and Shigella
  • What is the Difference Between NTU and FTU
  • What is the Difference Between Escherichia coli and Entamoeba coli
  • What is the Difference Between Education and Socialization
  • What is the Difference Between Nurse Crop and Cover Crop
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018 Difference Between. All rights reserved. Terms of Use and Privacy Policy: Legal.