Help Center/ GaussDB/ Developer Guide(Centralized_V2.0-8.x)/ FAQ/ What Are the Differences Between Functions and Stored Procedures?
Updated on 2025-05-29 GMT+08:00

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.

Table 1 Differences between functions and stored procedures

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.