Functions
Overview
A function is a database object that returns a single value or a table object. A function must have a defined return value type. It applies to scenarios where a single value needs to be returned, for example, calculation, data conversion, or table data return.
Examples
The following example shows the creation of a function named add_num() that takes two integer parameters as input and returns their sum.
-- Create a function. gaussdb=# CREATE OR REPLACE FUNCTION add_num(int, int) RETURNS int AS $$ BEGIN RETURN $1+$2; END; $$ LANGUAGE plpgsql; -- Use the add_num() function. gaussdb=# SELECT add_num(3,4); add_num --------- 7 (1 row) -- Drop the function. gaussdb=# DROP FUNCTION add_num; DROP FUNCTION
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot