Procedure Vs. Function

By | February 24, 2016

PROCEDURE:

CREATE OR REPLACE procedure_name(arg1 data_type, …) AS BEGIN …. END procedure_name;

Example:

CREATE OR REPLACE
PROCEDURE ADD_EVALUATION
( evaluation_id IN NUMBER
, employee_id IN NUMBER
, evaluation_date IN DATE
, job_id IN VARCHAR2
, manager_id IN NUMBER
, department_id IN NUMBER
) AS
BEGIN
  NULL;
END ADD_EVALUATION;

FUNCTION:
CREATE OR REPLACE
FUNCTION calculate_score
( cat IN VARCHAR2
, score IN NUMBER
, weight IN NUMBER
) RETURN NUMBER AS
BEGIN
  RETURN score* weight;
END calculate_score;

KEY DIFFERENCES:

-A function always return a values while procedure can return one or more values through Parameters.

-A function can be call directly by sql statement like select “func_name” from dual while procedure cannot

-DML statement cannot be used in function,but it used in procedure.

Leave a Reply

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


*