What Are the Differences Between Functions and Stored Procedures?
Answer: Functions and stored procedures are two common objects in databases. Both of them can encapsulate a series of SQL statements to complete certain specific operations. For details about the differences, see Table 1.
| Function | Stored Procedure |
|---|---|
| The identifier of a function is FUNCTION. | The identifier of the stored procedure is PROCEDURE. |
| A function must have a return value. | A stored procedure can have or not have a return value. |
| Functions can input and output parameters. | Stored procedures can input and output parameters. |
| Functions can only call SELECT statements and cannot modify data in tables. | Stored procedures can modify data in tables, such as UPDATE, DELETE, and INSERT. |
| Stored procedures cannot be called in functions. | Functions and stored procedures can be called in stored procedures. A series of complex statements can be simplified. |
| Functions are used to return single values, for example, a data calculation result, a string processing result, or a table. | Stored procedures are used for DML operations, for example, inserting, updating, and deleting data in batches. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.