Home Database Mysql Tutorial 基于Oracle的面向对象技术入门基础简析开发者网络Oracle

基于Oracle的面向对象技术入门基础简析开发者网络Oracle

Jun 07, 2016 pm 06:04 PM

基于Oracle的面向对象技术入门基础简析开发者网络Oracle

正在看的ORACLE教程是:基于Oracle的面向对象技术入门基础简析开发者网络Oracle。

一、概述

  对象是Oracle8i以上版本中的一个新的特性,对象实际是对一组数据和操作的封装,对象的抽象就是类。在面向对象技术中,对象涉及到以下几个重要的特性:

   封装性

  通过对数据和操作的封装,将用户关心的数据和操作暴露出来作为接口,其他数据和操作则隐藏到对象内部,这样便于用户使用和维护。

   继承性

  对象具有继承性,通过这一特性可以增强程序的可扩展性,适合大型项目的开发。

   多态性

  同一操作在运行时刻有不同的对象来引用,则其执行结果是不一样的。这一特性称之为多态性。

  正是因为面向对象的诸多优势,Oracle公司在8.0版本以后就加入了对这一特性的全面支持,下来的部分重点讲述在Oracle中的面向对象程序设计。

  二、Oracle中的面向对象程序设计

  既然对象具有这么多的优点,那么在Oracle数据库如何引用它呢?Oracle中的对象定义分两步进行:

  首先定义对象类型。定义对象类型跟定义包类型完全一样,即分为对象类型头(或称为对象规范,specification)和对象类型体(body)。对象类型头包括了对象类型的属性和方法的声明,而对象类型体则包含了对象类型具体的实现。

  例如,定义一个empObj对象类型,代码如下:


  特别需要注意的是,如果对象没有成员函数部分,那么此对象类型的定义只有对象类型头部分。

  然后定义对象实例。定义了对象类型后就可以直接定义它的实例了,比如定义一个empObj实例对象,代码如下:


  经过这两步之后就可以引用对象实例的属性和方法了,引用符号为“.”,比如


  另外,在初始化无成员函数的对象时可以直接以构造函数的形式进行初始化,注意,这个时候不需显式的定义构造函数。比如,初始化上面v_empObj1对象(假设无成员函数的情况下才能进行这种初始化操作), 代码如下:


  由于Oracle数据库是关系型数据库,其存储数据是以二维表的形式进行的,而对象是对数据和操作进行封装的一个实体,其存储信息往往是多维信息,那么对象在Oracle数据库中的存储是如何进行的呢?(这里补充一点,PL/SQL程序块中声明的对象是临时对象,在超出其作用区域后系统将自动收回其分配的资源,但是如果需要保存对象的信息,就必须将其存储在数据库中)

  事实上,对象在Oracle数据库中的存储形式分为两种:

  1. 对象列。即可以将数据表中的列的数据类型定义为一个对象类型,这样对象就可以存储在数据列中了。比如定义一个表table1,其中emp列可以用来存储对象。


  2. 对象行。即可以创建一个对象表,其中每一列就表示对象中的一个属性,这样一条行记录就是一个对象了。比如定义一个emp表如下:


  这样emp表的一个记录就是一个empObj对象,插入一个表的操作就可以为:


  注意,这里表中列类型与对象的属性类型应该一一对应,另外这样存储将忽略对象的成员函数的信息。

[NextPage]

 三、对象操作与比较

  可以采用DML语句对对象进行操作,其操作的语法跟一般的数据类型完全一样,比如在table1表中返回对象为empObj(10002,'mike',3000)的记录:


  如果需要进行对象的大小比较,那么用一般的方法就很难处理,毕竟对象含有一组属性,无法进行组合比较。可以采用向对象加入map方法和order方法来解决此问题,前者是通过将对象某一属性返回代表对象的值班来比较大小,后者是通过比较两个对象之间某个属性的值班来获取对象的大小。由于两者的相似性,这里以用途更广的map成员函数为为例示范如下:


  这样定义了map函数后,对empObj对象大小的比较实质转化为对各个对象的emp_id属性大小的比较,在实际操作中,应该根据实际情况来返回关心的数据,以进行对象大小比较的操作。

  四、小结

  通过前面内容的介绍,大家应该对Oracle数据库的面向对象的特性有一个初步的认识,充分利用Oracle的这一特性,可以将面向对象的重用性,可扩展性等优点引入到数据库中,提高了数据库的运行性能。

上一页

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Apr 02, 2025 pm 07:05 PM

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

See all articles