What is the difference between Oracle functions and stored procedures

Source: Internet
Author: User

What is the difference between Oracle functions and stored procedures

1. The difference between the return value, the function has 1 return values, and the stored procedure is returned by the parameter, can have more or No 2. The difference between the calls, the function can be called directly in the query statement, The stored procedure must be called separately. The function is generally used to calculate and return a calculation and the stored procedure is typically used to complete a particular data operation (such as modifying, inserting a database table, or executing some DDL statements, etc.). If you return multiple parameter values, it is best to use a stored procedure. A function can be used if there is only one return value, and from the invocation: if it is called in a SQL statement (DML or select) it must be a stored function or a stored wrapper function that cannot be a stored procedure, but there are a number of limitations and the level of purity of the function when calling the stored function. If it is called in a procedural statement, it depends on what kind of functionality you want to implement. Functions are typically used to calculate and return a calculation and stored procedures are typically used to complete specific data operations (such as modifying, inserting database tables, or executing certain DDL statements, etc.), so although they are syntactically similar, the functionality that users need to do when they use them is mostly different. The biggest difference between Oracle functions and stored procedures is that the function must carry a return value followed by the type of the return value, and the stored procedure can have no return value. In addition, stored procedures and functions also support the in,out,in out of the three types of parameters, corresponding to the input parameters, output parameters, input and output type parameters. That is, if we need to return multiple values, in addition to using stored procedures to implement, you can also use a function to do so, by returning one of them with a return, the other indicates that the data is an out parameter. Stored procedures and functions in Oracle can return values, but the function must return a value and generally only return a value, while stored procedures do not have this restriction. From a general point of view, if you do not need to return a value or need multiple return values, using stored procedures, if you use only one return value, the function is used, from the general Programmer's habit, this is more consistent with thinking. and the name of the stored procedure is best to begin with PROC_, the function is func_, the variables should be preceded by V_, the code can consider indentation, enhance the readability and aesthetics!

What is the difference between Oracle functions and stored procedures

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.