26 Native Datatypes


001 This chapter discusses the Oracle built-in datatypes, their properties, and how they map to non-Oracle datatypes.
 
本章讨论 Oracle 内置的数据类型及其特性,以及内置数据类型与非 Oracle 数据类型间的映射关系。
 
002 This chapter contains the following topics: 本章包含以下主题:
003

Introduction to Oracle Datatypes

26.1 Oracle 数据类型简介

004 Each column value and constant in a SQL statement has a datatype, which is associated with a specific storage format, constraints, and a valid range of values. When you create a table, you must specify a datatype for each of its columns.
 
SQL 语句所引用的每个列值[column value]及常量[constant]都属于某个数据类型[datatype],数据类型决定了数据的存储格式,约束,及有效值范围。当用户创建数据表时,必须为每列设定数据类型。
 
005 Oracle provides the following categories of built-in datatypes: Oracle 提供了以下内置数据类型:  
006
Note:

PL/SQL has additional datatypes for constants and variables, which include BOOLEAN, reference types, composite types (collections and records), and user-defined subtypes.
提示:

在 PL/SQL 中提供了额外的数据类型供常量及变量使用,这些类型包括 BOOLEAN,引用类型[reference type],复合类型[composite type](集合[collection]与记录[record]),及用户定义子类型[user-defined subtype]。
007

See Also:

另见:

008 The following sections that describe each of the built-in datatypes in more detail.
 
以下各节将分别详细描述每种内置数据类型。
 
009

Overview of Character Datatypes

26.2 字符数据类型概述

010 The character datatypes store character (alphanumeric) data in strings, with byte values corresponding to the character encoding scheme, generally called a character set or code page.
 
字符数据类型[character datatype]用于存储字符串[string]中的字符(包括文字及数字)数据,其占用的字节数[byte value]是由字符编码方案[character encoding scheme]决定的,字符编码方案也被称为字符集[character set]或编码页[code page]。
 
011 The database's character set is established when you create the database. Examples of character sets are 7-bit ASCII (American Standard Code for Information Interchange), EBCDIC (Extended Binary Coded Decimal Interchange Code), Code Page 500, Japan Extended UNIX, and Unicode UTF-8. Oracle supports both single-byte and multibyte encoding schemes.
 
Oracle 数据库的字符集是在创建数据库时设定的。常见的字符集包括 7-bit ASCII(American Standard Code for Information Interchange[美国标准信息交换编码]),EBCDIC(Extended Binary Coded Decimal Interchange Code[扩展二进制编码的十进制交换编码]),Code Page 500,Japan Extended UNIX,及 Unicode UTF-8。Oracle 支持单字节[single-byte]及多字节[multibyte]编码方案。
 
012

See Also:

另见:

013

CHAR Datatype

26.2.1 CHAR 数据类型

014 The CHAR datatype stores fixed-length character strings. When you create a table with a CHAR column, you must specify a string length (in bytes or characters) between 1 and 2000 bytes for the CHAR column width. The default is 1 byte. Oracle then guarantees that:
  • When you insert or update a row in the table, the value for the CHAR column has the fixed length.
  • If you give a shorter value, then the value is blank-padded to the fixed length.
  • If a value is too large, Oracle returns an error.
CHAR 数据类型用于存储固定长度的字符串。如果用户创建数据表时定义了 CHAR 类型的列,则必须为其设定一个介于 1 到 2000 之间的字符串长度(单位为字节[byte]或字符[character])以表明此列的宽度。CHAR 数据类型的默认长度为 1 字节。Oracle 能够确保:
  • 当用户插入或更新表的数据行时,CHAR 列数据值为固定长度。
  • 如果用户输入的数据值的长度小于定义,Oracle 以空格填充使之达到固定长度。
  • 如果用户输入的数据值的长度大于定义,Oracle 返回错误消息。
015 Oracle compares CHAR values using blank-padded comparison semantics.
 
Oracle 在比较 CHAR 类型的数据时采用空格填充比较语义[blank-padded comparison semantics]。
 
016
See Also:

Oracle Database SQL Reference for details about blank-padded comparison semantics
另见:

Oracle Database SQL Reference 了解空格填充比较语义
017

VARCHAR2 and VARCHAR Datatypes

26.2.2 VARCHAR2 及 VARCHAR 数据类型

018 The VARCHAR2 datatype stores variable-length character strings. When you create a table with a VARCHAR2 column, you specify a maximum string length (in bytes or characters) between 1 and 4000 bytes for the VARCHAR2 column. For each row, Oracle stores each value in the column as a variable-length field unless a value exceeds the column's maximum length, in which case Oracle returns an error. Using VARCHAR2 and VARCHAR saves on space used by the table.
 
VARCHAR2 数据类型用于存储变长的字符串。如果用户创建数据表时定义了 VARCHAR2 类型的列,则必须为其设定一个介于 1 到 4000 之间的字符串长度(单位为字节[byte]或字符[character])以表明此列的宽度。Oracle 为每行的 VARCHAR2 列存储数据所占用的长度是可变的,如果输入的数据长度超出列的定义宽度 Oracle 将返回错误消息。使用 VARCHAR2VARCHAR 类型能够节约数据表所占用的存储空间。
 
019 For example, assume you declare a column VARCHAR2 with a maximum size of 50 characters. In a single-byte character set, if only 10 characters are given for the VARCHAR2 column value in a particular row, the column in the row's row piece stores only the 10 characters (10 bytes), not 50.
 
例如,用户定义一个 VARCHAR2 列的最大宽度为 50 字符。当系统采用单字节字符集时,如果输入的数据行此列值的长度为 10 字符,则在此行对应的行片断[row piece]中,此列只占用 10 字符(10 字节)的存储空间,而非 50 字节。
 
020 Oracle compares VARCHAR2 values using nonpadded comparison semantics.
 
Oracle 在比较 VARCHAR2 类型的数据时采用非填充比较语义[nonpadded comparison semantics]。
 
021
See Also:

Oracle Database SQL Reference for details about nonpadded comparison semantics
另见:

Oracle Database SQL Reference 了解非填充比较语义
022

VARCHAR Datatype

26.2.2.1 VARCHAR 数据类型

023 The VARCHAR datatype is synonymous with the VARCHAR2 datatype. To avoid possible changes in behavior, always use the VARCHAR2 datatype to store variable-length character strings.
 
VARCHAR 数据类型是 VARCHAR2 数据类型的同义词[synonymous]。为了避免对代码产生影响,开发者应使用 VARCHAR2 数据类型存储变长字符串。
 
024

Length Semantics for Character Datatypes

26.2.3 字符数据类型的长度语义

025 Globalization support allows the use of various character sets for the character datatypes. Globalization support lets you process single-byte and multibyte character data and convert between character sets. Client sessions can use client character sets that are different from the database character set.
 
Oracle 的全球化支持[globalization support]特性使字符数据类型能够使用多种字符集。全球化支持特性可以处理单字节及多字节字符数据并在两者间进行转换。客户端会话使用的客户字符集可以与数据库字符集不同。
 
026 Consider the size of characters when you specify the column length for character datatypes. You must consider this issue when estimating space for tables with columns that contain character data.
 
当用户为字符数据类型设定列长度时需要考虑字符的大小。用户在预估数据表所占用的空间时,必须考虑字符数据列对空间的影响。
 
027 The length semantics of character datatypes can be measured in bytes or characters.
  • Byte semantics treat strings as a sequence of bytes. This is the default for character datatypes.
  • Character semantics treat strings as a sequence of characters. A character is technically a codepoint of the database character set.
字符数据类型的长度语义[length semantic]有两种:
  • 字节语义[byte semantic]把字符串看作字节数据的序列。字符数据类型默认使用此种语义。
  • 字符语义[character semantic]把字符串看作字符数据的序列。每个字符 均为数据库字符集中的一个元素。
028 For single byte character sets, columns defined in character semantics are basically the same as those defined in byte semantics. Character semantics are useful for defining varying-width multibyte strings; it reduces the complexity when defining the actual length requirements for data storage. For example, in a Unicode database (UTF8), you need to define a VARCHAR2 column that can store up to five Chinese characters together with five English characters. In byte semantics, this would require (5*3 bytes) + (1*5 bytes) = 20 bytes; in character semantics, the column would require 10 characters.
 
对于单字节的字符集,采用字符语义定义的列与采用字节语义定义的列基本相同。当定义变长的多字节字符串时,使用字符语义更为简便,用户不必计算数据存储所需的实际长度。例如,在采用 Unicode(UTF8)的数据库中,用户需要定义一个 VARCHAR2 列用于存储最多 5 个中文字符及 5 个英文字符。使用字节语义时,此列需要(5*3 字节)+(5*1 字节)= 20 字节;而使用字符语义时,只需设定此列为 10 字符。
 
029 VARCHAR2(20 BYTE) and SUBSTRB(<string>, 1, 20) use byte semantics. VARCHAR2(10 CHAR) and SUBSTR(<string>, 1, 10) use character semantics.
 
VARCHAR2(20 BYTE) SUBSTRB(<string>, 1, 20) 采用的是字节语义。而 VARCHAR2(10 CHAR) SUBSTR(<string>, 1, 10) 采用的是字符语义。
 
030 The parameter NLS_LENGTH_SEMANTICS decides whether a new column of character datatype uses byte or character semantics. The default length semantic is byte. If all character datatype columns in a database use byte semantics (or all use character semantics) then users do not have to worry about which columns use which semantics. The BYTE and CHAR qualifiers shown earlier should be avoided when possible, because they lead to mixed-semantics databases. Instead, the NLS_LENGTH_SEMANTICS initialization parameter should be set appropriately in the server parameter file (SPFILE) or initialization parameter file, and columns should use the default semantics.
 
NLS_LENGTH_SEMANTICS 初始化参数决定了一个字符数据类型列采用字符语义或字节语义。Oracle 默认的长度语义是字节语义。如果一个数据库中所有字符数据类型列均采用字节语义(或均采用字符语义),用户在使用过程中就不会产生混淆。用户应尽量避免 使用前例中的 BYTECHAR 限定符,因为这将导致同一数据库中存在多种长度语义。用户应在服务端参数文件[server parameter file,SPFILE]或初始化参数文件[initialization parameter file]中设置 NLS_LENGTH_SEMANTICS 初始化参数,并在定义列时采用初始化参数指定的默认长度语义。
 
031

See Also:

另见:

032

NCHAR and NVARCHAR2 Datatypes

26.2.4 NCHAR 及 NVARCHAR2 数据类型

033 NCHAR and NVARCHAR2 are Unicode datatypes that store Unicode character data. The character set of NCHAR and NVARCHAR2 datatypes can only be either AL16UTF16 or UTF8 and is specified at database creation time as the national character set. AL16UTF16 and UTF8 are both Unicode encoding.
  • The NCHAR datatype stores fixed-length character strings that correspond to the national character set.
  • The NVARCHAR2 datatype stores variable length character strings.
NCHARNVARCHAR2 均为 Unicode 数据类型,用于存储以 Unicode 编码的字符数据。NCHARNVARCHAR2 使用的字符集只能为 AL16UTF16UTF8,此字符集为创建数据库时设定的国家字符集[national character set]。AL16UTF16UTF8 均采用 Unicode 编码。
  • NCHAR 数据类型用于存储以国家字符集编码的固定长度字符串。
  • NVARCHAR2 数据类型用于存储变长字符串。
034 When you create a table with an NCHAR or NVARCHAR2 column, the maximum size specified is always in character length semantics. Character length semantics is the default and only length semantics for NCHAR or NVARCHAR2.
 
当用户创建的表包含 NCHARNVARCHAR2 列时,只能使用字符长度语义设定列的最大长度。字符长度语义是 NCHARNVARCHAR2 数据类型默认且唯一的长度语义。
 
035 For example, if national character set is UTF8, then the following statement defines the maximum byte length of 90 bytes:
 
例如,国家字符集为 UTF8,以下语句所定义的列的最大长度为 90 字节:
 
036
CREATE TABLE tab1 (col1 NCHAR(30));
CREATE TABLE tab1 (col1 NCHAR(30));
037 This statement creates a column with maximum character length of 30. The maximum byte length is the multiple of the maximum character length and the maximum number of bytes in each character.
 
上述语句所创建的列的最大长度为 30 字符。列的最大字节长度为列的最大字符长度乘每个字符的最大字节数。
 
038

NCHAR

26.2.4.1 NCHAR

039 The maximum length of an NCHAR column is 2000 bytes. It can hold up to 2000 characters. The actual data is subject to the maximum byte limit of 2000. The two size constraints must be satisfied simultaneously at run time.
 
NCHAR 列的最大长度为 2000 字节。NCHAR 列最多容纳 2000 字符。而其中实际存储的数据必须低于 2000 字节的限制。这两个容量限制必须同时满足。
 
040

NVARCHAR2

26.2.4.2 NVARCHAR2

041 The maximum length of an NVARCHAR2 column is 4000 bytes. It can hold up to 4000 characters. The actual data is subject to the maximum byte limit of 4000. The two size constraints must be satisfied simultaneously at run time.
 
NVARCHAR2 列的最大长度为 4000 字节。NVARCHAR2 列最多容纳 4000 字符。而其中实际存储的数据必须低于 4000 字节的限制。这两个容量限制必须同时满足。
 
042
See Also:

Oracle Database Globalization Support Guide for more information about the NCHAR and NVARCHAR2 datatypes
另见:

Oracle Database Globalization Support Guide 了解关于 NCHARNVARCHAR2 数据类型的详细信息
043

Use of Unicode Data in an Oracle Database

26.2.5 在 Oracle 数据库中使用 Unicode 数据

044 Unicode is an effort to have a unified encoding of every character in every language known to man. It also provides a way to represent privately-defined characters. A database column that stores Unicode can store text written in any language.
 
Unicode 的目标是将所有人类语言使用的字符统一编码。同时 Unicode 还提供了自定义字符的方式。一个能够存储 Unicode 的数据库列能够存储任何语言的文本数据。
 
045 Oracle users deploying globalized applications have a strong need to store Unicode data in Oracle databases. They need a datatype which is guaranteed to be Unicode regardless of the database character set.
 
如果用户需要部署全球化的应用程序,一定需要在 Oracle 数据库中存储 Unicode 数据。用户需要一种保证采用 Unicode 编码的数据类型(无论数据库字符集采用何种编码方式)。
 
046 Oracle supports a reliable Unicode datatype through NCHAR, NVARCHAR2, and NCLOB. These datatypes are guaranteed to be Unicode encoding and always use character length semantics. The character sets used by NCHAR/NVARCHAR2 can be either UTF8 or AL16UTF16, depending on the setting of the national character set when the database is created. These datatypes allow character data in Unicode to be stored in a database that may or may not use Unicode as database character set.
 
Oracle 通过 NCHARNVARCHAR2,及 NCLOB 数据类型提供了可靠的 Unicode 支持。Oracle 确保这些数据类型采用 Unicode 编码,并使用字符长度语义。这些数据类型使用的字符集为 UTF8 AL16UTF16,由创建数据库时设定的国家字符集决定。通过这些数据类型,用户可以在未使用 Unicode 数据库字符集的数据库中存储以 Unicode 编码的数据。
 
047

Implicit Type Conversion

26.2.5.1 隐式类型转换

048 In addition to all the implicit conversions for CHAR/VARCHAR2, Oracle also supports implicit conversion for NCHAR/NVARCHAR2. Implicit conversion between CHAR/VARCHAR2 and NCHAR/NVARCHAR2 is also supported.
 
Oracle 支持 CHAR/VARCHAR2 数据类型的隐式转换,也支持 NCHAR/NVARCHAR2 数据类型的隐式转换。此外,Oracle 还支持 CHAR/VARCHAR2NCHAR/NVARCHAR2 间的隐式转换。
 
049

LOB Character Datatypes

26.2.6 LOB 字符数据类型

050 The LOB datatypes for character data are CLOB and NCLOB. They can store up to 8 terabytes of character data (CLOB) or national character set data (NCLOB).
 
CLOBNCLOB 是用于存储字符数据的 LOB 数据类型。这两种数据类型分别可存储最大 8 TB(terabyte)的字符数据(CLOB)及国家字符集数据(NCLOB)。
 
051
See Also:

"Overview of LOB Datatypes"
另见:

LOB 数据类型概述
052

LONG Datatype

26.2.7 LONG 数据类型

053
Note:

Do not create tables with LONG columns. Use LOB columns (CLOB, NCLOB) instead. LONG columns are supported only for backward compatibility.

Oracle also recommends that you convert existing LONG columns to LOB columns. LOB columns are subject to far fewer restrictions than LONG columns. Further, LOB functionality is enhanced in every release, whereas LONG functionality has been static for several releases.
提示:

不要在新创建的表中使用数据类型为 LONG 的数据列,而应使用 LOB 数据类型(CLOBNCLOB)作为替代。LONG 数据类型只用于向后兼容[backward compatibility]。

Oracle 建议用户将现有的 LONG 数据列转换为 LOB 类型。LOB 数据类型所受的限制远少于 LONG 类型。此外,Oracle 各个版本中均对 LOB 功能有所加强,而关于 LONG 的功能已经不再更新。
054 Columns defined as LONG can store variable-length character data containing up to 2 gigabytes of information. LONG data is text data that is to be appropriately converted when moving among different systems.
 
定义为 LONG 类型的列可存储最大 2 GB 的变长数据。LONG 类型的数据实际为文本数据,经过适当转换后可以在不同系统间进行迁移。
 
055 LONG datatype columns are used in the data dictionary to store the text of view definitions. You can use LONG columns in SELECT lists, SET clauses of UPDATE statements, and VALUES clauses of INSERT statements.
 
Oracle 数据字典中使用 LONG 数据类型的列存储视图定义的文本。用户可以在 SELECT 列表,UPDATE 语句的 SET 子句,及 INSERT 语句的 VALUES 子句中使用 LONG 类型的列。
 
056

See Also:

另见:

057

Overview of Numeric Datatypes

26.3 数字数据类型概述

058 The numeric datatypes store positive and negative fixed and floating-point numbers, zero, infinity, and values that are the undefined result of an operation (that is, is "not a number" or NAN).
 
数字数据类型[numeric datatype]用于存储正负整数、浮点数,零,无穷数,及一个操作返回的未定义结果值(即“非数字”或 NAN)。
 
059

NUMBER Datatype

26.3.1 NUMBER 数据类型

060 The NUMBER datatype stores fixed and floating-point numbers. Numbers of virtually any magnitude can be stored and are guaranteed portable among different systems operating Oracle, up to 38 digits of precision.
 
NUMBER 数据类型用于存储固定及浮点数字。NUMBER 数据类型可以存储任意数量级的数字,NUMBER 数据能够在运行 Oracle 的不同操作系统间迁移,数字的精度[precision]最高可达 38 位。
 
061 The following numbers can be stored in a NUMBER column:
  • Positive numbers in the range 1 x 10-130 to 9.99...9 x 10125 with up to 38 significant digits
  • Negative numbers from -1 x 10-130 to 9.99...99 x 10125 with up to 38 significant digits
  • Zero
  • Positive and negative infinity (generated only by importing from an Oracle Version 5 database)
以下数字数据均可以存储在 NUMBER 类型的数据列中:
  • 范围在 1 x 10-130 到 9.99...9 x 10125 之间的正数,最高 38 位有效数字
  • 范围在 -1 x 10-130 到 9.99...99 x 10125 之间的负数,最高 38 位有效数字
  • 正负无穷(只存在于从 Oracle 数据库版本 5 导入的数据中)
062 For numeric columns, you can specify the column as:
 
用户可以按以下方式定义数字列:
 
063
column_name NUMBER
column_name NUMBER
064 Optionally, you can also specify a precision (total number of digits) and scale (number of digits to the right of the decimal point):
 
此外,用户还可以设定 NUMBER 数据类型的精度[precision](数字位数)和小数位[scale](小数点右侧的数据位数):
 
065
column_name NUMBER (precision, scale)
column_name NUMBER (precision, scale)
066 If a precision is not specified, the column stores values as given. If no scale is specified, the scale is zero.
 
如果用户没有设定精度,则此列直接存储输入的值。如果用户没有设定小数位,则小数位默认为 0。
 
067 Oracle guarantees portability of numbers with a precision equal to or less than 38 digits. You can specify a scale and no precision:
 
Oracle 在迁移 NUMBER 类型的数据时,能够确保其精度小于等于 38 位。用户定义 NUMBER 类型时可以只设定小数位而不设定精度:
 
068
column_name NUMBER (*, scale)
column_name NUMBER (*, scale)
069 In this case, the precision is 38, and the specified scale is maintained.
 
上述例子中,数据列的精度为 38,小数位为用户设定的值。
 
070 When you specify numeric fields, it is a good idea to specify the precision and scale. This provides extra integrity checking on input.
 
在定义数字数据类型的数据列时应尽量设定精度及小数位。Oracle 能够根据定义对输入的数据进行完整性检查。
 
071 Table 26-1 shows examples of how data would be stored using different scale factors.
 
表 26-1 显示了不同小数位设定下数据是如何存储的。

 
072 Table 26-1 How Scale Factors Affect Numeric Data Storage
 
表 26-1 小数位如何影响数字数据的存储
 
073

Input Data
 
Specified As
 
Stored As
 

7,456,123.89
 
NUMBER
 
7456123.89
 
7,456,123.89
 
NUMBER(*,1)
 
7456123.9
 
7,456,123.89
 
NUMBER(9)
 
7456124
 
7,456,123.89
 
NUMBER(9,2)
 
7456123.89
 
7,456,123.89
 
NUMBER(9,1)
 
7456123.9
 
7,456,123.89
 
NUMBER(6)
 
(not accepted, exceeds precision)
 
7,456,123.89
 
NUMBER(7,-2)
 
7456100
 
 

Input Data
 
Specified As
 
Stored As
 

7,456,123.89
 
NUMBER
 
7456123.89
 
7,456,123.89
 
NUMBER(*,1)
 
7456123.9
 
7,456,123.89
 
NUMBER(9)
 
7456124
 
7,456,123.89
 
NUMBER(9,2)
 
7456123.89
 
7,456,123.89
 
NUMBER(9,1)
 
7456123.9
 
7,456,123.89
 
NUMBER(6)
 
(不接受,超过设定的精度值)
 
7,456,123.89
 
NUMBER(7,-2)
 
7456100
 
 
074 If you specify a negative scale, then Oracle rounds the actual data to the specified number of places to the left of the decimal point. For example, specifying (7,-2) means Oracle rounds to the nearest hundredths, as shown in Table 26-1.
 
如果用户设定的小数位为负值,Oracle 在小数点左侧的相应位置对输入数据四舍五入。例如,设定 (7,-2) 表示 Oracle 将在十位对数据进行四舍五入,如 表 26-1 所示。
 
075 For input and output of numbers, the standard Oracle default decimal character is a period, as in the number 1234.56. The decimal is the character that separates the integer and decimal parts of a number. You can change the default decimal character with the initialization parameter NLS_NUMERIC_CHARACTERS. You can also change it for the duration of a session with the ALTER SESSION statement. To enter numbers that do not use the current default decimal character, use the TO_NUMBER function.
 
对于输入及输出的数据,Oracle 默认的小数点字符[decimal character]为点号,如数字 1234.56 所示。小数点字符是分隔数字整数及小数部分的字符。用户可以通过初始化参数 NLS_NUMERIC_CHARACTERS 修改默认的小数点字符。用户也可以使用 ALTER SESSION 语句修改一个会话的默认小数点字符。如需输入没有采用默认小数点字符的数据,可以使用 TO_NUMBER 函数进行转换。
 
076

Internal Numeric Format

26.3.1.1 数字数据存储格式

077 Oracle stores numeric data in variable-length format. Each value is stored in scientific notation, with 1 byte used to store the exponent and up to 20 bytes to store the mantissa. The resulting value is limited to 38 digits of precision. Oracle does not store leading and trailing zeros. For example, the number 412 is stored in a format similar to 4.12 x 102, with 1 byte used to store the exponent(2) and 2 bytes used to store the three significant digits of the mantissa(4,1,2). Negative numbers include the sign in their length.
 
Oracle 以变长格式存储数字数据。所有数字数据均以科学计数法存储[scientific notation],使用 1 字节存储指数[exponent],最多 20 字节存储尾数[mantissa]。最终存储的数字数据受限于 38 位精度限制。且 Oracle 不会存储数字首端及末端的 0。举例来说,数字 412 在存储时的格式可以理解为 4.12 x 102,Oracle 使用 1 字节存储指数(2),使用 2 字节存储尾数的三位有效数字(4,1,2)。存储负数时,符号也需要占用存储空间。
 
078 Taking this into account, the column size in bytes for a particular numeric data value NUMBER(p), where p is the precision of a given value, can be calculated using the following formula:
 
综合上述存储特性,定义为 NUMBER(p)p 表示数字值的精度)的数字数据值所占用的字节数可以通过以下公式计算:
 
079
ROUND((length(p)+s)/2))+1
ROUND((length(p)+s)/2))+1
080 where s equals zero if the number is positive, and s equals 1 if the number is negative.
 
如果数字为正数则 s 值为 0,如果数字为负值则 s 值为 1。
 
081 Zero and positive and negative infinity (only generated on import from Version 5 Oracle databases) are stored using unique representations. Zero and negative infinity each require 1 byte; positive infinity requires 2 bytes.
 
零与正负无穷(只存在于从 Oracle 数据库版本 5 导入的数据中)采用特殊格式存储。零及负无穷需要占用 1 字节,正无穷需要占用 2 字节。
 
082

Floating-Point Numbers

26.3.2 浮点数字

083 Oracle provides two numeric datatypes exclusively for floating-point numbers: BINARY_FLOAT and BINARY_DOUBLE. They support all of the basic functionality provided by the NUMBER datatype. However, while NUMBER uses decimal precision, BINARY_FLOAT and BINARY_DOUBLE use binary precision. This enables faster arithmetic calculations and usually reduces storage requirements.
 
Oracle 为存储浮点数提供了两种专用的数据类型:BINARY_FLOATBINARY_DOUBLE。这两种数据类型均支持 NUMBER 数据类型所提供的基本功能。但 BINARY_FLOATBINARY_DOUBLE 采用二进制精度,而 NUMBER 采用十进制精度。因此这两种数据类型能够提供更快的数学运算速度,且能减少占用的存储空间。
 
084 BINARY_FLOAT and BINARY_DOUBLE are approximate numeric datatypes. They store approximate representations of decimal values, rather than exact representations. For example, the value 0.1 cannot be exactly represented by either BINARY_DOUBLE or BINARY_FLOAT. They are frequently used for scientific computations. Their behavior is similar to the datatypes FLOAT and DOUBLE in Java and XMLSchema.
 
BINARY_FLOAT BINARY_DOUBLE 均为近似数字类型。她们存储数字的近似值而非准确值。例如,BINARY_FLOAT BINARY_DOUBLE 只能存储 0.1 的近似值。此种数据类型常用于科学计算。此种数据类型上可执行的操作与 Java 及 XMLSchema 中的 FLOATDOUBLE 数据类型类似。
 
085

BINARY_FLOAT Datatype

26.3.2.1 BINARY_FLOAT 数据类型

086 BINARY_FLOAT is a 32-bit, single-precision floating-point number datatype. Each BINARY_FLOAT value requires 5 bytes, including a length byte.
 
BINARY_FLOAT 是一种 32 位,单精度浮点数字数据类型。每个 BINARY_FLOAT 值需要 5 字节存储空间,其中 1 字节用于存储数据值的长度。
 
087

BINARY_DOUBLE Datatype

26.3.2.2 BINARY_DOUBLE 数据类型

088 BINARY_DOUBLE is a 64-bit, double-precision floating-point number datatype. Each BINARY_DOUBLE value requires 9 bytes, including a length byte.
 
BINARY_DOUBLE 是一种 64 位,双精度浮点数字数据类型。每个 BINARY_DOUBLE 值需要 9 字节存储空间,其中 1 字节用于存储数据值的长度。
 
089
Note:

BINARY_DOUBLE and BINARY_FLOAT implement most of the Institute of Electrical and Electronics Engineers (IEEE) Standard for Binary Floating-Point Arithmetic, IEEE Standard 754-1985 (IEEE754). For a full description of the Oracle implementation of floating-point numbers and its differences from IEEE754, see the Oracle Database SQL Reference
提示:

BINARY_DOUBLEBINARY_FLOAT 类型基本符合 IEEE 制定的二进制浮点数字标准,IEEE 标准 754-1985(IEEE754)。用户可参考 Oracle Database SQL Reference 了解 Oracle 浮点数据类型实现的详细描述,及其与 IEEE754 标准的区别。
090

Overview of DATE Datatype

26.4 DATE 数据类型概述

091 The DATE datatype stores point-in-time values (dates and times) in a table. The DATE datatype stores the year (including the century), the month, the day, the hours, the minutes, and the seconds (after midnight).
 
DATE 数据类型用于存储时刻点[point-in-time]数据(包括日期及时间)。DATE 数据类型中包含年(包括世纪),月,日,小时,分钟,及秒。
 
092 Oracle can store dates in the Julian era, ranging from January 1, 4712 BCE through December 31, 4712 CE (Common Era, or 'AD'). Unless BCE ('BC' in the format mask) is specifically used, CE date entries are the default.
 
Oracle 能够存储儒略历[Julian era]形式的日期数据,范围自公元前 4712 年 1 月 1 日起,至公元 4712 年 12 月 31 日止。CE(公元后,也写为“AD”)是 DATE 数据的默认属性,除非用户设定使用 BCE(在格式掩码[format mask]中以“BC”表示)。
 
093 Oracle uses its own internal format to store dates. Date data is stored in fixed-length fields of seven bytes each, corresponding to century, year, month, day, hour, minute, and second.
 
Oracle 实际存储日期数据时使用一种内部格式。日期数据的存储长度固定为 7 字节,各个字节依次为世纪,年,月,日,小时,分钟,及秒。
 
094 For input and output of dates, the standard Oracle date format is DD-MON-YY, as follows:
 
在输入输出日期数据时,Oracle 使用的标准日期格式为 DD-MON-YY,如下所示:
 
095
'13-NOV-92'
'13-NOV-92'
096 You can change this default date format for an instance with the parameter NLS_DATE_FORMAT. You can also change it during a user session with the ALTER SESSION statement. To enter dates that are not in standard Oracle date format, use the TO_DATE function with a format mask:
 
用户可以通过 NLS_DATE_FORMAT 参数修改实例的日期格式。用户也可以使用 ALTER SESSION 语句修改会话期间的日期格式。如需输入非 Oracle 标准格式的日期数据,可以使用 TO_DATE 函数及格式掩码进行转换:
 
097
TO_DATE ('November 13, 1992', 'MONTH DD, YYYY')
TO_DATE ('November 13, 1992', 'MONTH DD, YYYY')
098 Oracle stores time in 24-hour format—HH:MI:SS. By default, the time in a date field is 00:00:00 A.M. (midnight) if no time portion is entered. In a time-only entry, the date portion defaults to the first day of the current month. To enter the time portion of a date, use the TO_DATE function with a format mask indicating the time portion, as in:
 
Oracle 以 24 小时的格式存储时间数据——HH:MI:SS。如用户没有输入日期数据中的时间部分,默认的时间值为 00:00:00 A.M(午夜)。对于只具有时间的日期数据,日期部分的默认值为当前月的第一天。在输入日期数据的时间部分时,可以使用 TO_DATE 函数及格式掩码:
 
099
INSERT INTO birthdays (bname, bday) VALUES
('ANDY',TO_DATE('13-AUG-66 12:56 A.M.','DD-MON-YY HH:MI A.M.'));
INSERT INTO birthdays (bname, bday) VALUES
('ANDY',TO_DATE('13-AUG-66 12:56 A.M.','DD-MON-YY HH:MI A.M.'));
100

Use of Julian Dates

26.4.1 使用儒略历日期数据

101 Julian dates allow continuous dating by the number of days from a common reference. (The reference is 01-01-4712 years BCE, so current dates are somewhere in the 2.4 million range.) A Julian date is nominally a noninteger, the fractional part being a portion of a day. Oracle uses a simplified approach that results in integer values. Julian dates can be calculated and interpreted differently. The calculation method used by Oracle results in a seven-digit number (for dates most often used), such as 2449086 for 08-APR-93.
 
对于儒略历日期数据,可以在一个基准日期的基础上通过天数累加来进行日期计算。(基准日期为 01-01-公元前 4712,因此现在的时间大概位于 240 万天前后的位置上。)儒略历日期数据理论上是一个非整型数,数据的小数部分代表一天中的部分时间。Oracle 将儒略历日期数据简化为整数值。儒略历日期数据有多种 计算及解释方法。Oracle 使用的计算方法能够将(大多数常用的)日期数据转换为一个 7 位的数字,例如 2449086 对应 08-APR-93。
 
102
Note:

Oracle Julian dates might not be compatible with Julian dates generated by other date algorithms.
提示:

Oracle 儒略历日期数据可能与其他日期算法生成的儒略历日期数据不兼容。
103 The format mask 'J' can be used with date functions (TO_DATE or TO_CHAR) to convert date data into Julian dates. For example, the following query returns all dates in Julian date format:
 
在日期函数(TO_DATE TO_CHAR)中可以使用格式掩码“J”将日期数据转换为儒略历日期数据。例如,以下查询将所有日期数据转换为儒略历日期格式:
 
104
SELECT TO_CHAR (hire_date, 'J') FROM employees;
SELECT TO_CHAR (hire_date, 'J') FROM employees;
105 You must use the TO_NUMBER function if you want to use Julian dates in calculations. You can use the TO_DATE function to enter Julian dates:
 
如果用户需要对儒略历日期数据进行计算,必须使用 TO_NUMBER 函数。用户可以使用 TO_DATE 函数输入儒略历日期数据:
 
106
INSERT INTO employees (hire_date) VALUES (TO_DATE(2448921, 'J'));
INSERT INTO employees (hire_date) VALUES (TO_DATE(2448921, 'J'));
107

Date Arithmetic

26.4.2 日期数据运算

108 Oracle date arithmetic takes into account the anomalies of the calendars used throughout history. For example, the switch from the Julian to the Gregorian calendar, 15-10-1582, eliminated the previous 10 days (05-10-1582 through 14-10-1582). The year 0 does not exist.
 
Oracle 进行日期数据运算时能够考虑历史上存在异常的日期。例如,将儒略历日期数据转换为格利高里历日期数据时,不计算 05-10-1582 至 14-10-1582 之间的 10 天。此外,Oracle 中不存在 0 年。
 
109 You can enter missing dates into the database, but they are ignored in date arithmetic and treated as the next "real" date. For example, the next day after 04-10-1582 is 15-10-1582, and the day following 05-10-1582 is also 15-10-1582.
 
用户可以向数据库中输入上述 10 天中的日期,但在日期算法中这些日期将被忽略,其值以下一个有效日期替代。例如,在 Oracle 中,04-10-1582 之后的一天为 15-10-1582,05-10-1582 之后的一天也为 15-10-1582。
 
110
Note:

This discussion of date arithmetic might not apply to all countries' date standards (such as those in Asia).
提示:

本节讨论的日期算法可能不适合所有国家(例如某些亚洲国家)的日期标准。
111

Centuries and the Year 2000

26.4.3 世纪及 2000 年

112 Oracle stores year data with the century information. For example, the Oracle database stores 1996 or 2001, and not simply 96 or 01. The DATE datatype always stores a four-digit year internally, and all other dates stored internally in the database have four digit years. Oracle utilities such as import, export, and recovery also deal with four-digit years.
 
Oracle 在存储年份数据时包含了世纪信息。例如,Oracle 数据库中存储的年份为 1996 或 2001,而非 96 或 01。DATE 数据类型在数据库内部存储时使用 4 位数字表示年份,其他日期类型在数据库内部存储也使用 4 位数字表示年份。用于数据导入,导出及数据恢复的 Oracle 工具也使用 4 位数字表示年份。
 
113

Daylight Savings Support

26.4.4 夏令时支持

114 Oracle Database provides daylight savings support for DATETIME datatypes in the server. You can insert and query DATETIME values based on local time in a specific region. The DATETIME datatypes TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE are time-zone aware.
 
Oracle 数据库处理 DATETIME 数据类型时支持夏令时[daylight saving]。用户在插入或查询 DATETIME 类型的数据时可以使用特定区域的当地时间。DATETIME 数据类型中的 TIMESTAMP WITH TIME ZONETIMESTAMP WITH LOCAL TIME ZONE 类型能够处理时区。
 
115

See Also:

另见:

116

Time Zones

26.4.5 时区

117 You can include the time zone in your date/time data and provides support for fractional seconds. Three new datatypes are added to DATE, with the following differences:
 
在日期/时间数据中可以加入时区数据,日期/时间数据也支持分数秒[fractional second]。除 DATE 数据类型外还有三种日期数据类型,这些类型的区别如下所示:
 
118

Datatype
 
Time Zone
 
Fractional Seconds
 

DATE
 
No
 
No
 
TIMESTAMP
 
No
 
Yes
 
TIMESTAMP WITH TIME ZONE
 
Explicit
 
Yes
 
TIMESTAMP WITH LOCAL TIME ZONE
 
Relative
 
Yes
 
 

日期类型
 
时区
 
分数秒
 

DATE
 

 

 
TIMESTAMP
 

 

 
TIMESTAMP WITH TIME ZONE
 
显式的
 

 
TIMESTAMP WITH LOCAL TIME ZONE
 
相对的
 

 
 
119 TIMESTAMP WITH LOCAL TIME ZONE is stored in the database time zone. When a user selects the data, the value is adjusted to the user's session time zone.
 
TIMESTAMP WITH LOCAL TIME ZONE 数据是根据数据库时区设置存储的。当用户查询数据时,数据值将被调整为用户会话所在时区的时间。
 
120 For example, a San Francisco database has system time zone = -8:00. When a New York client (session time zone = -5:00) inserts into or selects from the San Francisco database, TIMESTAMP WITH LOCAL TIME ZONE data is adjusted as follows:
  • The New York client inserts TIMESTAMP'1998-1-23 6:00:00-5:00' into a TIMESTAMP WITH LOCAL TIME ZONE column in the San Francisco database. The inserted data is stored in San Francisco as binary value 1998-1-23 3:00:00.
  • When the New York client selects that inserted data from the San Francisco database, the value displayed in New York is '1998-1-23 6:00:00'.
  • A San Francisco client, selecting the same data, see the value '1998-1-23 3:00:00'.
例如,位于 San Francisco 的数据库的系统时区为 -8:00。一个位于 New York 的客户(会话时区为 -5:00)在 San Francisco 的数据库中进行查询或插入操作时,TIMESTAMP WITH LOCAL TIME ZONE 数据的调整规则如下:
  • 位于 New York 的客户将值为 '1998-1-23 6:00:00-5:00'TIMESTAMP 数据插入到 San Francisco 数据库的 TIMESTAMP WITH LOCAL TIME ZONE 列。此数据在数据库中的二进制值为 1998-1-23 3:00:00
  • 当位于 New York 的客户从 San Francisco 的数据库中查询此数据时显示为 '1998-1-23 6:00:00'
  • 位于 San Francisco 的客户查询相同的数据则显示为 '1998-1-23 3:00:00'
121
Note:

To avoid unexpected results in your DML operations on datatime data, you can verify the database and session time zones by querying the built-in SQL functions DBTIMEZONE and SESSIONTIMEZONE. If the database time zone or the session time zone has not been set manually, Oracle uses the operating system time zone by default. If the operating system time zone is not a valid Oracle time zone, then Oracle uses UTC as the default value.
提示:

为了避免对日期时间数据进行 DML 操作时出现非预期的结果,用户可以通过内置的 SQL 函数 DBTIMEZONESESSIONTIMEZONE 确定数据库及会话的时区设置。如果用户没有手工设置数据库及会话的时区,Oracle 将默认使用操作系统的时区。如果操作系统的时区设置不是有效的 Oracle 时区,Oracle 将默认使用 UTC。
122
See Also:

Oracle Database SQL Reference for details about the syntax of creating and entering data in time stamp columns
另见:

Oracle Database SQL Reference 了解创建及输入时间戳数据的语法
123

Overview of LOB Datatypes

26.5 LOB 数据类型概述

124 The LOB datatypes BLOB, CLOB, NCLOB, and BFILE enable you to store and manipulate large blocks of unstructured data (such as text, graphic images, video clips, and sound waveforms) in binary or character format. They provide efficient, random, piece-wise access to the data. Oracle recommends that you always use LOB datatypes over LONG datatypes. You can perform parallel queries (but not parallel DML or DDL) on LOB columns.
 
BLOBCLOBNCLOB,及 BFILE 四种 LOB 数据类型可供用户存储或操作二进制格式或字符格式的大型非结构化数据(例如文本,图像,视频片断,及声音波形)。LOB 数据类型能够提供高效,随机,基于块[piece-wise]的数据访问。Oracle 建议用户使用 LOB 数据类型替代 LONG 数据类型。用户可以对 LOB 列执行并行查询(不支持并行 DML 或 DDL)。
 
125 LOB datatypes differ from LONG and LONG RAW datatypes in several ways. For example:
  • A table can contain multiple LOB columns but only one LONG column.
  • A table containing one or more LOB columns can be partitioned, but a table containing a LONG column cannot be partitioned.
  • The maximum size of a LOB is 8 terabytes, and the maximum size of a LONG is only 2 gigabytes.
  • LOBs support random access to data, but LONGs support only sequential access.
  • LOB datatypes (except NCLOB) can be attributes of a user-defined object type but LONG datatypes cannot.
  • Temporary LOBs that act like local variables can be used to perform transformations on LOB data. Temporary internal LOBs (BLOBs, CLOBs, and NCLOBs) are created in a temporary tablespace and are independent of tables. For LONG datatypes, however, no temporary structures are available.
  • Tables with LOB columns can be replicated, but tables with LONG columns cannot.
LOB 数据类型与 LONGLONG RAW 数据类型的区别如下:
  • 一个数据表能够包含多个 LOB 列,但只能包含一个 LONG 列。
  • 包含一个或多个 LOB 列的数据表可以被分区,但包含 LONG 列的数据表无法被分区。
  • LOB 数据的最大容量为 8 TB,而 LONG 数据的最大容量为 2 GB。
  • Oracle 能够对 LOB 数据进行随机访问,但对 LONG 数据只能进行顺序访问。
  • LOB 数据类型(NCLOB 除外)可以作为用户定义对象类型的属性,而 LONG 数据类型不行。
  • 用户可以定义 LOB 类型的本地变量,用于执行 LOB 数据的转换。Oracle 可以在临时表空间中创建临时 LOB 对象(BLOBCLOB,及 NCLOB),这些对象独立存储,不与数据表相关。但是 Oracle 不提供与 LONG 数据类型对应的临时存储结构。
  • 包含 LOB 列的数据表可以被复制[replicate],但包含 LONG 列的数据表无法实现复制。
126 SQL statements define LOB columns in a table and LOB attributes in a user-defined object type. When defining LOBs in a table, you can explicitly specify the tablespace and storage characteristics for each LOB.
 
用户可以使用 SQL 语句定义表中的 LOB 列,以及用户定义对象类型中的 LOB 属性。在表中定义 LOB 列时,用户可以显式地设定每个 LOB 列使用的表空间及存储属性。
 
127 LOB datatypes can be stored inline (within a table), out-of-line (within a tablespace, using a LOB locator), or in an external file (BFILE datatypes). With compatibility set to Oracle9i or higher, you can use LOBs with SQL VARCHAR operators and functions.
 
LOB 数据类型可以采用内联存储[stored inline](即存储于表中),或外联存储[stored out-of-line](存储在表空间中,通过 LOB 定位器[LOB locator]定位),或存储于外部文件中(BFILE 数据类型)。如果将数据库的兼容性设置为 Oracle9i 或更高,用户可以使用 SQL 中 VARCHAR 数据类型的操作符及函数处理 LOB 数据。
 
128

See Also:

另见:

129

BLOB Datatype

26.5.1 BLOB 数据类型

130 The BLOB datatype stores unstructured binary data in the database. BLOBs can store up to 8 terabytes of binary data.
 
用户可以使用 BLOB 数据类型在数据库中存储非结构化二进制数据。BLOB 数据类型最大可存储 8 TB 二进制数据。
 
131 BLOBs participate fully in transactions. Changes made to a BLOB value by the DBMS_LOB package, PL/SQL, or the OCI can be committed or rolled back. However, BLOB locators cannot span transactions or sessions.
 
用户可以对 BLOB 数据类型进行完全的事务控制。通过 DBMS_LOB 包,PL/SQL,或 OCI 对 BLOB 数据的修改可以被提交或回滚。但是 BLOB 定位器不能跨事务或会话。
 
132

CLOB and NCLOB Datatypes

26.5.2 CLOB 及 NCLOB 数据类型

133 The CLOB and NCLOB datatypes store up to 8 terabytes of character data in the database. CLOBs store database character set data, and NCLOBs store Unicode national character set data. Storing varying-width LOB data in a fixed-width Unicode character set internally enables Oracle to provide efficient character-based random access on CLOBs and NCLOBs.
 
用户使用 CLOBNCLOB 数据类型可以在数据库中存储最大 8 TB 的字符数据。CLOB 数据采用数据库字符集编码,NCLOB 数据为 Unicode 的国家字符集编码。如果在 LOB 中存储数据时采用固定长度的 Unicode 字符集替代变长字符集,Oracle 能够对 CLOB  及 NCLOB 数据进行基于字符的高效的随机访问。
 
134 CLOBs and NCLOBs participate fully in transactions. Changes made to a CLOB or NCLOB value by the DBMS_LOB package, PL/SQL, or the OCI can be committed or rolled back. However, CLOB and NCLOB locators cannot span transactions or sessions. You cannot create an object type with NCLOB attributes, but you can specify NCLOB parameters in a method for an object type.
 
用户可以对 CLOBNCLOB 数据类型进行完全的事务控制。通过 DBMS_LOB 包,PL/SQL,或 OCI 对 CLOBNCLOB 数据的修改可以被提交或回滚。但是 CLOB NCLOB 定位器不能跨事务或会话。 用户创建的对象类型中不能包含 NCLOB 类型的属性,但可以在对象类型的方法中使用 NCLOB 类型的参数。
 
135
See Also:

Oracle Database Globalization Support Guide for more information about national character set data and Unicode
另见:

Oracle Database Globalization Support Guide 了解关于国家字符集数据及 Unicode 的信息
136

BFILE Datatype

26.5.3 BFILE 数据类型

137 The BFILE datatype stores unstructured binary data in operating-system files outside the database. A BFILE column or attribute stores a file locator that points to an external file containing the data. BFILEs can store up to 8 terabytes of data.
 
用户可以使用 BFILE 数据类型在数据库外的操作系统文件中存储二进制数据。数据类型为 BFILE 的列或属性中存储的为文件定位器[file locator],其指向包含实际数据的外部文件。BFILE 数据类型最大可存储 8 TB 数据。
 
138 BFILEs are read only; you cannot modify them. They support only random (not sequential) reads, and they do not participate in transactions. The underlying operating system must maintain the file integrity, security, and durability for BFILEs. The database administrator must ensure that the file exists and that Oracle processes have operating-system read permissions on the file.
 
BFILE 数据是只读的,用户不能对其修改。BFILE 数据只支持随机读取(不支持顺序读取),且不支持事务控制。底层操作系统必须负责确保 BFILE 文件的完整性,安全性,及持久性[durability]。数据库管理员应确保所有 BFILE 文件存在,且 Oracle 进程具有读取 BFILE 文件的操作系统权限。
 
139

Overview of RAW and LONG RAW Datatypes

26.6 RAW 及 LONG RAW 数据类型概述

140
Note:

The LONG RAW datatype is provided for backward compatibility with existing applications. For new applications, use the BLOB and BFILE datatypes for large amounts of binary data.

Oracle also recommends that you convert existing LONG RAW columns to LOB columns. LOB columns are subject to far fewer restrictions than LONG columns. Further, LOB functionality is enhanced in every release, whereas LONG RAW functionality has been static for several releases.
提示:

LONG RAW 数据类型的作用是为已有应用程序提供向后兼容能力。在新开发的应用程序中应使用 BLOBBFILE 数据类型存储大型二进制数据。

Oracle 还建议用户将 LONG RAW 数据类型的列转换为 LOB 类型。LOB 列所受的限制远少于 LONG 列。此外,Oracle 每个发行版本都对 LOB 功能进行了增强,而与 LONG RAW 有关的功能将不再更新。
141 The RAW and LONG RAW datatypes are used for data that is not to be interpreted (not converted when moving data between different systems) by Oracle. These datatypes are intended for binary data or byte strings. For example, LONG RAW can be used to store graphics, sound, documents, or arrays of binary data. The interpretation depends on the use.
 
RAWLONG RAW 数据类型用于存储不应由 Oracle 进行解释的数据(即在不同系统间迁移数据时不应被转换的数据)。这两种数据类型可以存储二进制数据及字节字符串[byte string]。例如,LONG RAW 数据类型可以存储图形,声音,文档,或二进制数据数组。
142 RAW is a variable-length datatype like the VARCHAR2 character datatype, except Oracle Net Services (which connects user sessions to the instance) and the Import and Export utilities do not perform character conversion when transmitting RAW or LONG RAW data. In contrast, Oracle Net Services and Import/Export automatically convert CHAR, VARCHAR2, and LONG data between the database character set and the user session character set, if the two character sets are different.
 
RAW 是一种与 VARCHAR2 字符数据类型类似的变长数据类型,但 Oracle Net Services(其功能为连接用户会话与实例)及 Import/Export 工具在处理 RAW LONG RAW 数据时不进行字符转换。与之相反,如果用户会话字符集与数据库字符集不同,Oracle Net Services 及 Import/Export 工具将对 CHARVARCHAR2,及 LONG 类型的数据执行自动转换。
 
143 When Oracle automatically converts RAW or LONG RAW data to and from CHAR data, the binary data is represented in hexadecimal form with one hexadecimal character representing every four bits of RAW data. For example, one byte of RAW data with bits 11001011 is displayed and entered as 'CB'.
 
当 Oracle 自动地在 RAWLONG RAW 数据与 CHAR 数据间进行转换时,二进制数据以十六进制形式表现,一个十六进字符代表 RAW 数据中的 4 位。例如,1 字节 RAW 数据的各位为 11001011,将被显示为‘CB’。
 
144 LONG RAW data cannot be indexed, but RAW data can be indexed.
 
LONG RAW 数据不能被索引,但 RAW 数据可以被索引。
 
145
See Also:

Oracle Database Application Developer's Guide - Fundamentals for information about other restrictions on the LONG RAW datatype
另见:

Oracle Database Application Developer's Guide - Fundamentals 了解 LONG RAW 数据类型的其他限制
146

Overview of ROWID and UROWID Datatypes

26.7 ROWID 及 UROWID 数据类型概述

147 Oracle uses a ROWID datatype to store the address (rowid) of every row in the database.
  • Physical rowids store the addresses of rows in ordinary tables (excluding index-organized tables), clustered tables, table partitions and subpartitions, indexes, and index partitions and subpartitions.
  • Logical rowids store the addresses of rows in index-organized tables.
Oracle 使用 ROWID 数据类型存储每个数据行在数据库中的地址(rowid)。
  • 物理 rowid[physical rowid]:用于存储常规表[ordinary table](即索引表[index-organized table]之外的数据表),簇表[clustered table],表分区及子分区,索引,索引分区及子分区数据行的地址。
  • 逻辑 rowid[logical rowid]:用于存储索引表数据行的地址。
148 A single datatype called the universal rowid, or UROWID, supports both logical and physical rowids, as well as rowids of foreign tables such as non-Oracle tables accessed through a gateway.
 
UROWID 数据类型,也被称为通用数据类型[universal rowid],同时支持物理 rowid 和逻辑 rowid,也支持外表[foreign table](例如通过网关访问的非 Oracle 数据表)的 rowid。
 
149 A column of the UROWID datatype can store all kinds of rowids. The value of the COMPATIBLE initialization parameter (for file format compatibility) must be set to 8.1 or higher to use UROWID columns.
 
数据类型为 UROWID 的列可以存储各类 rowid。(用于设定文件格式兼容性的)COMPATIBLE 初始化参数的值必须设为 8.1 或更高才能使用 UROWID 数据类型。
 
150
See Also:

"Rowids in Non-Oracle Databases"
另见:

非 Oracle 数据库的 rowid
151

The ROWID Pseudocolumn

26.7.1 ROWID 虚列

152 Each table in an Oracle database internally has a pseudocolumn named ROWID. This pseudocolumn is not evident when listing the structure of a table by executing a SELECT * FROM ... statement, or a DESCRIBE ... statement using SQL*Plus, nor does the pseudocolumn take up space in the table. However, each row's address can be retrieved with a SQL query using the reserved word ROWID as a column name, for example:
 
Oracle 数据库的每张数据表都包含一个名为 ROWID虚列[pseudocolumn]。使用 SQL*Plus 执行 SELECT * FROM 语句或 DESCRIBE 语句时此列不会被显示,此列也不占用数据表的存储空间。但在 SQL 查询中使用保留字 ROWID 作为列名可以获得数据行的地址,例如:
 
153
SELECT ROWID, last_name FROM employees;
SELECT ROWID, last_name FROM employees;
154 You cannot set the value of the pseudocolumn ROWID in INSERT or UPDATE statements, and you cannot delete a ROWID value. Oracle uses the ROWID values in the pseudocolumn ROWID internally for the construction of indexes.
 
用户不能使用 INSERTUPDATE 语句设置 ROWID 虚列的值,同时也不能删除 ROWID 值。Oracle 使用 ROWID 虚列中的 ROWID 值构建索引。
 
155 You can reference rowids in the pseudocolumn ROWID like other table columns (used in SELECT lists and WHERE clauses), but rowids are not stored in the database, nor are they database data. However, you can create tables that contain columns having the ROWID datatype, although Oracle does not guarantee that the values of such columns are valid rowids. The user must ensure that the data stored in the ROWID column truly is a valid ROWID.
 
用户可以像使用其他数据列一样使用 ROWID 虚列中的 rowid 值(在 SELECT 列表和 WHERE 子句中使用),但 rowid 不存储于数据库中,也不是数据库数据。用户创建数据表时可以包含数据类型为 ROWID 的数据列,不过 Oracle 不保证其中的列值为有效的 rowid。用户必须确保存储于 ROWID 列的数据为真实有效的 ROWID
 
156
See Also:

"How Rowids Are Used"
另见:

如何使用 rowid
157

Physical Rowids

26.7.2 物理 rowid

158 Physical rowids provide the fastest possible access to a row of a given table. They contain the physical address of a row (down to the specific block) and allow you to retrieve the row in a single block access. Oracle guarantees that as long as the row exists, its rowid does not change. These performance and stability qualities make rowids useful for applications that select a set of rows, perform some operations on them, and then access some of the selected rows again, perhaps with the purpose of updating them.
 
通过物理 rowid[physical rowid]可以以最快的速度访问表的数据行。物理 rowid 包含了数据行的物理地址(可定位到数据行所在的数据块内部),用户只需访问个别数据块就可以获取数据行。Oracle 能够保证只要数据行存在,其 rowid 就不会改变。由于 rowid 具有稳定且查询性能高的特点,如果应用程序需要选择一个数据行集并对其执行某种操作,之后需要再次访问其中的某些数据行(例如进行更新操作),就可以考虑 利用 rowid。
 
159 Every row in a nonclustered table is assigned a unique rowid that corresponds to the physical address of a row's row piece (or the initial row piece if the row is chained among multiple row pieces). In the case of clustered tables, rows in different tables that are in the same data block can have the same rowid.
 
非簇表[nonclustered table]中的每个数据行都有一个唯一的 rowid,对应此行的行片断[row piece]的物理地址(如果数据行由多个行片链接而成,则 rowid 对应首个行片断的物理地址)。对于簇表,位于同一数据块内不同表的数据行可能拥有相同的 rowid。
 
160 A row's assigned rowid remains unchanged unless the row is exported and imported using the Import and Export utilities. When you delete a row from a table and then commit the encompassing transaction, the deleted row's associated rowid can be assigned to a row inserted in a subsequent transaction.
 
Rowid 赋予数据行后将保持不变,直到使用 Import/Export 工具执行了导入/导出操作。当用户提交了包含删除数据行操作的事务后,被删除数据行的 rowid 有可能被后续事务中插入的新数据行使用。
 
161 A physical rowid datatype has one of two formats:
  • The extended rowid format supports tablespace-relative data block addresses and efficiently identifies rows in partitioned tables and indexes as well as nonpartitioned tables and indexes. Tables and indexes created by an Oracle8i (or higher) server always have extended rowids.
  • A restricted rowid format is also available for backward compatibility with applications developed with Oracle database version 7 or earlier releases.
物理 rowid 数据类型有两种格式:
  • 扩展 rowid[extended rowid]格式支持与表空间相关的数据块地址,能够高效地定位分区表及分区索引中的数据行,同样也能用于对非分区表及非分区索引进行高效地检索。在 Oracle8i(或更高版本)数据库中创建的表及索引均使用扩展 rowid。
  • 受限 rowid[restricted rowid]格式的作用是为 Oracle 7 或更早版本的数据库应用程序提供向后兼容能力。
162

Extended Rowids

26.7.2.1 扩展 rowid

163 Extended rowids use a base 64 encoding of the physical address for each row selected. The encoding characters are A-Z, a-z, 0-9, +, and /. For example, the following query:
 
扩展 rowid[extended rowid]使用 64 位对每个数据行的物理地址进行编码。编码字符为 A-Za-z0-9+,和 /。例如,以下查询:
 
164
SELECT ROWID, last_name FROM employees WHERE department_id = 20;
SELECT ROWID, last_name FROM employees WHERE department_id = 20;
165 can return the following row information:
 
能够返回如下信息:
 
166
ROWID              LAST_NAME
------------------ ----------
AAAAaoAATAAABrXAAA BORTINS
AAAAaoAATAAABrXAAE RUGGLES
AAAAaoAATAAABrXAAG CHEN
AAAAaoAATAAABrXAAN BLUMBERG
ROWID              LAST_NAME
------------------ ----------
AAAAaoAATAAABrXAAA BORTINS
AAAAaoAATAAABrXAAE RUGGLES
AAAAaoAATAAABrXAAG CHEN
AAAAaoAATAAABrXAAN BLUMBERG
167 An extended rowid has a four-piece format, OOOOOOFFFBBBBBBRRR:
  • OOOOOO: The data object number that identifies the database segment (AAAAao in the example). Schema objects in the same segment, such as a cluster of tables, have the same data object number.
  • FFF: The tablespace-relative datafile number of the datafile that contains the row (file AAT in the example).
  • BBBBBB: The data block that contains the row (block AAABrX in the example). Block numbers are relative to their datafile, not tablespace. Therefore, two rows with identical block numbers could reside in two different datafiles of the same tablespace.
  • RRR: The row in the block.
扩展 rowid 的格式可分为 4 段,OOOOOOFFFBBBBBBRRR
  • OOOOOO数据对象编号[data object number]用于确定数据库段[database segment](示例中为 AAAAao)。位于相同数据段中的方案对象 (例如簇中的数据表)具有相同的数据对象编号。
  • FFF:与表空间相关的数据文件编号[datafile number],代表包含此行的数据文件(示例中为 AAT)。
  • BBBBBB:包含数据行的数据块[data block](示例中为 AAABrX)。数据块编号与其所在的数据文件相关,而与表空间相关。因此两个具备相同数据块编号的数据行可能存在于同一个表空间的不同数据文件中。
  • RRR: 数据块中的数据行[row]。
168 You can retrieve the data object number from data dictionary views USER_OBJECTS, DBA_OBJECTS, and ALL_OBJECTS. For example, the following query returns the data object number for the employees table in the SCOTT schema:
 
用户可以从数据字典视图 USER_OBJECTSDBA_OBJECTS,或 ALL_OBJECTS 中获取数据库对象的数据对象编号。例如,以下查询将返回 SCOTT 方案中的 employees 表的数据对象编号:
 
169
SELECT DATA_OBJECT_ID FROM DBA_OBJECTS
WHERE OWNER = 'SCOTT' AND OBJECT_NAME = 'EMPLOYEES';
SELECT DATA_OBJECT_ID FROM DBA_OBJECTS
WHERE OWNER = 'SCOTT' AND OBJECT_NAME = 'EMPLOYEES';
170 You can also use the DBMS_ROWID package to extract information from an extended rowid or to convert a rowid from extended format to restricted format (or vice versa).
 
用户可以使用 DBMS_ROWID 包通过扩展 rowid 获取数据库对象信息,或在扩展格式及受限格式间转换 rowid。
 
171
See Also:

Oracle Database Application Developer's Guide - Fundamentals for information about the DBMS_ROWID package
另见:

Oracle Database Application Developer's Guide - Fundamentals 了解关于 DBMS_ROWID 包的信息
172

Restricted Rowids

26.7.2.2 受限 rowid

173 Restricted rowids use a binary representation of the physical address for each row selected. When queried using SQL*Plus, the binary representation is converted to a VARCHAR2/hexadecimal representation. The following query:
 
受限 rowid[restricted rowid]采用二进制形式表现每个数据行的物理地址。在 SQL*Plus 中进行查询时,二进制的受限 rowid 将被转换为 VARCHAR2 类型的十六进制形式。以下查询:
 
174
SELECT ROWID, last_name FROM employees
WHERE department_id = 30;
SELECT ROWID, last_name FROM employees
WHERE department_id = 30;
175 can return the following row information:
 
能够返回如下信息:
 
176
ROWID              ENAME
------------------ ----------
00000DD5.0000.0001 KRISHNAN
00000DD5.0001.0001 ARBUCKLE
00000DD5.0002.0001 NGUYEN
ROWID              ENAME
------------------ ----------
00000DD5.0000.0001 KRISHNAN
00000DD5.0001.0001 ARBUCKLE
00000DD5.0002.0001 NGUYEN
177 As shown, a restricted rowid's VARCHAR2/hexadecimal representation is in a three-piece format, block.row.file:
  • The data block that contains the row (block DD5 in the example). Block numbers are relative to their datafile, not tablespace. Two rows with identical block numbers could reside in two different datafiles of the same tablespace.
  • The row in the block that contains the row (rows 0, 1, 2 in the example). Row numbers of a given block always start with 0.
  • The datafile that contains the row (file 1 in the example). The first datafile of every database is always 1, and file numbers are unique within a database.
受限 rowid 的 VARCHAR2 类型的十六进制表现形式可以分为 3 段,块.行.文件[block.row.file]:
  • 包含数据行的数据块[data block](示例中为 DD5)。数据块编号与其所在的数据文件相关,而与表空间相关。因此两个具备相同数据块编号的数据行可能存在于同一个表空间的不同数据文件中。
  • 数据行[row]在数据块中的位置(示例中各行分别为 0,1,2)。数据块内的行号总是从 0 开始。
  • 数据行所在的数据文件[datafile](示例中的文件号为 1)。数据库内的数据文件编号总是从 1 开始,数据文件编号在一个数据库内唯一。
178

Examples of Rowid Use

26.7.2.3 使用 rowid 的例子

179 You can use the function SUBSTR to break the data in a rowid into its components. For example, you can use SUBSTR to break an extended rowid into its four components (database object, file, block, and row):
 
用户可以使用 SUBSTR 函数分解 rowid 数据。例如,用户可以使用 SUBSTR 函数将扩展 rowid[extended rowid]分解为以下四部分(数据库对象,数据文件,数据块,与数据行):
 
180
SELECT ROWID,
SUBSTR(ROWID,1,6) "OBJECT",
SUBSTR(ROWID,7,3) "FIL",
SUBSTR(ROWID,10,6) "BLOCK",
SUBSTR(ROWID,16,3) "ROW"
FROM products;
SELECT ROWID,
SUBSTR(ROWID,1,6) "OBJECT",
SUBSTR(ROWID,7,3) "FIL",
SUBSTR(ROWID,10,6) "BLOCK",
SUBSTR(ROWID,16,3) "ROW"
FROM products;
181
ROWID              OBJECT FIL BLOCK  ROW
------------------ ------ --- ------ ----
AAAA8mAALAAAAQkAAA AAAA8m AAL AAAAQk AAA
AAAA8mAALAAAAQkAAF AAAA8m AAL AAAAQk AAF
AAAA8mAALAAAAQkAAI AAAA8m AAL AAAAQk AAI
ROWID              OBJECT FIL BLOCK  ROW
------------------ ------ --- ------ ----
AAAA8mAALAAAAQkAAA AAAA8m AAL AAAAQk AAA
AAAA8mAALAAAAQkAAF AAAA8m AAL AAAAQk AAF
AAAA8mAALAAAAQkAAI AAAA8m AAL AAAAQk AAI
182 Or you can use SUBSTR to break a restricted rowid into its three components (block, row, and file):
 
用户也可以使用 SUBSTR 函数将受限 rowid[restricted rowid]分解为以下三部分(数据块,数据行,与数据文件):
 
183
SELECT ROWID, SUBSTR(ROWID,15,4) "FILE",
SUBSTR(ROWID,1,8) "BLOCK",
SUBSTR(ROWID,10,4) "ROW"
FROM products;
SELECT ROWID, SUBSTR(ROWID,15,4) "FILE",
SUBSTR(ROWID,1,8) "BLOCK",
SUBSTR(ROWID,10,4) "ROW"
FROM products;
184
ROWID              FILE BLOCK    ROW
------------------ ---- -------- ----
00000DD5.0000.0001 0001 00000DD5 0000
00000DD5.0001.0001 0001 00000DD5 0001
00000DD5.0002.0001 0001 00000DD5 0002
ROWID              FILE BLOCK    ROW
------------------ ---- -------- ----
00000DD5.0000.0001 0001 00000DD5 0000
00000DD5.0001.0001 0001 00000DD5 0001
00000DD5.0002.0001 0001 00000DD5 0002
185 Rowids can be useful for revealing information about the physical storage of a table's data. For example, if you are interested in the physical location of a table's rows (such as for table striping), the following query of an extended rowid tells how many datafiles contain rows of a given table:
 
用户可以通过 rowid 数据获得表数据的物理存储信息。例如,如果用户需要了解表数据的物理分布情况(例如条带化表[table striping]),以下查询能够分析扩展 rowid 从而找出表数据存储于几个数据文件中:
 
186
SELECT COUNT(DISTINCT(SUBSTR(ROWID,7,3))) "FILES" FROM tablename;
SELECT COUNT(DISTINCT(SUBSTR(ROWID,7,3))) "FILES" FROM tablename;
187
  FILES
--------
    2
  FILES
--------
    2
188

See Also:

for more examples using rowids

另见:

查看使用 rowid 的例子
189

How Rowids Are Used

26.7.2.4 如何使用 rowid

190 Oracle uses rowids internally for the construction of indexes. Each key in an index is associated with a rowid that points to the associated row's address for fast access. End users and application developers can also use rowids for several important functions:
  • Rowids are the fastest means of accessing particular rows.
  • Rowids can be used to see how a table is organized.
  • Rowids are unique identifiers for rows in a given table.
Oracle 使用 rowid 构建索引。索引中的每个键值都与一个 rowid 相关,此 rowid 为相关数据行的地址,因此通过索引能够实现对数据行的快速访问。用户及应用程序开发者也可以使用 rowid 实现一些重要功能:
  • 通过 rowid 是访问特定数据行的最快的方法。
  • 通过 rowid 可以了解数据表是如何组织的。
  • rowid 是数据表内各数据行的唯一标识。
191 Before you use rowids in DML statements, they should be verified and guaranteed not to change. The intended rows should be locked so they cannot be deleted. Under some circumstances, requesting data with an invalid rowid could cause a statement to fail.
 
在 DML 语句中使用 rowid 之前,用户必须确定 rowid 是有效的且保证不会改变。用户应该为将要被操作的数据行加锁,以防止其被删除。在某些情况下,包含无效 rowid 的数据处理请求可能导致语句失败。
 
192 You can also create tables with columns defined using the ROWID datatype. For example, you can define an exception table with a column of datatype ROWID to store the rowids of rows in the database that violate integrity constraints. Columns defined using the ROWID datatype behave like other table columns: values can be updated, and so on. Each value in a column defined as datatype ROWID requires six bytes to store pertinent column data.
 
用户在创建数据表时可以定义数据类型为 ROWID 的数据列。例如,用户在创建存储异常数据的数据表时,可以定义数据类型为 ROWID 的数据列,以存储数据库中违反完整性约束的数据行的 rowid。数据类型为 ROWID 的数据列与其他常规的数据列相同:例如数据值可以被更新,等等。数据类型为 ROWID 的数据列需要使用 6 字节的存储空间。
 
193

Logical Rowids

26.7.3 逻辑 rowid

194 Rows in index-organized tables do not have permanent physical addresses—they are stored in the index leaves and can move within the block or to a different block as a result of insertions. Therefore their row identifiers cannot be based on physical addresses. Instead, Oracle provides index-organized tables with logical row identifiers, called logical rowids, that are based on the table's primary key. Oracle uses these logical rowids for the construction of secondary indexes on index-organized tables.
 
索引表[index-organized table]内的数据行没有固定的物理地址,索引表中的数据行被存储于索引的叶子节点上,已有数据行有可能随着新数据的插入而在同一数据块内或不同数据块间移动。因此索引表数据行不能使用物理地址作为其标识。Oracle 处理索引表时使用被称为逻辑 rowid[logical rowid]的逻辑行标识,逻辑 rowid 基于索引表的主键。Oracle 使用逻辑 rowid 为索引表构建辅助索引[secondary index]。
 
195 Each logical rowid used in a secondary index includes a physical guess, which identifies the block location of the row in the index-organized table at the time the guess was made; that is, when the secondary index was created or rebuilt.
 
辅助索引所使用的逻辑 rowid 中还包含物理猜测[physical guess]信息,此信息表示猜测发生时,索引表内对应数据行在数据块中的位置。所谓猜测发生时,即辅助索引创建或重建时。
 
196 Oracle can use guesses to probe into the leaf block directly, bypassing the full key search. This ensures that rowid access of nonvolatile index-organized tables gives comparable performance to the physical rowid access of ordinary tables. In a volatile table, however, if the guess becomes stale the probe can fail, in which case a primary key search must be performed.
 
Oracle 可以根据猜测信息直接探测叶子数据块,从而跳过索引完全扫描。因此,通过逻辑 rowid 访问物理存储固定的[nonvolatile]索引表的性能与通过物理 rowid 访问常规表的性能相接近。但是对于物理存储不固定的[volatile]的索引表来说,如果猜测信息失效则探测将失败,此时 Oracle 必须执行主键扫描。
 
197 The values of two logical rowids are considered equal if they have the same primary key values but different guesses.
 
如果两个逻辑 rowid 值基于相同的主键值,但具有不同的物理猜测信息,这两个逻辑 rowid 值依然被视为是相同的。
 
198

Comparison of Logical Rowids with Physical Rowids

26.7.3.1 逻辑 rowid 与物理 rowid 的比较

199 Logical rowids are similar to the physical rowids in the following ways:
  • Logical rowids are accessible through the ROWID pseudocolumn.

    You can use the ROWID pseudocolumn to select logical rowids from an index-organized table. The SELECT ROWID statement returns an opaque structure, which internally consists of the table's primary key and the physical guess (if any) for the row, along with some control information.

    You can access a row using predicates of the form WHERE ROWID = value, where value is the opaque structure returned by SELECT ROWID.
  • Access through the logical rowid is the fastest way to get to a specific row, although it can require more than one block access.
  • A row's logical rowid does not change as long as the primary key value does not change. This is less stable than the physical rowid, which stays immutable through all updates to the row.
  • Logical rowids can be stored in a column of the UROWID datatype.
逻辑 rowid 与物理 rowid 具有以下相似之处:
  • 用户可以通过 ROWID 虚列访问逻辑 rowid。

    用户可以通过 ROWID 虚列查询索引表中的逻辑 rowid。执行 SELECT ROWID 语句将返回不透明[opaque]数据结构,其内容由索引表的主键,数据行的物理猜测信息(如果猜测信息存在),及一些控制信息组成。

    用户可以按 WHERE ROWID = value 的形式编辑谓词,以根据逻辑 rowid 访问索引表的数据行。谓词的 valueSELECT ROWID 语句所返回的不透明数据结构。
  • 通过逻辑 rowid 是检索特定数据行的最快方法,检索过程有可能访问多个数据块。
  • 只要索引表的主键值不发生变化,其中数据行的逻辑 rowid 就不会变化。逻辑 rowid 不如物理 rowid 稳定,对数据行执行更新操作后者也不会发生变化。
  • 逻辑 rowid 可以存储在数据类型为 UROWID 的数据列中。
200 One difference between physical and logical rowids is that logical rowids cannot be used to see how a table is organized.
 
逻辑 rowid 与物理 rowid 的一个不同点在于,通过逻辑 rowid 无法了解数据表是如何组织的。
 
201
Note:

An opaque type is one whose internal structure is not known to the database. The database provides storage for the type. The type designer can provide access to the contents of the type by implementing functions, typically 3GL routines.
提示:

不透明类型[opaque type]的内部结构对数据库来说是未知的。数据库为此种类型提供存储。而不透明类型的设计者需要实现函数(通常采用第三代语言编写)供数据库访问类型中的数据。
202
See Also:

"Overview of ROWID and UROWID Datatypes"
另见:

ROWID 及 UROWID 数据类型概述
203

Guesses in Logical Rowids

26.7.3.2 逻辑 rowid 猜测

204 When a row's physical location changes, the logical rowid remains valid even if it contains a guess, although the guess could become stale and slow down access to the row. Guess information cannot be updated dynamically. For secondary indexes on index-organized tables, however, you can rebuild the index to obtain fresh guesses. Note that rebuilding a secondary index on an index-organized table involves reading the base table, unlike rebuilding an index on an ordinary table.
 
在数据行的物理位置发生变化后,其逻辑 rowid 依然是有效的,即使逻辑 rowid 中包含物理猜测信息,但此时物理猜测信息有可能失效,并导致数据行的访问速度下降。物理猜测信息无法被动态更新。但是用户可以通过重建索引表的辅助索引来更新其中的物理猜测信息。注意,重建索引表的辅助索引时需要读取基表,这与重建常规表的索引有所不同。
 
205 Collect index statistics with the DBMS_STATS package or ANALYZE statement to keep track of the staleness of guesses, so Oracle does not use them unnecessarily. This is particularly important for applications that store rowids with guesses persistently in a UROWID column, then retrieve the rowids later and use them to fetch rows.
 
用户可以使用 DBMS_STATS 包或 ANALYZE 语句收集索引统计信息,并刷新失效的物理猜测信息,Oracle 不会自动地执行此类操作。对于在数据类型为 UROWID 的列中存储逻辑 rowid 及物理猜测信息并通过此数据获取数据行的应用程序来说,上述操作尤为重要。
 
206 When you collect index statistics with the DBMS_STATS package or ANALYZE statement, Oracle checks whether the existing guesses are still valid and records the percentage of stale/valid guesses in the data dictionary. After you rebuild a secondary index (recomputing the guesses), collect index statistics again.
 
当用户使用 DBMS_STATS 包或 ANALYZE 语句收集索引统计信息时,Oracle 将记录相关的物理猜测信息是否有效,并在数据字典中记录失效信息与有效信息的比例。当用户重建索引表的辅助索引(即重新获取物理猜测信息)后,需要再次收集索引统计信息。
 
207 In general, logical rowids without guesses provide the fastest possible access for a highly volatile table. If a table is static or if the time between getting a rowid and using it is sufficiently short to make row movement unlikely, logical rowids with guesses provide the fastest access.
 
一般来说,对于存储高度不固定的[volatile]的索引表,使用逻辑 rowid 且不参考物理猜测信息是访问数据的最快方法。如果表数据固定,或获取逻辑 rowid 与使用逻辑 rowid 的时间间隔较短(不可能发生行移动[row movement]),使用逻辑 rowid 且参考物理猜测信息是访问数据的最快方法。
 
208
See Also:

Oracle Database Performance Tuning Guide for more information about collecting statistics
另见:

Oracle Database Performance Tuning Guide 了解关于收集统计数据的信息
209

Rowids in Non-Oracle Databases

26.7.4 非 Oracle 数据库的 rowid

210 Oracle database applications can be run against non-Oracle database servers using SQL*Connect. The format of rowids varies according to the characteristics of the non-Oracle system. Furthermore, no standard translation to VARCHAR2/hexadecimal format is available. Programs can still use the ROWID datatype. However, they must use a nonstandard translation to hexadecimal format of length up to 256 bytes.
 
Oracle 数据库应用程序可以通过 SQL*Connect 运行在非 Oracle 数据库服务器上。此时 rowid 数据的格式与非 Oracle 数据库的特性有关。此外,Oracle 不提供标准的 VARCHAR2/hexadecimal 格式转换。应用程序仍旧可以使用 ROWID 数据类型。但应用程必须采用非标准的方式将 rowid 转换为 256 字节长的十六进制格式。
 
211 Rowids of a non-Oracle database can be stored in a column of the UROWID datatype.
 
非 Oracle 数据库的 rowid 可以存储在数据类型为 UROWID 的数据列中。
 
212

See Also:

另见:

213

Overview of ANSI, DB2, and SQL/DS Datatypes

26.8 ANSI,DB2,及 SQL/DS 数据类型概述

214 SQL statements that create tables and clusters can also use ANSI datatypes and datatypes from IBM's products SQL/DS and DB2. Oracle recognizes the ANSI or IBM datatype name that differs from the Oracle datatype name, records it as the name of the datatype of the column, and then stores the column's data in an Oracle datatype based on the conversions.
 
在 Oracle 中使用 SQL 语句创建表及簇表时,可以定义 ANSI 数据类型的列,或定义 IBM 的 SQL/DS 及 DB2 等产品使用的数据类型的列。Oracle 能够识别出 ANSI 或 IBM 数据类型中与 Oracle 数据类型名称不同的类型,将此名称作为新定义数据列的数据类型名称,并将输入数据转换为 Oracle 数据类型进行存储。
 
215
See Also:

Oracle Database SQL Reference for more information about the conversions
另见:

Oracle Database SQL Reference 了解关于数据转换的信息
216

Overview of XML Datatypes

26.9 XML 数据类型概述

217 Oracle provides the XMLType datatype to handle XML data.
 
Oracle 提供了 XMLType 数据类型供用户处理 XML 数据。
 
218

XMLType Datatype

26.9.1 XMLType 数据类型

219 XMLType can be used like any other user-defined type. XMLType can be used as the datatype of columns in tables and views. Variables of XMLType can be used in PL/SQL stored procedures as parameters, return values, and so on. You can also use XMLType in PL/SQL, SQL and Java, and through JDBC and OCI.
 
XMLType 数据类型的用法与用户定义类型相似。XMLType 数据类型可以用于定义表或视图的列。在 PL/SQL 中可以定义 XMLType 数据类型的变量作为存储过程的参数,返回值,等等。用户还可以在 PL/SQL,SQL 与 Java,及 JDBC 和 OCI 中使用 XMLType 数据类型。
 
220 A number of useful functions that operate on XML content have been provided. Many of these are provided both as SQL functions and as member functions of XMLType. For example, function extract extracts a specific node(s) from an XMLType instance. You can use XMLType in SQL queries in the same way as any other user-defined datatypes in the system.
 
Oracle 提供了大量操作 XML 内容的功能。这些功能以 SQL 函数或 XMLType 类型的成员函数的形式提供。例如,extract 函数能够从 XMLType 实例中获取特定的节点[node]。用户可以在 SQL 查询中使用 XMLType 类型,使用方式与其他用户定义数据类型相似。
 
221

See Also:

另见:

222

Overview of URI Datatypes

26.10 URI 数据类型概述

223 A URI, or uniform resource identifier, is a generalized kind of URL. Like a URL, it can reference any document, and can reference a specific part of a document. It is more general than a URL because it has a powerful mechanism for specifying the relevant part of the document. By using UriType, you can do the following:
  • Create table columns that point to data inside or outside the database.
  • Query the database columns using functions provided by UriType.
统一资源标识符[uniform resource identifier,URI]是一种一般化[generalized]的 URL。与 URL 类似,URI 能够引用任何文档,或引用文档中的特定部分。URI 比 URL 更为一般化,因为 URI 提供了功能强大的文档引用机制。通过 UriType 数据类型,用户可以完成以下工作:
  • 创建数据列,指向数据库内部或外部的数据。
  • 通过 UriType 类型提供的函数查询数据库列。
224
See Also:

Oracle XML DB Developer's Guide
另见:

Oracle XML DB Developer's Guide
225

Overview of Data Conversion

26.11 数据转换概述

226 In some cases, Oracle supplies data of one datatype where it expects data of a different datatype. This is allowed when Oracle can automatically convert the data to the expected datatype.
 
在某些情况下,Oracle 提供的数据与使用者预期的数据类型不符。如果 Oracle 能够自动地将数据转换为预期的数据类型,则上述情况不会带来任何问题。
 
227
See Also:

Oracle Database SQL Reference for the rules for implicit datatype conversions
另见:

Oracle Database SQL Reference 了解隐式数据类型转换的规则

A 翻译不确定的词汇[格式:黄色背景 ]  

 

B 翻译不确定的Oracle/数据库词汇[格式:
黄色背景 ]

[163] base 64 encoding
[199] opaque structure

C 翻译不确定的句子[格式:
黄色背景 ]

[091] (after midnight)
[101] Julian dates can be calculated and interpreted differently.
[108] For example, the switch from the Julian to the Gregorian calendar, 15-10-1582, eliminated the previous 10 days (05-10-1582 through 14-10-1582).
[131] However, BLOB locators cannot span transactions or sessions.
[134] However, CLOB and NCLOB locators cannot span transactions or sessions.
[205] Collect index statistics with the DBMS_STATS package or ANALYZE statement to keep track of the staleness of guesses, so Oracle does not use them unnecessarily.
[210] Oracle database applications can be run against non-Oracle database servers using SQL*Connect. The format of rowids varies according to the characteristics of the non-Oracle system. Furthermore, no standard translation to VARCHAR2/hexadecimal format is available. Programs can still use the ROWID datatype. However, they must use a nonstandard translation to hexadecimal format of length up to 256 bytes.
[223] It is more general than a URL because it has a powerful mechanism for specifying the relevant part of the document.
[226] In some cases, Oracle supplies data of one datatype where it expects data of a different datatype. This is allowed when Oracle can automatically convert the data to the expected datatype.

D 注释性的文字[格式:
[绿色]]

 

E 未完成的链接


 

F Oracle学习问题[格式:
黄色背景]
1、什么意思?
[197] The values of two logical rowids are considered equal if they have the same primary key values but different guesses.

2、什么意思?
[204] Note that rebuilding a secondary index on an index-organized table involves reading the base table, unlike rebuilding an index on an ordinary table.

I 相关链接

[108] Gregorian calendar 1582
http://en.wikipedia.org/wiki/Gregorian_calendar

translator: zw1840@hotmail.com