Help Center/ GaussDB/ Developer Guide(Centralized_V2.0-2.x)/ Stored Procedure/ Basic Statements/ Call Statements
Updated on 2025-08-19 GMT+08:00
Call Statements
Syntax
Figure 1 shows the syntax diagram for calling a clause.
The above syntax diagram is explained as follows:
- procedure_name specifies the name of a stored procedure.
- parameter specifies the parameters for the stored procedure. You can set no parameter or multiple parameters.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | -- Create a table. openGauss=# CREATE SCHEMA hr; openGauss=# SET CURRENT_SCHEMA = hr; openGauss=# CREATE TABLE staffs ( section_id INTEGER, salary INTEGER ); openGauss=# INSERT INTO staffs VALUES (30, 10); openGauss=# INSERT INTO staffs VALUES (30, 20); -- Create the stored procedure proc_staffs. openGauss=# CREATE OR REPLACE PROCEDURE proc_staffs ( section NUMBER(6), salary_sum out NUMBER(8,2), staffs_count out INTEGER ) IS BEGIN SELECT sum(salary), count(*) INTO salary_sum, staffs_count FROM hr.staffs where section_id = section; END; / -- Create the stored procedure proc_return. openGauss=# CREATE OR REPLACE PROCEDURE proc_return AS v_num NUMBER(8,2); v_sum INTEGER; BEGIN proc_staffs(30, v_sum, v_num); -- Call a statement. dbe_output.print_line(v_sum||'#'||v_num); RETURN; -- Return a statement. END; / -- Call the stored procedure proc_return. openGauss=# CALL proc_staffs(2,8,6); -- Drop the stored procedure. openGauss=# DROP PROCEDURE proc_staffs; openGauss=# DROP PROCEDURE proc_return; -- Create the function func_return. openGauss=# CREATE OR REPLACE FUNCTION func_return returns void language plpgsql AS $$ DECLARE v_num INTEGER := 1; BEGIN dbe_output.print_line(v_num); RETURN; -- Return a statement. END $$; -- Call the function func_return. openGauss=# CALL func_return(); -- Drop the function. openGauss=# DROP FUNCTION func_return; -- Drop the current database schema. openGauss=# DROP SCHEMA hr CASCADE; |
Parent topic: Basic Statements
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.
