Since Oracle9i, Oracle is no longer simply a relational database management system. It adds a series of object-oriented features based on the relational database model. Oracle9i is known as object-oriented database. Oracle's object system complies with the Basic Features of Object-oriented Thinking. Many concepts are similar to those in C ++ and JAVA. It has the characteristics of inheritance, heavy load, and polymorphism, but has its own characteristics.
Why should we introduce the object model? Parts can be reused and simplify complex applications.
The following describes Oracle Object-Oriented Programming in detail.
1. Object-oriented TYPE
In PL/SQL, object-oriented programming is based on object types.
1.1 object-oriented type definition syntax
Object Type definitions include Object Type headers (or specification) and object type bodies (bodies ). Object Type headers include object type attributes, functions, and process declarations. Object Type bodies are specific implementations of object types, that is, functions and procedures. Therefore, if the object type contains only attributes, but does not include functions and procedures, you only need to declare the object type header.
Object Type Header declaration Syntax:
Create or replace type type_name as object (
-- Attribute Declaration
Propertyname1 TYPE1,
Propertyname2 TYPE2,
...
Properynamen TYPEn,
-- Function declaration
Member function funcname1 (param1 TYPE1,...) return TYPE11,
Static function funcname2 (param1 TYPE2,...) return TYPE22,
...
-- Process statement
Member procedure procname1 (param1 TYPE1 ,...),
Static procedure procname2 (param1 TYPE2 ,...),
...
);
Object Type Definition Syntax:
Create or replace type body type_name -- No 'as Object'
AS -- NO 'begin'
Member function funcname1 return TYPE11
IS
// Variable definition
BEGIN
// Process
Return var1;
END funcname1;
Static function funcname2 return TYPE22
IS
// Variable definition
BEGIN
// Process
Return var2;
END funcname2;
...
Member procedure procname1 (param1 TYPE1 ,...)
IS
// Variable definition
BEGIN
// Process
END procname1;
Static procedure procname2 (param1 TYPE2 ,...)
IS
// Variable definition
BEGIN
// Process
END procname2;
...
END;