Oracle Schema Objects——Tables——TableType

Oracle Schema Objects

Object Tables

 

 object type

      • An Oracle object type is a user-defined type with a name, attributes, and methods.

Oracle 对象类型是具有名称、 属性、和方法的用户定义类型。

      • Object types make it possible to model real-world entities such as customers and purchase orders as objects in the database.

对象类型使得对现实世界中的实体(如客户和采购单等),作为对象在数据库中进行建模成为可能。

 

      • An object type defines a logical structure, but does not create storage.

对象类型定义逻辑结构,但不会创建存储

创建对象类型

CREATE TYPE department_typ AS OBJECT
   ( d_name     VARCHAR2(100),
     d_address VARCHAR2(200) );
/

object table

An object table is a special kind of table in which each row represents an object.

对象表是一种特殊的表,其中每一行表示一个对象

 

创建对象表

CREATE TABLE departments_obj_t OF department_typ;

INSERT INTO departments_obj_t

VALUES ('hr', '10 Main St, Sometown, CA');

 

  • The CREATE TABLE statement creates an object table named departments_obj_t of the object type department_typ.

CREATE TABLE 语句创建一个名为 departments_obj_t 的对象表,其对象类型为 department_typ 。

  • The attributes (columns) of this table are derived from the definition of the object type.

此表的属性 (列) 派生自该对象类型的定义

  • The INSERT statement inserts a row into this table.

使用INSERT 语句将行插入到此表。

 

 

 

Temporary Tables

temporary tables

      • Oracle Database temporary tables hold data that exists only for the duration of a transaction or session.

Oracle 数据库的 临时表,用于存放只存在于某个事务或会话期间的数据。

      • Data in a temporary table is private to the session, which means that each session can only see and modify its own data.

临时表中的数据是会话私有的,这意味着每个会话只可以查看和修改自己的数据。

      • Temporary tables are useful in applications where a result set must be buffered.

临时表对于必须缓冲中间结果集的应用程序非常有用。

    • For example, a scheduling application enables college students to create optional semester course schedules.
    • Each schedule is represented by a row in a temporary table. During the session, the schedule data is private.
    • When the student decides on a schedule, the application moves the row for the chosen schedule to a permanent table.
    •  At the end of the session, the schedule data in the temporary data is automatically dropped.
    • 例如,一个计划应用程序使学生可以创建可选的学期课程计划。
    • 每个课程计划由临时表中的一行表示。
    • 在会话期间,课程计划数据是私有的。
    • 当某个学生确定了课程计划,应用程序会将其所选计划移入永久表。
    • 在会话结束时,临时表中的课程计划数据将被自动删除。

Temporary Table Creation

创建临时表

      • The CREATE GLOBAL TEMPORARY TABLE statement creates a temporary table.

使用 CREATE GLOBAL TEMPORARY TABLE 语句创建一个临时表。

      • The ON COMMIT clause specifies whether the table data is transaction-specific (default) or session-specific.

ON COMMIT 子句指定表中的数据是特定于事务 (默认值),还是特定于

 

Unlike temporary tables in some other relational databases, when you create a temporary table in an Oracle database, you create a static table definition. The temporary table is a persistent object described in the data dictionary, but appears empty until your session inserts data into the table. You create a temporary table for the database itself, not for every PL/SQL stored procedure.

Because temporary tables are statically defined, you can create indexes for them with the CREATE INDEX statement. Indexes created on temporary tables are also temporary. The data in the index has the same session or transaction scope as the data in the temporary table. You can also create a view or trigger on a temporary table.

 

与其它一些关系数据库中的临时表不同,当你在 Oracle 数据库中创建一个临时表时,你只创建其静态表定义

临时表是在数据字典中所描述的一个持久对象,但在您的会话向表中插入数据之前,表显示为空。

你是在为数据库本身创建一个临时表,而不是为每个 PL/SQL 存储过程。

因为临时表是静态定义的,您可以使用 CREATE INDEX 语句为其创建索

临时表上创建的索引也是临时的。在索引中的数据与临时表中的数据具有相同的会话或事务范围。您还可以在临时表上创建一个视图或触发器。

Segment Allocation in Temporary Tables

临时表中的段分配

Like permanent tables, temporary tables are defined in the data dictionary. Temporary segments are allocated when data is first inserted. Until data is loaded in a session the table appears empty. Temporary segments are deallocated at the end of the transaction for transaction-specific temporary tables and at the end of the session for session-specific temporary tables.

与永久表类似,临时表被定义在数据字典中。

但是,临时表和他们的索引不会在创建时自动分配段

相反,临时段是在第一次插入数据时分配的

在一个会话中加载数据之前,表显示为空。

对特定事务的临时表,临时段在事务结束时释放空间,而对特定于会话的临时表,在会话结束时释放空间。

 

 

 

 

 

External Tables

external table

An external table accesses data in external sources as if this data were in a table in the database. You can use SQL, PL/SQL, and Java to query the external data.

外部表访问外部数据源中的数据,如同此数据是在数据库中的表中一样。您可以使用 SQL PL/SQL、和 Java 查询外部数据。

 

External tables are useful for querying flat files. For example, a SQL-based application may need to access records in a text file. The records are in the following form:

外部表可用于查询平面文件。例如,一个基于 SQL 的应用程序,可能需要访问一个文本文件中的记录。记录的形式如下:

100,Steven,King,SKING,515.123.4567,17-JUN-03,AD_PRES,31944,150,90
101,Neena,Kochhar,NKOCHHAR,515.123.4568,21-SEP-05,AD_VP,17000,100,90
102,Lex,De Haan,LDEHAAN,515.123.4569,13-JAN-01,AD_VP,17000,100,90

 

You could create an external table, copy the file to the location specified in the external table definition, and use SQL to query the records in the text file.

您可以创建一个外部表,把这个文件复制到外部表定义中指定的位置,并使用 SQL 查询该文本文件中的记录。

External tables are also valuable for performing ETL tasks common in data warehouse environments.

外部表对于在数据仓库环境中执行常见的 ETL任务也是很有价值的

For example, external tables enable the pipelining of the data loading phase with the transformation phase, eliminating the need to stage data inside the database in preparation for further processing inside the database.

例如,外部表使得数据加载阶段和数据转换阶段对接,消除了为进一步处理数据库中的数据而在数据库内存放中间数据的需要。

External Table Creation

External Table Creation

Internally, creating an external table means creating metadata in the data dictionary.

数据库内部,创建一个外部表意味着在数据字典中创建元数据

Unlike an ordinary table, an external table does not describe data stored in the database, nor does it describe how data is stored externally.

与普通的表不同,外部表不描述存储在数据库中的数据,也不会描述数据在外部是如何存储的。

Rather, external table metadata describes how the external table layer must present data to the database.

外部表的元数据描述了外部表层必须如何提供数据给数据库

 

A CREATE TABLE ... ORGANIZATION EXTERNAL statement has two parts.

CREATE TABLE ... ORGANIZATION EXTERNAL 语句包含两部分.

 

The external table definition describes the column types.

外部表定义描述列类型

This definition is like a view that enables SQL to query external data without loading it into the database.

这个定义像一个视图,使您可以使用 SQL 查询外部数据,而不用将其加载到数据库。

The second part of the statement maps the external data to the columns.

该语句的第二部分将外部数据映射到列

 

External tables are read-only unless created with CREATE TABLE AS SELECT with the ORACLE_DATAPUMP access driver. 外部表是只读的,除非它是使用 CREATE TABLE AS SELECT ORACLE_DATAPUMP 访问驱动程序创建的。

Restrictions for external tables include no support for indexed columns, virtual columns, and column objects.

外部表有些限制,包括不支持索引列、 虚拟列、和列对象

External Table Access Drivers

外部表访问 驱动程序

External Table Access Drivers

外部表访问 驱动程序

An access driver is an API that interprets the external data for the database.

访问驱动程序是一个 API,它为数据库解释外部数据

The access driver runs inside the database, which uses the driver to read the data in the external table.

访问驱动程序在数据库内运行,数据库使用该驱动程序来读取外部表中的数据。

The access driver and the external table layer are responsible for performing the transformations required on the data in the data file so that it matches the external table definition.

访问驱动程序和外部表层负责对数据文件中的数据进行转换,使它与外部表定义匹配。

xternal Tables外部数据是如何被访问的

Description of Figure 2-4 follows

ORACLE_LOADER (default) and ORACLE_DATAPUMP access drivers

Oracle provides the ORACLE_LOADER (default) and ORACLE_DATAPUMP access drivers for external tables.

Oracle 为外部表提供了 ORACLE_LOADER(缺省)ORACLE_DATAPUMP 访问驱动程序

For both drivers, the external files are not Oracle data files.

对于这两个驱动程序来说,外部文件不是 Oracle 数据文件(,而只是普通操作系统文件)。

 

 ORACLE_LOADER (default)

ORACLE_LOADER enables read-only access to external files using SQL*Loader.

ORACLE_LOADER 允许通 SQL*Loader 对外部文件进行只读访问

You cannot create, update, or append to an external file using the ORACLE_LOADER driver.

您不能使用 ORACLE_LOADER 驱动程序创建、 更新、或追加数据到外部文

ORACLE_DATAPUMP access drivers

The ORACLE_DATAPUMP driver enables you to unload external data.

ORACLE_DATAPUMP 驱动程序使您能够 卸载外部数据

 

This operation involves reading data from the database and inserting the data into an external table, represented by one or more external files.

此操作包括从数据库读取数据,并将其插入到由一个或多个外部文件所代表的外部表中。

After external files are created, the database cannot update or append data to them.

创建外部文件后,无法更新或将追加数据到外部文件。

The driver also enables you to load external data, which involves reading an external table and loading its data into a database.

该驱动程序也使您能够加载外部数据,包括读取外部表并将其数据加载到数据库中。

posted @ 2017-06-23 13:00  寻香径  阅读(526)  评论(0编辑  收藏  举报