A brief analysis of the foundation of Object-oriented Technology based on Oracle Developer Network Oracle_oracle

Source: Internet
Author: User
Tags inheritance oracle database oracle developer
The Oracle tutorial that is being looked at is: An Introduction to Oracle based object-oriented Technology Brief analysis of the Developer Network Oracle.

I. Overview

An object is a new feature in the above version of Oracle8i, which is actually an encapsulation of a set of data and operations, and the abstraction of an object is a class. In object-oriented technology, objects involve several important features:

Encapsulation of

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 easy for users to use and maintain.

Inheritance of

Object has inheritance, it can enhance the scalability of the program, suitable for the development of large-scale projects.

Polymorphism

The same operation has different objects to reference at run time, and its execution results are not the same. This property is called polymorphism.

Thanks to the many advantages of object-oriented, Oracle has added full support for this feature after version 8.0, with a section focused on object-oriented programming in Oracle.

Object-oriented Programming in Oracle

Since objects have so many advantages, how do you reference them in an Oracle database? The object definitions in Oracle are performed in two steps:

First, define the object type. Defining an object type is exactly the same as defining a package type, which is divided into object type headers (or object specifications, specification) and object type bodies (body). The object type header includes the declaration of the properties and methods of the object type, while the object type body contains the specific implementation of the object type.

For example, define a Empobj object type with the following code:


Notably, if the object does not have a member function part, the definition of this object type has only the object type header part.

The object instance is then defined. Once you define an object type, you can define its instance directly, such as defining a Empobj instance object with the following code:


After these two steps, you can reference the properties and methods of the object instance, and the reference symbol is ".", such as


In addition, initializing an object without a member function can be initialized directly in the form of a constructor, noting that you do not need to explicitly define the constructor at this time. For example, to initialize the above V_empobj1 object (assuming there is no member function for this initialization operation), the code is as follows:


Since the Oracle database is a relational database, and its storage data is in the form of a two-dimensional table, and the object is an entity that encapsulates data and operations, and its storage information is often multidimensional, how is the object stored in the Oracle database? (add that the object declared in the Pl/sql block is a temporary object that will automatically retract its assigned resources after it has exceeded its scope, but must be stored in the database if you need to save the object's information)

In fact, the types of objects stored in an Oracle database are divided into two categories:

1. The object column. That is, you can define the data type of a column in a datasheet as an object type so that the object can be stored in a data column. For example, define a table table1 in which the EMP column can be used to store objects.


2. The object row. You can create an object table in which each column represents an attribute in the object, and a row record is an object. For example, define an EMP table as follows:


So a record of the EMP table is a Empobj object, and inserting a table can be:


Note that the column type in the table should correspond to one by one of the object's property type, in addition to storing information that ignores the member functions of the object.

[NextPage]

Iii. Object Manipulation and comparison

You can manipulate an object with a DML statement with the same syntax as a typical data type, such as a record in the Table1 table that returns the object as Empobj (10002, ' Mike ', 3000):


If you need to compare the size of the object, then it is difficult to deal with the general method, after all, the object contains a set of properties, can not be combined comparison. You can resolve this problem by adding a map method and an order method to the object, which compares the size of an object by returning a property on duty to represent the object, which gets the size of the object by comparing the duty of one of the two objects. As a result of the similarity between the two, this is demonstrated as an example of a more versatile map member function:


After defining the map function, the Empobj object size is transformed into the comparison of the emp_id attribute size of each object, in the actual operation, we should return the concerned data according to the actual situation in order to carry out the operation of object size comparison.

Iv. Summary

Through the introduction of the previous content, we should have a preliminary understanding of the object-oriented characteristics of Oracle database, make full use of this feature of Oracle, can introduce the advantages of object-oriented reusability and extensibility into the database, and improve the performance of 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.