The CREATE PROCEDURE statement is used to create or replace standalone stored procedures or call specifications.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
A standalone stored procedure is a procedure stored in the database that executes specific operations.
Notice
A standalone stored procedure created by using the CREATE PROCEDURE statement is different from a stored procedure declared and defined in a PL block or package.
Prerequisites
To create or replace a standalone stored procedure in the current schema, you must have the CREATE PROCEDURE system privilege. To create or replace a standalone stored procedure in another user's schema, you must have the CREATE ANY PROCEDURE system privilege.
Syntax
The syntax of create_procedure is as follows:
CREATE [ OR REPLACE ]
PROCEDURE plsql_procedure_source
The syntax of plsql_procedure_source is as follows:
[ schema. ] procedure_name
[ ( parameter_declaration [, parameter_declaration ]... ) ] [ sharing_clause ]
[ ( default_collation_option | invoker_rights_clause | accessible_by_clause)... ]
{ IS | AS } { [ declare_section ] body | call_spec } ;
Semantics
| Syntax | Keywords or syntax nodes | Description |
|---|---|---|
| create_procedure | OR REPLACE | Recreates the stored procedure (if it exists) and recompiles it. Users who were granted privileges to the stored procedure before it was redefined can still access it without needing to be granted privileges again. |
| plsql_procedure_source | schema | The schema name in which the stored procedure is located. The default value is the current user's schema. |
| plsql_procedure_source | procedure_name | The name of the stored procedure to be created. |
| plsql_procedure_source | body | The executable part required for the stored procedure, and the exception handling part of the stored procedure (optional). |
| plsql_procedure_source | declare_section | The optional declaration section of the stored procedure. Declarations are local to the stored procedure and can be referenced in the body, but they no longer exist after the stored procedure has completed execution. |
Examples
Create a stored procedure named userlogin.
CREATE TABLE loghistory
(userid VARCHAR2(20),
logdate DATE DEFAULT SYSDATE);
CREATE OR REPLACE PROCEDURE userlogin
IS
BEGIN
INSERT INTO loghistory (userid) VALUES (USER);
END;
/
