You can use the CREATE TYPE BODY statement to define or implement the member methods in a type specification created by using the CREATE TYPE statement.
For a method not specified in the type specification of call_spec, you must specify the corresponding method body in the type body.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Prerequisites
In the CREATE TYPE statement used to create an abstract data type (ADT), each member declaration must have a corresponding construct in the CREATE TYPE or CREATE TYPE BODY definition.
To create or replace a type body in your own schema, you must have the CREATE TYPE or CREATE ANY TYPE system privilege. To create a type in the schema of other users, you must have the CREATE ANY TYPE system privilege. To replace a type in the schema of other users, you must have the DROP ANY TYPE system privilege.
Syntax
Note
This topic describes the syntax of some important syntax nodes only.
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 | Keyword or syntax node | Description |
|---|---|---|
| create_type_body_stmt | OR REPLACE | Re-creates this type body (if any) and recompiles it. Before the type body is redefined, users granted the access privilege can still access this type body without the need to obtain the access privilege again. You can use this clause to add the definition of a member subprogram to the specification defined by using ALTER TYPE ... REPLACE. |
| plsql_type_body_source | pl_schema_name | The name of the schema that contains the type body. The default value is your own schema. |
| plsql_type_body_source | TYPE | The name of the ADT. |
| subprog_decl_in_type | subprog_decl_in_type | The type of the feature or stored procedure that is associated with the type specification. You must define in the type specification a corresponding method name and a parameter list for each stored procedure or function. You must also specify a return type for functions. |
| proc_or_func_def_in_type | proc_or_func_def_in_type | The definition of a 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;
/