码迷,mamicode.com
首页 > 数据库 > 详细

Oracle Schema Objects——Tables——Oracle Data Types

时间:2017-06-22 13:20:22      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:rowid   site   sim   列表   sel   日期时间   cin   different   例子   

Character Data Types

字符数据类型

      • Character data types store character (alphanumeric) data in strings.

字符数据类型存储在字符串中的字符 (字母或数字) 数据

 

      • The most commonly used character data type is VARCHAR2, which is the most efficient option for storing character data.

最常用的字符数据类型是 VARCHAR2,它是用于存储字符数据的最有效的选项

 

      • The byte values correspond to the character encoding scheme, generally called a character set or code page. The database character set is established at database creation.

与字符编码模式相对应的字节值,一般称为 字符集代码页。 数据库字符集是在数据库创建时建立的。

 

      •  Examples of character sets are 7-bit ASCII, EBCDIC, and Unicode UTF-8.

字符集的例子有 7 ASCII 码、 EBCDIC码、和 Unicode utf-8

 

      • The length semantics of character data types can be measured in bytes or characters.

字符数据类型的长度语义可以以字节或字符为单位。

 

      •  Byte semantics treat strings as a sequence of bytes. This is the default for character data types.

字节语义将字符串视为一个字节序列。 这是字符数据类型的默认值。

 

      • Character semantics treat strings as a sequence of characters. A character is technically a code point of the database character set.

字符语义将字符串视为字符序列。 一个字符在技术上是数据库字符集的编码点。

 

VARCHAR2 CHAR NCHARNVARCHAR2

 

Oracle Database compares VARCHAR2 values using nonpadded comparison semantics and compares CHAR values using blank-padded comparison semantics.

Oracle 数据库将使用非填充比较语义来比较 VARCHAR2 值,而使用空白填充比较语义来比较 CHAR 值。

VARCHAR2  

CHAR

The VARCHAR2 data type stores variable-length character literals.

VARCHAR2 数据类型存储变长字符文本

The terms literal and constant value are synonymous and refer to a fixed data value.

文本常量值这两个术语是同义词,指的是一个固定的数据值

CHAR stores fixed-length character strings.

CHAR 存储固定长度的字符串

 VARCHAR2(25):表示该列中存储的名字最多可以长达25个字节

      • When you create a table with a CHAR column, the column requires a string length. The default is 1 byte.

当创建一个有CHAR 列的表时,需要为该列指定一个字符串长度。默认值是 1 个字节。

      • The database uses blanks to pad the value to the specified length.

据库使用空格填充到指定的长度的值

NVARCHAR2  

NCHAR

NVARCHAR2 NCHAR 数据类型存储 Unicode 字符数据

Unicode 是一种通用的编码字符集,可以将任何语言的信息存储在一种字符集中。

当您创建数据库时,指定国家字符集。

NCHAR NVARCHAR2 数据类型的字符集必须是 AL16UTF16 UTF8

这两种字符集都使用 Unicode 码。

当您创建一个有 NCHAR NVARCHAR2 列的表时,其最大大小始终是字符长度语义。

对于 NCHAR NVARCHAR2,字符长度语义是默认的,也是唯一的长度语义。

The NCHAR and NVARCHAR2 data types store Unicode character data.

Unicode is a universal encoded character set that can store information in any language using a single character set.

NCHAR stores fixed-length character strings that correspond to the national character set, whereas NVARCHAR2 stores variable length character strings.

You specify a national character set when creating a database.

The character set of NCHAR and NVARCHAR2 data types must be either AL16UTF16 or UTF8.

Both character sets use Unicode encoding.

When you create a table with an NCHAR or NVARCHAR2 column, the maximum size is always in character length semantics.

Character length semantics is the default and only length semantics for NCHAR or NVARCHAR2.

NVARCHAR2 存储可变长度的字符串

NCHAR存储对应于国家字符集的固定长度字符串

 

Numeric Data Types

数字数据类型

      • The Oracle Database numeric data types store fixed and floating-point numbers, zero, and infinity.

Oracle 数据库的数字数据类型存储固定和浮点数字、零、或无穷

      • Some numeric types also store values that are the undefined result of an operation, which is known as "not a number" or NAN.

某些数值类型也可以存储未定义操作的结果值,叫做"非数字" NAN

 

      • Oracle Database stores numeric data in variable-length format. Each value is stored in scientific notation, with 1 byte used to store the exponent.

Oracle 数据库以变长格式存储数字数据。用科学计数法存储值,其中一个字节用于存储指数

      • The database uses up to 20 bytes to store the mantissa, which is the part of a floating-point number that contains its significant digits.

数据库使用最多 20 个字节存储尾数,即浮点数的有效位数部分。

      • Oracle Database does not store leading and trailing zeros.

Oracle 数据库不会存储前导零和结尾零

 

NUMBER Data Type

 

      • The NUMBER data type stores fixed and floating-point numbers.

NUMBER 数据类型存储固定和浮点数字

      • The database can store numbers of virtually any magnitude.

数据库可以存储几乎任何规模的数字。

      • This data is guaranteed to be portable among different operating systems running Oracle Database.

此数据保证在运行 Oracle 数据库的不同操作系统之间可移植。

      • The NUMBER data type is recommended for most cases in which you must store numeric data.

大多数情况下,当您必须存储数值数据时,推荐使用 NUMBER 数据类型。

      • You specify a fixed-point number in the form NUMBER(p,s), where p and s refer to the following characteristics:

NUMBER(p,s)的形式定义定点数,p s 有以下特征:

精度

Precision

he precision specifies the total number of digits.

精度指定数字的总长度

If a precision is not specified, then the column stores the values exactly as provided by the application without any rounding.

如果不指定精度,则列按应用程序提供的数据存储值,不作任何舍入。

小数位数

Scale

The scale specifies the number of digits from the decimal point to the least significant digit.

小数位数指从十进制的小数点到最小有效数字的位数。

Positive scale counts digits to the right of the decimal point up to and including the least significant digit.

正小数位数从小数点向右计数直至最小有效位。

Negative scale counts digits to the left of the decimal point up to but not including the least significant digit.

负小数位数从小数点向左计数直至(但不包括)最小有效数字。

 If you specify a precision without a scale, as in NUMBER(6), then the scale is 0.

如果您指定了精度但没有指定小数位数,如 NUMBER(6),那么小数位数为 0

 

Floating-Point Numbers

      • Oracle Database provides two numeric data types exclusively for floating-point numbers: BINARY_FLOAT and BINARY_DOUBLE.

Oracle 数据库为浮点数提供了两种互斥的数值数据类型: BINARY_FLOAT BINARY_DOUBLE

      • These types support all of the basic functionality provided by the NUMBER data type.

这两种类型支持所有 NUMBER 数据类型提供的基本功能

      • However, while NUMBER uses decimal precision, BINARY_FLOAT and BINARY_DOUBLE use binary precision, which enables faster arithmetic calculations and usually reduces storage requirements.

然而,相比 NUMBER使用十进制精度BINARY_FLOAT BINARY_DOUBLE 使用二进制精度,可以使算术计算更快并且通常可以降低存储需求

 

      • BINARY_FLOAT and BINARY_DOUBLE are approximate numeric data types.

BINARY_FLOAT BINARY_DOUBLE 是近似数字数据类型

      • 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.

例如值 0.1不能用BINARY_DOUBLE BINARY_FLOAT 完全精确地表示。他们经常用于科学计算。

      • They are frequently used for scientific computations. Their behavior is similar to the data types FLOAT and DOUBLE in Java and XMLSchema.

其行为类似于 Java XMLSchema 中的 FLOAT DOUBLE 数据类型。

Datetime Data Types

日期时间数据类型

Datetime Data Types

 

The datetime data types are DATE and TIMESTAMP. Oracle Database provides comprehensive time zone support for time stamps.

日期时间数据类型包括 DATE TIMESTAMPOracle 数据库为时间戳提供全面的时区支持。

DATE Data Type

The DATE data type stores date and time. Although datetimes can be represented in character or number data types, DATE has special associated properties.

DATE 数据类型存储日期和时间。尽管日期时间可以用字符或数字数据类型表示,DATE 具有特殊的相关属性。

 

The database stores dates internally as numbers. Dates are stored in fixed-length fields of 7 bytes each, corresponding to century, year, month, day, hour, minute, and second.

数据库在内部将日期存储为数字。日期被存储为固定长度的域, 7 个字,分别对应世纪、 年、 月、 日、 小时、分、和秒

 

Note:

 

  • The database displays dates according to the specified format model.

数据库根据指定的 格式模型显示日期。

  • A format model is a character literal that describes the format of a datetime in a character string. The standard date format is DD-MON-RR, which displays dates in the form 01-JAN-09.

格式模型是一个描述在字符串中的日期时间格式的字符文字。标准的日期格式是 DD-MON-RR,它会以 01-JAN-09 的形式显示日期。

 

  • RR is similar to YY (the last two digits of the year), but the century of the return value varies according to the specified two-digit year and the last two digits of the current year.

RR类似于 YY (年的最后两位),但返回值的世纪值会因指定的两位年份及本年度的最后两位不同而不同

  • Assume that in 1999 the database displays 01-JAN-09. If the date format uses RR, then 09 specifies 2009, whereas if the format uses YY, then 09 specifies 1909. You can change the default date format at both the instance and the session level.

假设在 1999 年,数据库显示为 01-JAN-09。如果日期格式使用 RR,那么 09 指的是 2009,而如果格式使用 YY,那 09 指的是 1909。您可以更改实例或会话级别的默认日期格式

  • Oracle Database stores time in 24-hour formatHH:MI:SS. If no time portion is entered, then by default the time in a date field is 00:00:00 A.M. In a time-only entry, the date portion defaults to the first day of the current month.

Oracle 数据库以 24 小时制格式存储时间 — — HH:MI:SS。如果不输入的任何时间部分,那么默认情况下,日期字段中的时间是凌晨 00: 00: 00,如果只输入了时间,则日期部分默认为当月的第一天。

TIMESTAMP Data Type

      • The TIMESTAMP data type is an extension of the DATE data type.

TIMESTAMP 数据类型是日期数据类型的扩展

      • It stores fractional seconds in addition to the information stored in the DATE data type.

除了存储在 DATE 数据类型的信息,它同时还存储秒的小数部分

      • The TIMESTAMP data type is useful for storing precise time values, such as in applications that must track event order.

TIMESTAMP 数据类型对于存储精确时间的值很有用,比如那些必须跟踪事件顺序的应用程序。

      • The DATETIME data types TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE are time-zone aware.

DATETIME 数据类型 TIMESTAMP WITH TIME ZONE TIMESTAMP WITH LOCAL TIME ZONE 能感知时区。

      • When a user selects the data, the value is adjusted to the time zone of the user session. This data type is useful for collecting and evaluating date information across geographic regions.

当用户中选择数据时,其值会被调整以适配用户会话的时区。此数据类型可用于收集和评估各地理区域的日期信息

Rowid Data Types

ROWI数据类型

Rowid Data Types

Every row stored in the database has an address. Oracle Database uses a ROWID data type to store the address (rowid) of every row in the database. Rowids fall into the following categories:

存储在数据库中的每一行都有一个地址Oracle 数据库使用 ROWID 数据类型存储在数据库中的每一行的地址 (rowid)。Rowids 分为以下几类:

物理 rowids

Physical rowids store the addresses of rows in heap-organized tables, table clusters, and table and index partitions.

存储堆组织表、 表簇、表分区、和索引分区中的行地址。

逻辑 rowids

存储索引组织表中的行地址

Logical rowids store the addresses of rows in index-organized tables.

外部 rowids

Foreign rowids are identifiers in foreign tables, such as DB2 tables accessed through a gateway. They are not standard Oracle Database rowids.

外来表(如通过网关访问的 DB2 表)中的标识符。他们不是标准的 Oralce 数据库 rowids。

A data type called the universal rowid, or UROWID, supports all kinds of rowids.

有一种数据类型称为用 通用 rowid 或 UROWID,支持各种 rowids。

 

Use of Rowids

Oracle Database uses rowids internally for the construction of indexes.

Oracle 数据库在内部使用 rowids用于构造索引

A B-tree index, which is the most common type, contains an ordered list of keys divided into ranges. Each key is associated with a rowid that points to the associated row‘s address for fast access.

最常见的 B 树索引,包含一个被划分成多个键范围的排序列表。每个键都与一个指向关联的行地址的rowid 相关联,用于快速访问。

End users and application developers can also use rowids for several important functions:

最终用户和应用程序开发人员也可以使用rowids 的几个重要功能:

  • Rowids are the fastest means of accessing particular rows.

Rowids 是访问特定行的最快方式。

  • Rowids provide the ability to see how a table is organized.

Rowids 提供了查看表的组织方式的能力。

  • Rowids are unique identifiers for rows in a given table.

Rowids 是给定表中的行的唯一标识符。

 

 

You can also create tables with columns defined using the ROWID data type. For example, you can define an exception table with a column of data type ROWID to store the rowids of rows that violate integrity constraints. Columns defined using the ROWID data type behave like other table columns: values can be updated, and so on.

您也可以创建带 ROWID 数据类型列的表。例如,您可以定义一个异常表,其中一列为 ROWID 数据类型,以存储违反了完整性约束的行 rowids。使用ROWID 数据类型定义的列像其他表中的列一样, 其值可以更新,等等。

 

ROWID Pseudocolumn

  • Every table in an Oracle database has a pseudocolumn named ROWID.

Oracle 数据库中的每个表都有一个名为 ROWID 的 伪列。

  • A pseudocolumn behaves like a table column, but is not actually stored in the table.

伪列类似于表列,但实际上并不存储在表中。

  • You can select from pseudocolumns, but you cannot insert, update, or delete their values.

您可以从伪列中选择数据,但不能插入、更新、或删除它们的值。

A pseudocolumn is also similar to a SQL function without arguments. Functions without arguments typically return the same value for every row in the result set, whereas pseudocolumns typically return a different value for each row.

  • Values of the ROWID pseudocolumn are strings representing the address of each row.

伪列也类似于不带参数的 SQL 函数。不带参数的函数对于结果集中的每一行通常返回相同的值,而伪列通常为每个行返回不同的值。

  • These strings have the data type ROWID. This pseudocolumn is not evident when listing the structure of a table by executing SELECT or DESCRIBE, nor does the pseudocolumn consume space.

ROWID 伪列的值是表示的每个行的地址的字符串。这些字符串具有的数据类型 ROWID。在执行 SELECT 或 DESCRIBE 列出表的结构时,此伪列并不显示,它也不占用空间。

  • However, the rowid of each row can be retrieved with a SQL query using the reserved word ROWID as a column name.

但是,每个行的 rowid 可以通过使用保留字ROWID 作为列名的 SQL 查询来检索。

 

SQL> SELECT ROWID FROM employees WHERE employee_id = 100;

ROWID

------------------

AAAPecAAFAAAABSAAA

 

Format Models and Data Types

格式模型和数据类型

Format Models and Data Types

  • A format model is a character literal that describes the format of datetime or numeric data stored in a character string.

格式模型是一个字符文本,用来描述存储在一个字符串中的日期时间或数值数据格式

  • A format model does not change the internal representation of the value in the database.

格式模式不会更改数据库中的值的内部表示形式。

  • When you convert a character string into a date or number, a format model determines how the database interprets the string.

当您将一个字符串转换成日期或数字时,格式模型决定了数据库如何解释字符串。

  • In SQL, you can use a format model as an argument of the TO_CHAR and TO_DATE functions to format a value to be returned from the database or to format a value to be stored in the database.

SQL 中,你可以使用格式模型作为 TO_CHAR TO_DATE 函数的参数,来格式化将从数据库中返回的一个值,或将存储到数据库中的一个值。

 

下面的语句选择部门 80 中的雇员的薪水,并使用 TO_CHAR 函数来将这些薪水的值,转换为以数字格式模型 ‘$ 99,990.99‘ 指定的字符值:

SQL> SELECT last_name employee, TO_CHAR(salary, ‘$99,990.99‘)

2 FROM employees

3 WHERE department_id = 80 AND last_name = ‘Russell‘;

EMPLOYEE TO_CHAR(SAL

------------------------- -----------

Russell $14,000.00

下面的示例更新一个雇佣日期,使用 TO_DATE 函数与格式掩码 ‘YYYYMM DD‘ 将字符串 ‘1998 05 20‘ 转换为日期值。

SQL> UPDATE employees

2 SET hire_date = TO_DATE(‘1998 05 20‘,‘YYYY MM DD‘)

3 WHERE last_name = ‘Hunold‘;

其他内建类型

Other important categories of built-in types include raw, large objects (LOBs), and collections. PL/SQL has data types for constants and variables, which include BOOLEAN, reference types, composite types (records), and user-defined types.

RAW、大对象 (LOB)、 和集合。 PL/SQL 有用于常量和变量的数据类型,包括布尔、 引用类型、 复合类型 (记录) 、和用户定义类型

Oracle Schema Objects——Tables——Oracle Data Types

标签:rowid   site   sim   列表   sel   日期时间   cin   different   例子   

原文地址:http://www.cnblogs.com/scentpath/p/OracleDataTypes.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!