CALL
Description
Calls defined functions and stored procedures.
Precautions
The owner of a function or stored procedure, users granted with the EXECUTE permission on the function or stored procedure, or users granted with the EXECUTE ANY FUNCTION permission can call the function or stored procedure. The system administrator has the permission to call the function or stored procedure by default.
Syntax
1
|
CALL [ schema.] { func_name | procedure_name } ( param_expr ); |
Parameters
- schema
Specifies the name of the schema where a function or stored procedure is located.
- func_name
Specifies the name of the function or stored procedure to be called.
Value range: an existing function name
You can use database links to perform operations on remote functions or stored procedures. For details, see DATABASE LINK.
- param_expr
Specifies a list of parameters in the function. Use := or => to separate a parameter name and its value. This method allows parameters to be placed in any order. If only parameter values are in the list, the value order must be the same as that defined in the function or stored procedure.
Value range: an existing function parameter name or stored procedure parameter name
- The parameters include input parameters (whose name and type are separated by IN) and output parameters (whose name and type are separated by OUT). When you run the CALL command to call a function or stored procedure, the parameter list must contain an output parameter for non-overloaded functions. You can set the output parameter to a variable or any constant. For details, see Examples. If an output parameter is contained, it must be a constant.
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 |
-- Create a function func_add_sql, calculate the sum of two integers, and return the result. gaussdb=# CREATE FUNCTION func_add_sql(num1 integer, num2 integer) RETURN integer AS BEGIN RETURN num1 + num2; END; / -- Transfer by parameter value. gaussdb=# CALL func_add_sql(1, 3); -- Transfer by naming tag method. gaussdb=# CALL func_add_sql(num1 => 1,num2 => 3); gaussdb=# CALL func_add_sql(num2 := 2, num1 := 3); -- Delete the function. gaussdb=# DROP FUNCTION func_add_sql; -- Create a function with output parameters. gaussdb=# CREATE FUNCTION func_increment_sql(num1 IN integer, num2 IN integer, res OUT integer) RETURN integer AS BEGIN res := num1 + num2; END; / -- Transfer a constant as an output parameter. gaussdb=# CALL func_increment_sql(1,2,1); -- Transfer a variable as an output parameter. gaussdb=# DECLARE res int; BEGIN func_increment_sql(1, 2, res); dbe_output.print_line(res); END; / -- Delete the function. gaussdb=# DROP FUNCTION func_increment_sql; |
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