Differences between Oracle procedures and functions

Source: Internet
Author: User

Oracle process and function are expected to be more familiar. The following describes the differences between Oracle process and function. We hope that you can have a deeper understanding of Oracle process and function.

Oracle processes and functions are stored in the database in the form of compilation. functions can have either no parameter or multiple parameters and return a value. The process has zero or multiple parameters and no return value. Functions and processes can receive or return zero or multiple values through the parameter list. The main difference between a function and a process is not the return value, but the call method. The Oracle process is called as an independent execution statement:

 
 
  1. pay_involume(invoice_nbr,30,due_date); 

The function is called using a valid expression:

 
 
  1. order_volumn:=open_orders(SYSDATE,30); 

The syntax of the creation process is as follows:

 
 
  1. CREATE [ OR REPLACE] PROCEDURE [schema.]procedure_name  
  2. [parameter_lister]  
  3. {AS|IS}  
  4. declaration_section  
  5. BEGIN  
  6. executable_section  
  7. [EXCEPTION  
  8. exception_section]  
  9. END [procedure_name]   

The syntax for each parameter is as follows:

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

There are three modes: IN, OUT, And INOUT.

IN indicates that during the call process, the actual parameter value is passed to the process. The formal parameter is considered read-only. When the process ends, the control will return to the control environment, the actual parameter value does not change.

When an out api is called, the actual parameter values are ignored. In the process, parameters can only be assigned values, but cannot be read from them, after the process ends, the content of the formal parameter is assigned to the actual parameter.

The INOUT mode is a combination of IN and OUT. The value of the actual parameter IN the Oracle process is passed to the form parameter, and the value of the situation parameter is readable and writable. After the process ends, the value of the situation parameter is assigned to the actual parameter.

The syntax for creating a function is basically the same as that for a process. The only difference is that a function has a RETUREN clause.

 
 
  1. CREATE [ OR REPLACE] FINCTION [schema.]function_name  
  2. [parameter_list]  
  3. RETURN returning_datatype  
  4. {AS|IS}  
  5. declaration_section  
  6. BEGIN  
  7. executable_section  
  8. [EXCEPTION]  
  9. exception_section  
  10. END [procedure_name]   

Some functions must have multiple return statements.

You can call single-row and group functions in creating a function. For example:

 
 
  1. CREATE OR REPLACE FUNCTION my_sin(DegreesIn IN NUMBER)  
  2. RETURN NUMBER  
  3. IS   
  4. pi NUMBER=ACOS(-1);  
  5. RadiansPerDegree NUMBER;  
  6.  
  7. BEGIN  
  8. RadiansPerDegree=pi/180;  
  9. RETURN(SIN(DegreesIn*RadiansPerDegree));  
  10. END   


 

Use of Oracle to_char Functions

Implementation of oracle function return table

Learn about the Oracle FBI Index

How to uninstall an Oracle database in Windows

Multiple table Connection Methods in Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.