27 Object Datatypes and Object Views
001 |
Object types and other user-defined datatypes let you define datatypes
that model the structure and behavior of the data in their applications.
An object view is a virtual object table. |
开发者可以使用对象类型[object type]及用户定义数据类型[user-defined
datatype]实现应用程序中所需的数据结构及数据的行为。对象视图[object view]是一种虚拟对象表[virtual object
table]。 |
002 | This chapter contains the following topics: | 本章包含以下主题: |
003 |
Introduction to Object Datatypes |
27.1 对象数据类型简介 |
004 |
Oracle object technology is a layer of abstraction built on Oracle's
relational technology. New object types can be created from any built-in
database types or any previously created object types, object
references, and collection types.
Metadata for user-defined types is
stored in a schema available to SQL, PL/SQL, Java, and other published
interfaces. Object datatypes make it easier to work with complex data,
such as images, audio, and video. |
Oracle 对象技术是构建于 Oracle 关系数据库技术之上的一个抽象层。对象类型[object
type]可以基于数据库内置的数据类型[built-in database type],或已创建的对象类型,对象引用[object
reference],及集合类型[collection type]。用户定义类型[user-defined
type]的元数据所在的方案[schema]可供 SQL,PL/SQL,Java,及其他公开的接口[published
interface]使用。通过对象类型更易于处理复杂数据,例如图像,音频,及视频。 |
005 |
An object type differs from native SQL datatypes in that it is
user-defined, and it specifies both the underlying persistent data
(attributes) and the related behaviors (methods). Object types are
abstractions of the real-world entities, for example, purchase orders.
Object types store structured business data in its natural form and
allow applications to retrieve it that way. |
对象类型与内置 SQL 数据类型[native SQL
datatype]的区别在于,前者为用户自定义的,且其中既定义了持久数据[persistent
data(属性[attribute]),也定义了相关的行为[behavior](方法[method])。对象类型是真实世界中实体的抽象,例如,订单可以被抽象为对象。通过对象类型,开发者能够以自然形态存储结构化的业务数据,应用程序也能够以自然形态使用这些数据。 |
006 |
Object types and related object-oriented features, such as
variable-length arrays and nested tables, provide higher-level ways to
organize and access data in the database. Underneath the object layer,
data is still stored in columns and tables, but you can work with the
data in terms of the real-world entities--customers and purchase orders,
for example--that make the data meaningful. Instead of thinking in terms
of columns and tables when you query the database, you can simply select
a customer. |
对象类型及其他 Oracle 的面向对象特性(例如变长数组[variable-length array]及嵌套表[nested
table])为开发者提供了一种更高层的组织及访问数据的方式。在对象层之下,数据依旧以表和列的形式存储,但是用户可以像处理真实世界实体(例如客户及订单)一样使用数据,这种方式
令数据的含义更清晰。用户在查询数据库时面对的不再是表及列,而是选择一个对象,例如一个客户。 |
007 |
Internally, statements about objects are still basically statements
about relational tables and columns, and you can continue to work with
relational datatypes and store data in relational tables. But you have
the option to take advantage of object-oriented features too. You can
use object-oriented features while continuing to work with most of your
relational data, or you can go over to an object-oriented approach
entirely. For instance, you can define some object datatypes and store
the objects in columns in relational tables. You can also create object
views of existing relational data to represent and access this data
according to an object model. Or you can store object data in object
tables, where each row is an object. |
在 Oracle
内部,操作对象的语句依旧是访问关系型数据表的基本语句,用户也可以继续操作关系型数据类型或将数据存储在关系型数据表中。但是,用户可以同时发挥面向对象特性的优势。例如,用户可以采用关系型的方式处理大多数数据,同时采用面向对象方式处理部分数据;用户也可以全面地采用面向对象方式。具体来说,用户可以定义对象类型,并将对象数据存储在关系型数据表中;也可以在已有
的关系型数据上创建对象视图,并采用对象模型访问或展现数据;或者将对象数据存储于对象表中(其中的每个数据行都为一个对象)。 |
008 |
See Also: |
另见: |
009 |
Complex Data Models |
27.1.1 复杂数据模型 |
010 |
The Oracle database server lets you define complex business models in
SQL and make them part of your database schema. Applications that manage
and share your data need only contain the application logic, not the
data logic. |
用户可以使用 SQL 语句在 Oracle
数据库服务器中的定义复杂业务模型,并将模型保存在数据库方案中。用于管理及共享数据的应用程序中只需包含应用逻辑,而无需包含数据逻辑。 |
011 |
For example, your firm might use purchase orders to organize its
purchasing, accounts payable, shipping, and accounts receivable
functions. |
例如,用户通过订单[purchase order]来管理采购[purchasing],应付帐款[accounts
payable],运送[shipping],及应收帐款[accounts receivable]等业务。 |
012 |
A purchase order contains an associated supplier or customer and an
indefinite number of line items. In addition, applications often need
dynamically computed status information about purchase orders. You may
need the current value of the shipped or unshipped line items. |
订单中包含与业务相关的客户,供应商,及销售产品的数量。在应用程序中需要动态地对订单进行统计。因此需要获取已发送及未发送产品的数量。 |
013 |
An object type is a schema object that serves as a template for
all purchase order data in your applications. An object type specifies
the elements, called attributes, that make up a structured data
unit, such as a purchase order. Some attributes, such as the list of
line items, can be other structured data units. The object type also
specifies the operations, called methods, you can perform on the
data unit, such as determining the total value of a purchase order. |
代表订单的对象类型[object type]是一个方案对象,在应用程序中可以作为所有订单数据的模版。对象类型中可以包含多个元素[element],我们称之为属性[attribute],这些属性共同构成了结构化的数据单元[structured
data unit],例如订单。属性可以是另一种结构化数据单元(对象类型),例如销售产品列表。对象类型中还可以包含多种操作,我们称之为方法[method],用户可以对一个数据单元执行某种方法,例如计算订单的总量。 |
014 |
You can create purchase orders that match the template and store them in
table columns, just as you would numbers or dates. |
用户可以依据模版创建订单,并将数据存储于表的数据列中,就如同存储数字或日期类型数据一样。 |
015 |
You can also store purchase orders in object tables, where each
row of the table corresponds to a single purchase order and the table
columns are the purchase order's attributes. |
用户也可以将订单数据存储在对象表[object
table]中,对象表中每行数据代表一个订单,对象表中的每列对应订单的一个属性。 |
016 |
Because the logic of the purchase order's structure and behavior is in
your schema, your applications do not need to know the details and do
not have to keep up with most changes. |
由于订单数据的结构及行为存储于数据库方案中,因此应用程序不必了解订单数据的细节,当订单的数据逻辑发生变化时应用程序也不必修改。 |
017 |
Oracle uses schema information about object types to achieve substantial
transmission efficiencies. A client-side application can request a
purchase order from the server and receive all the relevant data in a
single transmission. The application can then, without knowing storage
locations or implementation details, navigate among related data items
without further transmissions from the server. |
Oracle
在方案中存储对象类型的信息,从而提高了数据传输的效率。位于客户端的应用程序可以向数据库服务器请求订单类型,并在一次传输中获得全部有关的数据。此后应用程序可以使用各个数据项,而不必再次访问服务器,也不必了解数据的存储位置及实现细节。 |
018 |
Multimedia Datatypes |
27.1.2 多媒体数据类型 |
019 |
Many efficiencies of database systems arise from their optimized
management of basic datatypes like numbers, dates, and characters.
Facilities exist for comparing values, determining their distributions,
building efficient indexes, and performing other optimizations. |
多数数据库系统均能够通过优化对数字,日期,及字符等基本数据类型的管理来提升系统性能。数据库通常提供了数据值比较,数据分布,构建高效索引,及其他优化措施。 |
020 |
Text, video, sound, graphics, and spatial data are examples of important
business entities that do not fit neatly into those basic types. Oracle
Enterprise Edition supports modeling and implementation of these complex
datatypes. |
文本,视频,音频,图像,及地理空间数据是非常重要的业务信息,但并不属于基本的数据类型。Oracle
数据库企业版提供了这些复杂数据类型,并可利用这些复杂数据类型构建数据模型。 |
021 |
Overview of Object Datatype Categories |
27.2 对象数据类型分类概述 |
022 |
There are two categories of object datatypes:
|
对象数据类型可以分为两类:
|
023 |
Object datatypes use the built-in datatypes and other user-defined
datatypes as the building blocks for datatypes that model the structure
and behavior of data in applications. |
对象数据类型可以使用 Oracle 内置数据类型及其他用户定义数据类型作为构建元素,定义应用程序所需数据的结构及行为。 |
024 |
Object types are schema objects. Their use is subject to the same kinds
of administrative control as other schema objects. |
用户定义的对象类型将被存储为方案对象。对象类型遵从与其他方案对象相同的管理规则。 |
025 |
|
|
026 |
Object Types |
27.2.1 对象类型 |
027 |
Object types are abstractions of the real-world entities—for example,
purchase orders—that application programs deal with. An object type is a
schema object with three kinds of components:
|
对象类型是应用程序处理的真实世界实体的抽象,例如订单。对象类型将被存储为方案对象,由以下三部分组成:
|
028 |
An object type is a template. A structured data unit that matches the
template is called an object. |
对象类型如同一个模版。基于此模版所定义的结构化数据单元被称为对象[object]。 |
029 |
|
|
030 |
Types of Methods |
27.2.1.1 方法的类型 |
031 |
Methods of an object type model the behavior of objects. The methods of
an object type broadly fall into these categories:
|
对象类型的方法用于定义对象的行为。对象类型的方法可以被分为以下几类:
|
032 |
Oracle supports the choice of implementing type methods in PL/SQL, Java,
and C. |
Oracle 支持以 PL/SQL,Java,及 C 实现对象类型的方法。 |
033 |
Every object type also has one implicitly defined method that is not
tied to specific objects, the object type's constructor method. |
每个对象类型都具有一个隐式定义的方法,即对象类型的构造方法,此方法不与具体对象相关联。 |
034 |
Object Type Constructor Methods |
27.2.1.1.1 对象类型的构造方法 |
035 |
Every object type has a system-defined constructor method; that
is, a method that makes a new object according to the object type's
specification. The name of the constructor method is the name of the
object type. Its parameters have the names and types of the object
type's attributes. The constructor method is a function. It returns the
new object as its value. You can also define your own constructor
functions to use in place of the constructor functions that the system
implicitly defines for every object type. |
每个对象类型都具有一个系统定义的构造方法[constructor method]。构造方法的作用是依据对象类型的规范[specification]创建对象实例。构造方法的名称与相应的对象类型的名称相同。构造方法参数的名称及数据类型与对象类型的属性相同。构造方法是一个函数,构造方法的返回值为其创建的新对象实例。用户也可以为对象类型定义构造函数,以替代系统隐式定义的构造函数。 |
036 |
See Also: |
另见: |
037 |
Comparison Methods |
27.2.1.1.2 比较方法 |
038 |
Methods play a role in comparing objects. Oracle has facilities for
comparing two data items of a given built-in type (for example, two
numbers), and determining whether one is greater than, equal to, or less
than the other. Oracle cannot, however, compare two items of an
arbitrary user-defined type without further guidance from the definer.
Oracle provides two ways to define an order relationship among objects
of a given object type: map methods and order methods. |
进行对象比较时需要使用对象提供的方法。Oracle 提供了内置数据类型(例如两个数字)的比较方法,能够进行大于,小于,及等于的比较。但 Oracle
无法比较用户定义的数据类型,除非定义者提供了相应的比较方法。Oracle 提供了两种定义对象间顺序关系的方法:映射方法[map
method]及排序方法[order method]。 |
039 |
Map methods use Oracle's ability to compare built-in types.
Suppose that you have defined an object type called
rectangle, with attributes
height and width.
You can define a map method area that returns a number, namely the
product of the rectangle's height and
width attributes. Oracle can then compare
two rectangles by comparing their areas. |
映射方法利用了 Oracle 比较内置数据类型的能力。假设用户定义了名为
rectangle[长方形]的对象类型,此类型包含
height[高]和 width[宽]两个属性。用户可以定义一个映射方法
area[面积]返回一个数值,表示
rectangle 类型
height 属性与 width
属性的积。则 Oracle 可以通过比较面积来比较两个长方形对象。 |
040 |
Order methods are more general. An order method uses its own
internal logic to compare two objects of a given object type. It returns
a value that encodes the order relationship. For example, it could
return -1 if the first is smaller, 0 if they are equal, and 1 if the
first is larger. |
排序方法更为常见。排序方法使用其内部逻辑比较对象类型的两个实例。其返回值能够表明顺序关系。例如,如果第一个值较小则返回
-1,如果两值相等则返回 0,如果第一个值较大则返回 1。 |
041 |
Suppose that you have defined an object type called
address, with attributes
street, city,
state, and zip.
Greater than and less than may have no meaning for
addresses in your application, but you may need to perform complex
computations to determine when two addresses are equal. |
假设用户定义了名为
address[地址]的对象类型,并在此类型中定义了
street[街道],city[城市],state[州],及 zip[邮政编码]四个属性。在应用程序中,地址间的大于及小于关系是没有意义的,但用户可能需要执行复杂的运算来决定两个地址是否相同。 |
042 |
In defining an object type, you can specify either a map method or an
order method for it, but not both. If an object type has no comparison
method, Oracle cannot determine a greater than or less than relationship
between two objects of that type. It can, however, attempt to determine
whether two objects of the type are equal. |
在定义对象类型时,用户可以定义映射方法或排序方法,但不能同时定义两种方法。如果一个对象类型中没有定义比较方法,Oracle
将无法确定此类型的两个对象间的顺序关系(大于或小于)。但 Oracle 能够尝试确定此类型的两个对象是否相等。 |
043 |
Oracle compares two objects of a type that lacks a comparison method by
comparing corresponding attributes:
|
当对象类型中没有定义比较方法时,Oracle 将比较两个对象的属性:
|
044 |
See Also: |
另见: |
045 |
Object Tables |
27.2.1.2 对象表 |
046 |
An object table is a special kind of table that holds objects and
provides a relational view of the attributes of those objects. |
对象表[object table]是用于存储对象的特殊数据表,其中以关系型的形式存储对象的各个属性。 |
047 |
Oracle lets you view this table in two ways:
|
Oracle 能够以两种方式存储对象表:以
external_person
对象类型为例:
|
048 |
Row Objects and Column Objects |
27.2.1.2.1 行对象及列对象 |
049 |
Objects that appear in object tables are called row objects.
Objects that appear in table columns or as attributes of other objects
are called column objects. |
存储于对象表中的对象被称为行对象[row object]。存储于表列中,或作为其他对象属性的对象被称为列对象[column
object]。 |
050 |
Object Identifiers |
27.2.1.3 对象标识符 |
051 |
Every row object in an object table has an associated logical object
identifier. Oracle assigns a unique system-generated identifier of
length 16 bytes as the object identifier for each row object by default. |
对象表[object table]中的每个行对象[row object]都有一个与之对应的逻辑对象标识符[logical object
identifier]。Oracle 默认为每个行对象分配一个系统生成的唯一的对象标识符,长度为 16 字节。 |
052 |
The object identifier column of an object table is a hidden column.
Although the object identifier value in itself is not very meaningful to
an object-relational application, Oracle uses this value to construct
object references to the row objects. Applications need to be concerned
with only object references that are used for fetching and navigating
objects. |
对象表内的对象标识符列[object identifier
column]是一个隐藏列。对象标识符值本身对于对象-关系型应用程序没有意义,Oracle 使用此值构建行对象的对象引用[object
reference]。而应用程序可以通过对象引用遍历及获取对象。 |
053 |
The purpose of the object identifier for a row object is to uniquely
identify it in an object table. To do this Oracle implicitly creates and
maintains an index on the object identifier column of an object table.
The system-generated unique identifier has many advantages, among which
are the unambiguous identification of objects in a distributed and
replicated environment. |
对象标识符可用于唯一地确定对象表中的行对象。Oracle
能够隐式地创建并维护对象表对象标识符列上的索引。使用系统生成的唯一标识符有很多好处,例如在分布式系统[distributed
environment]或复制系统[replicated environment]中也能够通过对象标识符唯一地确定一个对象。 |
054 |
Primary-Key Based Object Identifiers |
27.2.1.3.1 基于主键的对象标识符 |
055 |
For applications that do not require the functionality provided by
globally unique system-generated identifiers, storing 16 extra bytes
with each object and maintaining an index on it may not be efficient.
Oracle allows the option of specifying the primary key value of a row
object as the object identifier for the row object. |
对于不需要由系统生成全局唯一标识符的应用程序,使用长度 16 字节的标识符并维护相关索引将降低系统的效率。Oracle
允许用户使用行对象的主键值作为行对象的标识符。 |
056 |
Primary-key based identifiers also have the advantage of enabling a more
efficient and easier loading of the object table. By contrast,
system-generated object identifiers need to be remapped using some
user-specified keys, especially when references to them are also stored
persistently. |
采用基于主键的标识符有利于更高效且更简便的加载对象表数据。与之相反,采用系统生成的对象标识符时,需要将用户定义的键映射为标识符,尤其是当对象引用也需要被持久存储时。 |
057 |
Object Views Description |
27.2.1.4 对象视图描述 |
058 |
An object view is a virtual object table. Its rows are row objects.
Oracle materializes object identifiers, which it does not store
persistently, from primary keys in the underlying table or view. |
对象视图[object view]是一个虚拟的对象表[object table]。对象视图中的行为行对象。Oracle
能够将对象视图的底层表或视图的主键物化[materializes]为对象标识符[object
identifier](对象视图中并不持久存储这些主键数据)。 |
059 |
See Also: |
另见: |
060 |
REFs |
27.2.1.5 REF |
061 |
In the relational model, foreign keys express many-to-one relationships.
Oracle object types provide a more efficient means of expressing
many-to-one relationships when the "one" side of the relationship is a
row object. |
在关系型模型[relational model]中,外键[foreign key]表示的是多对一关系[many-to-one
relationship]。Oracle 对象类型[object
type]提供了一种更为高效的方式来表示多对一关系,在此多对一关系中“一”的一方为一个行对象。 |
062 |
Oracle provides a built-in datatype called REF
to encapsulate references to row objects of a specified object type.
From a modeling perspective, REFs provide
the ability to capture an association between two row objects. Oracle
uses object identifiers to construct such REFs. |
Oracle 提供了一种称为 REF
的内置数据类型,用于封装对特定对象类型的行对象[row object]的引用[reference]。从数据建模的角度看,REF
数据能够表现两个行对象间的关系。Oracle 使用对象标识符来构建 REF
数据。 |
063 |
You can use a REF to examine or update the
object it refers to. You can also use a REF
to obtain a copy of the object it refers to. The only changes you can
make to a REF are to replace its contents
with a reference to a different object of the same object type or to
assign it a null value. |
用户可以使用 REF
来查询或更新其引用的对象。用户还可以通过 REF
来获得其引用对象的副本。用户只能以两种方式修改 REF
数据,其一是将 REF
数据更新为相同对象类型的其他对象的引用,其二是赋予 REF
空值。 |
064 |
Scoped REFs |
27.2.1.5.1 限定 REF |
065 |
In declaring a column type, collection element, or object type attribute
to be a REF, you can constrain it to
contain only references to a specified object table. Such a
REF is called a scoped
REF. Scoped REFs
require less storage space and allow more efficient access than unscoped
REFs. |
用户在定义数据类型为 REF 的数据列,集合元素[collection
element],或对象类型属性时,可以限定 REF 只能包含对特定对象表的引用。这种 REF
被称为限定 REF[scoped
REF]。与非限定的 REF
相比,限定 REF 所占用的存储空间更少,且存取效率更高。 |
066 |
Dangling REFs |
27.2.1.5.2 失效 REF |
067 |
It is possible for the object identified by a REF
to become unavailable through either deletion of the object or a change
in privileges. Such a REF is called
dangling. Oracle SQL provides a predicate (called
IS DANGLING) to allow testing
REFs for this condition. |
被 REF
所引用的对象可能会被删除或发生权限变化,从而导致 REF
不可用。此时 REF
被称为失效的[dangling]。Oracle SQL 中提供了谓词(IS DANGLING)来检验 REF
是否处于此种状态。 |
068 |
Dereference REFs |
27.2.1.5.3 非引用化 REF |
069 |
Accessing the object referred to by a REF
is called dereferencing the REF.
Oracle provides the DEREF operator to do
this. Dereferencing a dangling REF results
in a null object. Oracle provides implicit dereferencing of
REFs. |
访问 REF 所引用的对象被称为非引用化[dereferencing]
REF。Oracle 提供了 DEREF
操作符实现此种操作。当非引用化一个失效 REF[dangling REF]时将得到一个空对象。Oracle
支持对 REF 进行隐式的非引用化。 |
070 |
Obtain REFs |
27.2.1.5.4 获取 REF |
071 |
You can obtain a REF to a row object by
selecting the object from its object table and applying the
REF operator. |
用户在对象表[object table]中查询对象时使用
REF 操作符就可以获取行对象[row object]的
REF 数据。 |
072 |
See Also: |
另见: |
073 |
Collection Types |
27.2.2 集合类型 |
074 |
Each collection type describes a data unit made up of an indefinite
number of elements, all of the same datatype. The collection types are
array types and table types. |
集合类型[collection type]是由无限个相同数据类型的元素构成的数据单元。集合类型包括数组类型[array
type]及表类型[table type]。 |
075 |
Array types and table types are schema objects. The corresponding
data units are called VARRAYs and nested tables. When
there is no danger of confusion, we often refer to the collection
types as VARRAYs and nested tables. |
数组类型及表类型均为方案对象。与这两种集合类型相对应的数据单元分别被称为 VARRAY 及嵌套表[nested
table]。在不会发生混淆时,我们可以直接称集合类型为 VARRAY
或嵌套表。 |
076 |
Collection types have constructor methods. The name of the constructor
method is the name of the type, and its argument is a comma separated
list of the new collection's elements. The constructor method is a
function. It returns the new collection as its value. |
集合类型包含一个构造方法[constructor
method]。构造方法的名称即为集合类型的名称,其参数为以逗号分割的集合类型元素列表。构造方法是一个函数,其返回值为新创建的集合类型实例。 |
077 |
An expression consisting of the type name followed by empty parentheses
represents a call to the constructor method to create an
empty
collection of that type. An empty collection is different from a null
collection. |
在类型名后加空括号的表达式可以调用构造方法创建一个此类型的空值集合[empty
collection]。注意空值集合与空集合[null collection]是有区别的。 |
078 |
VARRAYs |
27.2.2.1 VARRAY |
079 |
An array is an ordered set of data elements. All elements
of a given array are of the same datatype. Each element has an index,
which is a number corresponding to the element's position in the array. |
数组[array]是一个有序的相同类型数据元素[element]的集合。一个数组内所有数据元素的数据类型均是相同的。每个元素均有一个索引[index],索引
是一个数字,代表元素在数组中的位置。 |
080 |
The number of elements in an array is the size of the array.
Oracle allows arrays to be of variable size, which is why they are
called VARRAYs. You must specify a maximum
size when you declare the array type. |
数组内元素的数量被称为此数组的容量[size]。Oracle 支持变化容量的数组,此种数组被称为 VARRAY。用户在声明数组类型时必须设定数组的最大容量。 |
081 |
Creating an array type does not allocate space. It defines a datatype,
which you can use as:
|
在创建数组类型时不会占用系统的存储空间。创建数组类型意味着定义了一种数据类型,用户可以使用这种数据类型:
|
082 |
A VARRAY is normally stored in line; that
is, in the same tablespace as the other data in its row. If it is
sufficiently large, however, Oracle stores it as a
BLOB. |
VARRAY 数据通常是内联存储的[stored in
line],即与其所在数据行的其他数据存储在同一表空间内。但是如果 VARRAY
数据很大,Oracle 也可以将其存储在
BLOB 中。 |
083 |
See Also: |
另见: |
084 |
Nested Tables |
27.2.2.2 嵌套表 |
085 |
A nested table is an unordered set of data elements, all
of the same datatype. It has a single column, and the type of that
column is a built-in type or an object type. If an object type, the
table can also be viewed as a multicolumn table, with a column for each
attribute of the object type. If compatibility is set to Oracle9i or
higher, nested tables can contain other nested tables. |
嵌套表[nested table]是一个无序的相同类型数据元素[element]的集合。嵌套表只有一列,此列的类型可以为
Oracle 内置数据类型或对象类型[object
type]。当嵌套表列的类型为对象类型时,嵌套表也可以被看做一个多列的表,对象类型的每个属性可以被看做一列。如果数据库的兼容性被设置为
Oracle9i 或更高,嵌套表中可以包含其他嵌套表。 |
086 |
A table type definition does not allocate space. It defines a type,
which you can use as:
|
在创建嵌套表类型时不会占用系统的存储空间。创建嵌套表类型意味着定义了一种数据类型,用户可以使用这种数据类型:
|
087 |
When a table type appears as the type of a column in a relational table
or as an attribute of the underlying object type of an object table,
Oracle stores all of the nested table data in a single table, which it
associates with the enclosing relational or object table. |
如果将关系型数据表的列或对象表底层对象类型的属性定义为嵌套表类型,Oracle
将把嵌套表数据存储在一个单独的数据表中,此表与嵌套表数据所在的关系型表或对象表相关。 |
088 |
A convenient way to access the elements of a nested table individually
is to use a nested cursor. |
用户可以使用嵌套游标[nested cursor]逐个地访问嵌套表的每个元素。 |
089 |
|
|
090 |
Overview of Type Inheritance |
27.3 类型继承概述 |
091 |
An object type can be created as a subtype of an existing object type. A
single inheritance model is supported: the subtype can be derived from
only one parent type. A type inherits all the attributes and methods of
its direct supertype. It can add new attributes and methods, and it can
override any of the inherited methods. |
用户可以基于已有的对象类型[object type]创建其子类型[subtype]。Oracle
只支持单一继承模型:即子类型只能继承自一个父类型。子类型将继承其直接超类型(direct
supertype)的所有属性和方法。用户还可以在子类型中添加新的属性和方法,或者覆盖[override]继承自父类型的方法。 |
092 |
Figure 27-1 illustrates two
subtypes, Student_t and
Employee_t, created under
Person_t. |
图 27-1 显示了
Person_t 类型下的两个子类型,Student_t
及
Employee_t 类型。 |
093 |
Figure 27-1 A Type Hierarchy |
图 27-1 类型层次结构 |
094 | ||
095 |
Figure 27-1 is described in the text preceding the image. |
图 27-1 所示内容将在下文中描述。 |
096 |
Furthermore, a subtype can itself be refined by defining another subtype
under it, thus building up type hierarchies. In the preceding diagram,
PartTimeStudent_t is derived from subtype
Student_t. |
此外,一个子类型还可以有自己的子类型,这就形成了类型层次结构。在上面的图示中,PartTimeStudent_t
类型继承自
Person_t 类型的子类型
Student_t。 |
097 |
FINAL and NOT FINAL Types |
27.3.1 FINAL 与 NOT FINAL 类型 |
098 |
A type declaration must have the NOT FINAL
keyword, if you want it to have subtypes. The default is that the type
is FINAL; that is, no subtypes can be
created for the type. This allows for backward compatibility. |
如果用户希望一个类型可以被继承,在声明此类型时应使用 NOT FINAL
关键字。在默认情况下类型的继承属性是 FINAL,即类型无法被继承。这个规定是为了提供向后兼容性。 |
099 |
NOT INSTANTIABLE Types and Methods |
27.3.2 NOT INSTANTIABLE 类型及方法 |
100 |
A type can be declared to be NOT INSTANTIABLE.
This implies that there is no constructor (default or user-defined) for
the type. Thus, it is not possible to construct instances of this type.
Typically, you would define instantiable subtypes for such a type as
follows: |
一个类型可以被声明为 NOT INSTANTIABLE。这表示此类型没有(默认或用户定义的)构造器[constructor]。因此这种类型无法构造新实例。通常情况下,用户可以按以下示例
的做法使用不可实例化[instantiable]的类型: |
101 |
CREATE TYPE Address_t AS OBJECT(...) NOT INSTANTIABLE NOT FINAL; |
CREATE TYPE Address_t AS OBJECT(...) NOT INSTANTIABLE NOT FINAL; |
102 |
A method of a type can be declared to be NOT
INSTANTIABLE. Declaring a method as NOT
INSTANTIABLE means that the type is not providing an
implementation for that method. Furthermore, a type that contains any
non-instantiable methods must necessarily be declared
NOT INSTANTIABLE. |
一个类型的方法也可以被声明为 NOT INSTANTIABLE。这表明类型定义中并没有提供此方法的实现。包含 NOT INSTANTIABLE
方法的类型必须也声明为 NOT INSTANTIABLE。 |
103 |
A subtype of a NOT INSTANTIABLE type can
override any of the non-instantiable methods of the supertype and
provide concrete implementations. If there are any non-instantiable
methods remaining, the subtype must also necessarily be declared
NOT INSTANTIABLE. |
NOT INSTANTIABLE
类型的子类型可以覆盖其超类型中的不可实例化的方法,并提供方法的具体实现。如果子类型中仍有不可实例化的方法,则子类型也必须声明为
NOT INSTANTIABLE。 |
104 |
A non-instantiable subtype can be defined under an instantiable
supertype. Declaring a non-instantiable type to be
FINAL is not allowed. |
不可实例化的类型可以继承可实例化的超类型。Oracle 不允许将不可实例化的类型声明为
FINAL。 |
105 |
See Also: |
另见: |
106 |
Overview of User-Defined Aggregate Functions |
27.4 用户定义聚合函数概述 |
107 |
Oracle supports a fixed set of aggregate functions, such as
MAX, MIN, and
SUM. These is also a mechanism to implement
new aggregate functions with user-defined aggregation logic. |
Oracle 内置了一套聚合函数,例如 MAX,MIN,及
SUM 等。用户也可以自定义聚合逻辑从而实现新的聚合函数。 |
108 |
Why Have User-Defined Aggregate Functions? |
27.4.1 为何使用用户定义聚合函数 |
109 |
User-defined aggregate functions (UDAGs) refer to aggregate functions
with user-specified aggregation semantics. Users can create a new
aggregate function and provide the aggregation logic through a set of
routines. After it is created, the user-defined aggregate function can
be used in SQL DML statements in a manner similar to built-in
aggregates. The Oracle database server evaluates the UDAG by invoking
the user-provided aggregation routines appropriately. |
用户定义聚合函数[user-defined aggregate function,UDAG]指用户使用自定义的聚合语义实现的聚合函数。用户可以创建新聚合函数,并通过一系列过程实现聚合逻辑。当创建了用户定义聚合函数后,就可以在
SQL DML 中使用,使用方式与其他 Oracle 内置聚合函数类似。Oracle 数据库服务器能够调用用户定义的过程处理 UDAG。 |
110 |
Databases are increasingly being used to store complex data such as
image, spatial, audio, video, and so on. The complex data is typically
stored in the database using object types, opaque types, or LOBs.
User-defined aggregates are primarily useful in specifying aggregation
over such new domains of data. |
当前,数据库中会存储越来越多的复杂数据,例如图像,空间数据,音频,视频等。复杂数据在数据库中通常以对象类型,不透明类型[opaque
type],或 LOB 类型存储。用户定义聚合函数主要用于对新出现的复杂数据进行聚合操作。 |
111 |
Furthermore, UDAGs can be used to create new aggregate functions over
traditional scalar datatypes for financial or scientific applications.
Because it is not possible to provide native support for all forms of
aggregates, it is desirable to provide application developers with a
flexible mechanism to add new aggregate functions. |
此外,用户也可以创建新聚合函数,以便在财务或科学计算应用程序中处理传统的数量数据类型[scalar datatype]。在 Oracle
中不可能预置所有用户需要的聚合函数,因此应用程序开发者可以通过 UDAG 这种灵活的机制定义新聚合函数。 |
112 |
|
|
113 |
Overview of Datatype Evolution |
27.5 对象数据类型演化概述 |
114 |
An object datatype can be referenced by any of the following schema
objects:
|
一个对象数据类型[object datatype]可以被以下方案对象[schema object]引用:
|
115 |
When any of these objects references a type, either directly or
indirectly through another type or subtype, it becomes a dependent
object on that type. Whenever a type is modified, all dependent program
units, views, operators and indextypes are marked invalid. The next time
each of these invalid objects is referenced, it is revalidated, using
the new type definition. If it is recompiled successfully, then it
becomes valid and can be used again. |
当上述方案对象引用了一个对象类型时(直接引用或间接地引用其他对象类型或子类型),这个方案对象将成为其引用对象类型的依赖对象。如果引用对象类型发生修改,所有依赖此对象类型的程序单元,视图,操作符,及索引类型都将被标记为无效[invalid]。当无效方案对象再次被使用时,将根据对象类型的新定义重新验证[revalidate]。如果方案对象能够被重新编译,将会恢复有效[valid]状态,并可以继续使用。 |
116 |
When a type has either type or table dependents, altering a type
definition becomes more complicated because existing persistent data
relies on the current type definition. |
如果一个对象类型被数据表或其他对象类型所依赖,那么修改此对象类型的定义将导致更为复杂的问题,因为已存在的持久化数据依赖于此对象类型的定义。 |
117 |
You can change an object type and propagate the type change to its
dependent types and tables. ALTER TYPE lets
you add or drop methods and attributes from existing types and
optionally propagate the changes to dependent types, tables, and even
the table data. You can also modify certain attributes of a type. |
用户可以在修改对象类型定义后将类型的修改传播[propagate]到依赖于此对象类型的数据表或类型中。用户可以使用 ALTER TYPE
语句添加或移除对象类型中的方法和属性,还可以使用此语句将定义修改传播到依赖于此对象类型的数据表或类型中,甚至传播到依赖于此对象类型的表数据中。ALTER TYPE
语句也可用于修改对象类型的属性。 |
118 |
|
|
119 |
Introduction to Object Views |
27.6 对象视图简介 |
120 |
Just as a view is a virtual table, an object view is a virtual
object table. |
如同视图是虚拟的表一样,对象视图[object view]是一个虚拟的对象表[object table]。 |
121 |
Oracle provides object views as an extension of the basic relational
view mechanism. By using object views, you can create virtual object
tables from data—of either built-in or user-defined types—stored in the
columns of relational or object tables in the database. |
Oracle 提供了对象视图作为关系型视图的扩展。通过对象视图,用户可以创建虚拟对象表,用于访问数据库关系型数据表或对象表中存储的数据(数据可以为
Oracle 内置数据类型,也可以为用户定义类型)。 |
122 |
Object views provide the ability to offer specialized or restricted
access to the data and objects in a database. For example, you can use
an object view to provide a version of an employee object table that
does not have attributes containing sensitive data and does not have a
deletion method. |
利用对象视图,可以对数据进行一定处理,或限制用户对数据库内对象及数据的访问。例如,用户可以定义对象视图,创建一个基于员工对象表的虚拟表,利用视图隐藏包含敏感信息的对象属性,并隐藏删除方法。 |
123 |
Object views allow the use of relational data in object-oriented
applications. They let users:
|
通过对象视图,用户可以在面向对象的应用程序中使用关系型数据。用户可以通过对象视图:
|
124 |
Advantages of Object Views |
27.6.1 对象视图的优势 |
125 |
Using object views can lead to better performance. Relational data that
make up a row of an object view traverse the network as a unit,
potentially saving many round trips. |
使用对象视图能够获得更好的性能。构成对象视图数据行的关系型数据在网络中是作为一个整体传输的,这减少了大量网络交互工作[round
trip]。 |
126 |
You can fetch relational data into the client-side object cache and map
it into C or C++ structures so 3GL applications can manipulate it just
like native structures. |
用户可以将关系型数据加载到位于客户端的对象缓存[object cache]中,再将其映射为 C 或 C++ 结构,这样以 3GL
开发的应用程序可以象操作其原生数据结构一样操作关系型数据。 |
127 |
Object views provide a gradual upgrade path for legacy data. They
provide for co-existence of relational and object-oriented applications,
and they make it easier to introduce object-oriented applications to
existing relational data without having to make a drastic change from
one paradigm to another. |
利用对象视图可以渐进地升级历史遗留数据。通过对象视图可以使关系型及面向对象应用程序共存,开发者也可以更便捷地在已有的关系型数据基础上开发面向对象
的应用程序,而不必对数据结构做大的改动。 |
128 |
Object views provide the flexibility of looking at the same relational
or object data in more than one way. Thus you can use different
in-memory object representations for different applications without
changing the way you store the data in the database. |
用户可以利用对象视图灵活地以多种方式查询关系型数据或对象数据。不同的应用程序可以使用不同的对象视图访问数据,数据库内的数据存储结构无需随着应用程序修改。 |
129 |
|
|
130 |
Use of Object Views |
27.6.2 使用对象视图 |
131 |
Data in the rows of an object view can come from more than one table,
but the object still traverses the network in one operation. When the
instance is in the client side object cache, it appears to the
programmer as a C or C++ structure or as a PL/SQL object variable. You
can manipulate it like any other native structure. |
对象视图中的一行数据可能来自多个底层表,但一行数据在网络中是作为一个整体传输。当对象实例被放入客户端的对象缓存后,开发者可以将其作为 C/C++
数据结构或 PL/SQL 变量使用。开发者可以将对象缓存中的对象作为其他语言的原生数据结构使用。 |
132 |
You can refer to object views in SQL statements the same way you refer
to an object table. For example, object views can appear in a
SELECT list, in an
UPDATE SET clause, or in a WHERE
clause. You can also define object views on object views. |
用户在 SQL 语句中使用对象视图与使用对象表的方式一样。例如,在
SELECT 列表,UPDATE SET
子句,或 WHERE
子句中均可以使用对象视图。用户还可以在已有对象视图之上定义新的对象视图。 |
133 |
You can access object view data on the client side using the same OCI
calls you use for objects from object tables. For example, you can use
OCIObjectPin for pinning a
REF and
OCIObjectFlush for flushing an object to the server. When you
update or flush to the server an object in an object view, Oracle
updates the object view. |
用户在客户端可以使用相同的 OCI 调用访问对象表及对象视图中的对象。例如,用户可以使用
OCIObjectPin 定位一个 REF,或使用
OCIObjectFlush 将对象传输到服务器中。当用户在客户端更新对象并将对象传输回服务器时,Oracle
将更新相关的对象视图。 |
134 |
See Also: |
另见: |
135 |
Updates of Object Views |
27.6.3 更新对象视图 |
136 |
You can update, insert, and delete the data in an object view using the
same SQL DML you use for object tables. Oracle updates the base tables
of the object view if there is no ambiguity. |
用户可以对对象视图进行插入,更新,及删除操作,上述操作使用的 SQL DML 与操作对象表的 DML
完全相同。如果更新语句不存在歧义,Oracle 将更新对象视图的底层表。 |
137 |
A view is not updatable if its view query contains joins, set operators,
aggregate functions, GROUP BY, or
DISTINCT. If a view query contains
pseudocolumns or expressions, the corresponding view columns are not
updatable. Object views often involve joins. |
如果对象视图的定义查询中包含连接,集合操作符,聚合函数,GROUP BY,或
DISTINCT,那么此视图是不可更新的。如果对象视图的定义查询中包含虚列[pseudocolumn]或表达式,那么
对应的视图列是不可更新的。需要注意,对象视图通常会包含连接。 |
138 |
To overcome these obstacles Oracle provides
INSTEAD OF triggers. They are called
INSTEAD OF triggers because Oracle runs the trigger body instead
of the actual DML statement. |
为了解决上述问题,Oracle 提供了
INSTEAD OF 触发器。INSTEAD OF 触发器得名于
Oracle 运行触发器程序而非实际 DML 语句。 |
139 |
INSTEAD OF triggers provide a transparent
way to update object views or relational views. You write the same SQL
DML (INSERT, DELETE,
and UPDATE) statements as for an object
table. Oracle invokes the appropriate trigger instead of the SQL
statement, and the actions specified in the trigger body take place. |
INSTEAD OF 触发器是一种透明地更新对象视图或关系型视图的方法。用户可以对对象视图执行正常的 SQL DML 语句(INSERT,DELETE,及 UPDATE),而
Oracle 将调用相应的触发器替代 SQL 语句,触发器内的程序将执行实际的数据更新工作。 |
140 |
|
|
141 |
Updates of Nested Table Columns in Views |
27.6.4 更新视图中的嵌套表列 |
142 |
A nested table can be modified by inserting new elements and updating or
deleting existing elements. Nested table columns that are virtual or
synthesized, as in a view, are not usually updatable. To overcome this,
Oracle allows INSTEAD OF triggers to be
created on these columns. |
对嵌套表[nested table]的修改包括插入新元素,及更新或删除已有元素。如果嵌套表列中包含虚拟或复合数据(例如视图中的数据),那么这种嵌套表列通常是不可更新的。为了解决这种问题,Oracle
可以在嵌套表列上创建 INSTEAD OF 触发器。 |
143 |
The INSTEAD OF trigger defined on a nested
table column of a view is fired when the column is modified. If the
entire collection is replaced by an update of the parent row, then the
INSTEAD OF trigger on the nested table
column is not fired. |
定义在视图的嵌套表列上的 INSTEAD OF
触发器在列被修改时将被触发。如果在更新视图数据行时,嵌套表列保存的集合数据被整个替换,那么此列上的 INSTEAD OF
触发器不会被触发。 |
144 |
See Also: |
另见: |
145 |
View Hierarchies |
27.6.5 对象视图层次结构 |
146 |
An object view can be created as a subview of another object view. The
type of the superview must be the immediate supertype of the type of the
object view being created. Thus, you can build an object view hierarchy
which has a one-to-one correspondence to the type hierarchy. This does
not imply that every view hierarchy must span the entire corresponding
type hierarchy. The view hierarchy can be rooted at any subtype of the
type hierarchy. Furthermore, it does not have to encompass the entire
subhierarchy. |
用户可以基于已有对象视图[object
view]创建新的对象视图(子对象视图[subview])。超对象视图[superview]的类型必须是子对象视图类型的直接超类[immediate
supertype]。也就是说,用户构建的对象视图层次结构与相应的对象层次结构是一一对应的。这并不意味着对象视图层次结构必须完整覆盖相应的对象层次结构。对象视图层次结构的根节点可以是对象层次结构中的任意节点。此外,对象视图层次结构也不必覆盖相应的对象层次结构的完整子结构。 |
147 |
Figure 27-2 illustrates multiple
view hierarchies. |
图 27-2 显示了一个多重对象视图层次结构。 |
148 |
Figure 27-2 Multiple View
Hierarchies |
图 27-2 多重对象视图层次结构 |
149 | ||
150 |
Figure 27-2 shows two view hierarchies as inverted tree structures. They share only the top-level (root) node. VH1 has one child that has one child. VH2 has two children, one of which has two children. The root node also has one child that is not included in either VH1 or VH2. |
图 27-2 显示了两棵倒转的对象类型层次结构树。两棵树拥有共同的顶层节点(根节点)。VH1 有一个子节点,此节点又有一个子节点。VH2 有两个子节点,其中一个字节点也有两个字节点。根节点有一个字节点,既不属于 VH1,也不属于 VH2。 |
151 |
By default, the rows of an object view in a view hierarchy include all
the rows of all its subviews (direct and indirect) projected over the
columns of the given view. |
默认情况下,对象视图层次结构中某个对象视图的数据行包含相应(直接或间接)子视图映射到此对象视图数据列中的全部数据行。 |
152 |
Only one object view can be created as a subview of a given view
corresponding to the given subtype; that is, the same view cannot
participate in many different view hierarchies. An object view can be
created as a subview of only one superview; multiple inheritance is not
supported. |
子对象类型的对象视图只能拥有一个子对象视图,即一个子视图不能存在于不同的对象视图层次结构中。同时,一个子对象视图只能继承自一个超对象视图。Oracle
不支持对象视图的多重继承。 |
153 |
The subview inherits the object identifier from its superview and cannot
be explicitly specified in any subview. |
子对象视图将继承其超对象视图的对象标识符,在子对象视图中不能显式地使用其超对象视图的对象标识符。 |
[004] published interfaces [125] round trip |
[077] empty collection [114] Indextype |
[004] Metadata for user-defined types is
stored in a schema available to SQL, PL/SQL, Java, and other published
interfaces. [017] Oracle uses schema information about object types to achieve substantial transmission efficiencies. A client-side application can request a purchase order from the server and receive all the relevant data in a single transmission. The application can then, without knowing storage locations or implementation details, navigate among related data items without further transmissions from the server. [033] Every object type also has one implicitly defined method that is not tied to specific objects, the object type's constructor method. [047] Oracle lets you view this table in two ways: [068] Dereference REFs [142] Nested table columns that are virtual or synthesized, as in a view, are not usually updatable. [146] An object view can be created as a subview of another object view. The type of the superview must be the immediate supertype of the type of the object view being created. Thus, you can build an object view hierarchy which has a one-to-one correspondence to the type hierarchy. This does not imply that every view hierarchy must span the entire corresponding type hierarchy. The view hierarchy can be rooted at any subtype of the type hierarchy. Furthermore, it does not have to encompass the entire subhierarchy. [151] By default, the rows of an object view in a view hierarchy include all the rows of all its subviews (direct and indirect) projected over the columns of the given view. [153] The subview inherits the object identifier from its superview and cannot be explicitly specified in any subview. |
1、? [152] Only one object view can be created as a subview of a given view corresponding to the given subtype; that is, the same view cannot participate in many different view hierarchies. |