The CREATE TYPE BODY statement defines or implements the member methods in the type specification created by the CREATE TYPE statement.
For methods not specified in the call_spec of the type specification, you must specify the method body in the type body.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
Prerequisites
In the CREATE TYPE statement of an ADT, each member declaration must have a corresponding constructor in the CREATE TYPE or CREATE TYPE BODY statement.
To create or replace a type body in a schema, you must have the CREATE TYPE or CREATE ANY TYPE system privilege. To create a type in another user's schema, you must have the CREATE ANY TYPE system privilege. To replace a type in another user's schema, you must have the DROP ANY TYPE system privilege.
Syntax
Note
This section contains only the syntax of key nodes.
The syntax of
create_type_body_stmtis as follows:
The syntax of
plsql_type_body_sourceis as follows:
The syntax of
plsql_type_body_decl_list_semicolonis as follows:
The syntax of
plsql_type_body_decl_listis as follows:
The syntax of
proc_or_func_def_in_typeis as follows:
Semantics
| Syntax | Keywords or syntax nodes | Description |
|---|---|---|
| create_type_body_stmt | OR REPLACE | Recreates the type body (if it exists) and recompiles it. Users who were granted privileges before the type body was redefined can still access the type body without needing to be granted privileges again. You can use this clause to add member subprogram definitions to the specification defined by ALTER TYPE ... REPLACE. |
| plsql_type_body_source | pl_schema_name | The schema name that contains the type body. The default value is your schema. |
| plsql_type_body_source | TYPE | The name of the ADT. |
| subprog_decl_in_type | subprog_decl_in_type | The type of the function or stored procedure associated with the type specification. You must define a corresponding method name and optional parameter list for each stored procedure or function in the type specification. For functions, you must also specify a return type. |
| proc_or_func_def_in_type | proc_or_func_def_in_type | The definition of the stored procedure or function. |
Examples
CREATE TYPE demo_typ2 AS OBJECT (
a1 NUMBER,
MEMBER FUNCTION get_square RETURN NUMBER
);
/
CREATE OR REPLACE TYPE BODY demo_typ2 IS
MEMBER FUNCTION get_square RETURN NUMBER IS
BEGIN
RETURN a1;
END;
END;
/
