This topic describes how object-oriented programming techniques can be exploited in Stored Procedure Language (SPL). Object-oriented programming as seen in programming languages such as Java and C++ centers on the concept of objects. An object is a representation of a real-world entity such as a person, place, or thing. The generic description or definition of a particular object, such as a person, is called an object type. Specific people such as "Joe" or "Sally" are objects of the object type person, or equivalently instances of the object type person, or simply person objects.

Precautions

The terms database objects and objects that have been used in this document up to this point are different from the object types and objects as used in this topic and other topics under "Object types and objects." The previous usage of these terms relates to the entities that can be created in a database, such as tables, views, indexes, and users. Within the context of topics that are mentioned, object types and objects refer to specific data structures supported by the SPL programming language to implement object-oriented concepts.

In Oracle, the term abstract data type (ADT) is used to describe object types in PL/SQL. The SPL implementation of object types is intended to be compatible with Oracle ADTs.

PolarDB databases compatible with Oracle do not support some features of object-oriented programming languages. This topic only describes the features that have been supported.

Concepts

An object type is a description or definition of some entity. This definition of an object type is characterized by two components:

  • Attributes: the fields that describe particular characteristics of an object instance. For example, the attributes of a person object may include the name, address, gender, date of birth, height, weight, eye color, and occupation.
  • Methods: the programs that perform some type of function or operation on or related to an object. For example, the methods of a person object may include calculating the person's age, displaying the person's attributes, and changing the values assigned to the person's attributes.

Attributes

Each object type must contain at least one attribute. The data type of an attribute can be one of the following types:

  • A base data type, such as NUMBER and VARCHAR2
  • Another object type
  • A globally defined collection type (created by the CREATE TYPE statement), such as a nested table or varray

An attribute obtains its initial value when an object instance is initially created. The initial value may be NULL. Each object instance has its own set of attribute values.

Methods

Methods are SPL procedures or functions defined within an object type. Methods can be categorized into three general types:

  • Member methods: the procedures or functions that operate within the context of an object instance. Member methods have access to and can change the attributes of the object instance on which they are operating.
  • Static methods: the procedures or functions that operate independently of a particular object instance. Static methods do not have access to and cannot change the attributes of an object instance.
  • Constructor methods: the functions used to create an instance of an object type. A default constructor method is always provided when an object type is defined.

Overloaded methods

In an object type, you cannot define two or more identically named methods of the same type (either a procedure or function) but with different signatures. Such methods are called overloaded methods.

A method's signature consists of the number of formal parameters, the data types of the formal parameters, and their order.