Basic Analysis of Oracle-Based Object-Oriented Technology

Source: Internet
Author: User

The ORACLE tutorial is: Oracle-based object-oriented technology basic analysis of the developer's network Oracle.

I. Overview

An object is a new feature of Oracle8i and later versions. An object is actually an encapsulation of a set of data and operations, and an object abstraction is a class. In object-oriented technology, objects involve the following important features:

Encapsulation

By encapsulating data and operations, the data and operations that users care about are exposed as interfaces, and other data and operations are hidden inside the object, which is convenient for users to use and maintain.

Inheritance

Objects are inherited. This feature enhances program scalability and is suitable for large-scale project development.

Polymorphism

If an operation has different objects for reference at runtime, the execution results are different. This feature is called polymorphism.

It is precisely because of the many advantages of object-oriented, Oracle has added comprehensive support for this feature since version 8.0. The next part focuses on the object-oriented programming in Oracle.

2. Object-Oriented Programming in Oracle

Since the object has so many advantages, how can we reference it in the Oracle database? The object definition in Oracle is divided into two steps:

First, define the object type. The definition object type is exactly the same as the definition package type. It can be divided into object type headers (or object specifications, specification) and object type bodies (bodies ). The object type header includes the object type attributes and method declarations, while the object type body contains the specific implementation of the object type.

For example, to define an empObj object type, the Code is as follows:


Note that if the object does not have a member function, the object type is defined only in the object type header.

Then define the object instance. After defining the object type, you can directly define its instance. For example, to define an empObj instance object, the Code is as follows:


After the two steps, you can reference the attributes and methods of the object instance. The reference symbol is ".", for example


In addition, you can initialize an object without a member function in the form of constructor. Note that you do not need to explicitly define the constructor at this time. For example, to initialize the above v_empObj1 object (this initialization operation can only be performed if there is no member function), the Code is as follows:


Since Oracle databases are relational databases, the stored data is in the form of a two-dimensional table, and objects are an entity that encapsulates data and operations. The stored information is usually multidimensional information, how is the storage of objects in the Oracle database performed? (Here, we add that the objects declared in the PL/SQL block are temporary objects. The system will automatically reclaim the allocated resources after the objects exceed their respective regions. However, if you need to save the object information, it must be stored in the database)

In fact, objects are stored in Oracle databases in two ways:

1. Object column. You can define the data type of columns in a data table as an object type so that objects can be stored in the data column. For example, define a table table1, where the emp column can be used to store objects.


2. Object row. You can create an object table, with each column representing an attribute in the object. In this way, a row record is an object. For example, define an emp table as follows:


In this way, a record in the emp table is an empObj object. You can insert a table as follows:


Note: The column type in the table must correspond to the attribute type of the object one by one. In addition, the information of the member functions of the object will be ignored.

[NextPage]

Iii. Object operations and Comparison

You can use DML statements to operate objects. The operation syntax is the same as that of common data types. For example, in table 1, the returned object is empObj (10002, 'Mike ', 3000) record:


If you need to compare the object size, it is difficult to use the general method. After all, the object contains a set of attributes and cannot be combined and compared. You can add the map method and order Method to the object to solve this problem. The former is to compare the size by returning a property of the object to indicate the duty of the object, the latter obtains the object size by comparing the duty of an attribute between two objects. Because of the similarity between the two, the examples of map member functions with wider application are as follows:


After the map function is defined, the comparison of the empObj object size is converted to the comparison of the emp_id attribute size of each object. In actual operations, you should return the concerned data according to the actual situation to compare the object size.

Iv. Summary

Through the introduction above, we should have a preliminary understanding of the object-oriented features of Oracle databases. Taking full advantage of this feature of Oracle, We can reuse the object-oriented features, extensibility and other advantages are introduced into the database to improve the running performance of the database.

Previous Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.