CREATE PROCEDURE
Function
CREATE PROCEDURE creates a stored procedure.
Precautions
- If the parameters or return values of a stored procedure have precision, the precision is not checked.
- When creating a stored procedure, you are advised to explicitly specify the schemas of all operations on table objects in the stored procedure definition. Otherwise, the stored procedure may fail to be executed.
- current_schema and search_path specified by SET during stored procedure creation are invalid. search_path and current_schema before and after function execution should be the same.
- If a stored procedure has output parameters, the SELECT statement uses the default values of the output parameters when calling the procedure. When the CALL statement calls the stored procedure or a non-overloaded function, output parameters must be specified. When the CALL statement calls an overloaded PACKAGE function, it can use the default values of the output parameters. For details, see examples in CALL.
- A stored procedure with the PACKAGE attribute can use overloaded functions.
- When you create a procedure, you cannot insert aggregate functions or other functions out of the average function.
- When stored procedures without parameters are called in another stored procedure, you can omit brackets and call stored procedures using their names directly.
- When functions with output parameters are called in a stored procedure which is an assignment expression, you can omit the output parameters of the called functions.
- The stored procedure supports viewing, exporting, and importing parameter comments.
- The stored procedure supports viewing, exporting, and importing parameter comments between IS/AS and plsql_body.
- The default permission on a stored procedure is SECURITY INVOKER. If you want to change the default permission to SECURITY DEFINER, you need to set the GUC parameter behavior_compat_options to 'plsql_security_definer'. For details about the SECURITY DEFINER permission, see section "Permission Control" in Security Hardening Guide.
- Users granted with the CREATE ANY FUNCTION permission can create or replace stored procedures in the user schemas.
- out/inout must be set to a variable but not a constant.
- In a centralized environment, if you want to call a stored procedure with the same in parameters but different out parameters, you need to set the GUC parameter behavior_compat_options to 'proc_outparam_override'. After the parameter is enabled, you must add the out parameters no matter whether you use the SELECT or CALL statement to call the stored procedure. After the parameter is enabled, you cannot use perform to call a stored procedure or function.
Syntax
CREATE [ OR REPLACE ] PROCEDURE procedure_name [ ( {[ argname ] [ argmode ] argtype [ { DEFAULT | := | = } expression ]}[,...]) ] [ { IMMUTABLE | STABLE | VOLATILE } | { SHIPPABLE | NOT SHIPPABLE } | {PACKAGE} | [ NOT ] LEAKPROOF | { CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT } | {[ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER | AUTHID DEFINER | AUTHID CURRENT_USER} | COST execution_cost | SET configuration_parameter { TO value | = value | FROM CURRENT } ][ ... ] { IS | AS } plsql_body /
Parameter Description
- OR REPLACE
Replaces the original definition when two stored procedures are with the same name.
- procedure_name
Specifies the name of the stored procedure that is created (optionally with schema names).
Value range: a string. It must comply with the identifier naming convention.
- argmode
Specifies the mode of an argument.
VARIADIC specifies parameters of the array type.
Value range: IN, OUT, INOUT, and VARIADIC. The default value is IN. Only the parameters in OUT mode can follow the VARIADIC parameter.
- argname
Specifies the argument name.
Value range: a string. It must comply with the identifier naming convention.
- argtype
Specifies the type of an argument. %TYPE or %ROWTYPE can be used to indirectly reference a variable or table type. For details, see Variable Definition Statements.
Value range: a valid data type
In PROCEDURE argtype outside PACKAGE, %TYPE cannot reference the type of the PACKAGE variable.
- configuration_parameter
- value
Sets the specified configuration parameter to a specified value. If the value is DEFAULT, the default setting is used in the new session. OFF disables the setting.
Value range: a string
- DEFAULT
- OFF
- Specified default value
- from current
Uses the value of configuration_parameter of the current session.
- value
- IMMUTABLE, STABLE,...
Specifies a constraint. The function of each parameter is similar to that of CREATE FUNCTION. For details, see CREATE FUNCTION.
- plsql_body
Specifies the PL/SQL stored procedure body.
When you create a user, or perform other operations requiring password input in a stored procedure, the system catalog and CSV log record the password in plaintext. Therefore, you are advised not to perform such operations in the stored procedure.
No specific order is applied to argname and argname. The following order is advised: argname, argmode, and argtype.
Helpful Links
Suggestions
- analyse | analyze
- Do not run ANALYZE in a transaction or anonymous block.
- Do not run ANALYZE in a function or stored procedure.
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