What are the differences between oracle functions and stored procedures?

Source: Internet
Author: User

What are the differences between oracle functions and stored procedures? 1. the difference between return values. A function has one return value, while a stored procedure returns multiple or no 2 values through a parameter. the difference between calling. A function can be called directly in a query statement, and a stored procedure must be called independently. A function is generally used to calculate and return a computing result, while a stored procedure is generally used to perform specific data operations (such as modifying, inserting a database table, or executing some DDL statements) if multiple parameter values are returned, it is best to use the stored procedure. If only one return value is returned, you can use the function. From the call situation, if the SQL statement (DML or SELECT) the stored function or the stored encapsulated function cannot be a stored procedure, but there are many restrictions and the purity level of the function when calling the stored function. if it is called in a procedural statement, it depends on what features you want to implement. A function is generally used to calculate and return a computing result, while a stored procedure is generally used to perform specific data operations (such as modifying, inserting a database table, or executing some DDL statements ), so although their syntax is very similar, the functions that users need to complete when using them are mostly different. The biggest difference between an oracle function and a stored procedure is that a function must carry a return value, followed by a type of return value, while a stored procedure can have no return value. In addition, stored procedures and functions also support the in, out, and in out parameters, which indicate the input parameters, output parameters, and input and output parameters respectively. That is to say, if we need to return multiple values, in addition to using stored procedures, we can also use functions to implement them by returning one of them, you can specify the data as the out parameter. In Oracle, stored procedures and functions can return values, but functions must return values. Generally, only one value is returned. stored procedures do not have this restriction. From the general application perspective, if no return value or multiple return values are required, the stored procedure is used. If only one return value is used, the function is used. From the programmer's habits, this is more in line with thinking. In addition, it is best to name stored procedures with proc _ headers, while functions with func _ headers and variables with v _ headers. The code can be indented to enhance readability and aesthetics!

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.