Difference Analysis of Oracle Process and Function

  • 2021-12-21 05:28:15
  • OfStack

I believe everyone knows Oracle process and function better. The following is a detailed introduction to the differences between Oracle process and function 2, hoping to give you a deeper understanding of Oracle process and function.

Oracle procedures and functions are stored in the database in compiled form, and functions can have no parameters or multiple parameters and have a return value. Procedure has zero or more parameters and no return value. Both functions and procedures can receive or return zero or more values through a parameter list. The main difference between functions and procedures is not the return value, but the way they are called. The Oracle procedure is called as a stand-alone execution statement:

pay_involume(invoice_nbr,30,due_date);

Function is called as a legal expression:

order_volumn:=open_orders(SYSDATE,30);

The syntax for the creation process is as follows:


CREATE [ OR REPLACE] PROCEDURE [schema.]procedure_name 
[parameter_lister] 
{AS|IS} 
declaration_section 
BEGIN 
executable_section 
[EXCEPTION 
exception_section] 
END [procedure_name] 

The syntax for each parameter is as follows:

paramter_name mode datatype [(:=|DEFAULT) value]

There are three forms of mode: IN, OUT and INOUT.

IN means that when the procedure is called, the values of the actual parameters are passed to the procedure, the formal parameters are considered read-only, and when the procedure ends, the control will return to the control environment, and the values of the actual parameters will not change.

In OUT, the values of actual parameters will be ignored when calling the procedure. In the procedure, formal parameters can only be assigned, but data cannot be read from it. After the procedure is finished, the contents of formal parameters will be assigned to actual parameters.

INOUT is a combination of IN and OUT; In Oracle process, the values of actual parameters will be passed to formal parameters, and the values of situation parameters can be read or written. After the process is finished, the values of situation parameters will be given to actual parameters.

The syntax for creating the function is basically the same as the syntax for the procedure, except that the function has an RETUREN clause


CREATE [ OR REPLACE] FINCTION [schema.]function_name 
[parameter_list] 
RETURN returning_datatype 
{AS|IS} 
declaration_section 
BEGIN 
executable_section 
[EXCEPTION] 
exception_section 
END [procedure_name]

There must be one or more return statements in the execution part of the function.

You can call single-line functions and group functions in the creation function, for example:


CREATE OR REPLACE FUNCTION my_sin(DegreesIn IN NUMBER) 
RETURN NUMBER 
IS  
pi NUMBER=ACOS(-1); 
RadiansPerDegree NUMBER; 
 
BEGIN 
RadiansPerDegree=pi/180; 
RETURN(SIN(DegreesIn*RadiansPerDegree)); 
END 

Related articles: