Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
32
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

2

Selecting a Datatype

This chapter discusses how to use Oracle built-in datatypes in applications. Topics include:

Summary of Oracle Built-In Datatypes

Representing Character Data

Representing Numeric Data with Number and Floating-Point Datatypes

Representing Date and Time Data

Representing Conditional Expressions as Data

Representing Geographic Coordinate Data

Representing Image, Audio, and Video Data

Representing Searchable Text Data

Representing Large Amounts of Data

Addressing Rows Directly with the ROWID Datatype

ANSI/ISO, DB2, and SQL/DS Datatypes

How Oracle Database Converts Datatypes

Representing Dynamically Typed Data

Representing XML Data

Selecting a Datatype 2-1

Summary of Oracle Built-In Datatypes

See Also:

Oracle Database Application Developer's Guide - Object-Relational Features for information about more complex types, such as object types, varrays, and nested tables

Oracle Database Application Developer's Guide - Large Objects for information about LOB datatypes

PL/SQL User's Guide and Reference for information about the PL/SQL datatypes. Many SQL datatypes are the same or similar in PL/SQL.

Summary of Oracle Built-In Datatypes

A datatype associates a fixed set of properties with the values that can be used in a column of a table or in an argument of a procedure or function. These properties cause Oracle Database to treat values of one datatype differently from values of another datatype. For example, Oracle Database can add values of NUMBER datatype, but not values of RAW datatype.

Oracle supplies the following built-in datatypes:

Character datatypes

CHAR

NCHAR

VARCHAR2 and VARCHAR (synonymous with VARCHAR2)

NVARCHAR2

CLOB

NCLOB

LONG

Numerical datatypes:

BINARY_FLOAT

BINARY_DOUBLE

NUMBER

Time and date datatypes:

DATE

INTERVAL DAY TO SECOND

2-2 Oracle Database Application Developer's Guide - Fundamentals

Summary of Oracle Built-In Datatypes

INTERVAL YEAR TO MONTH

TIMESTAMP

TIMESTAMP WITH TIME ZONE

TIMESTAMP WITH LOCAL TIME ZONE

Binary datatypes

BLOB

BFILE

RAW

LONG RAW

Row address datatypes

ROWID

UROWID

See Also:

Oracle Database SQL Reference for general descriptions of these datatypes

Oracle Database Application Developer's Guide - Large Objects for information about the LOB datatypes

Table 2–1 summarizes the information about each Oracle built-in datatype.

Selecting a Datatype 2-3

Summary of Oracle Built-In Datatypes

Table 2–1 Summary of Oracle Built-In Datatypes

 

 

Column Length / Default

Datatype

Description

Values

CHAR

Fixed-length character data

[(size [BYTE | CHAR])]

of length size bytes or

 

characters.

Fixed for every row in the table (with trailing blanks); maximum size is 2000 bytes per row, default size is 1 byte per row. When neither BYTE nor CHAR is specified, the setting of NLS_LENGTH_ SEMANTICS at the time of column creation determines which is used. Consider the character set (single-byte or multibyte) before setting size.

VARCHAR2

(size [BYTE | CHAR])

Variable-length character data, with maximum length size bytes or characters. BYTE or CHAR indicates that the column has byte or character semantics, respectively. A size must be specified.

Variable for each row, up to 4000 bytes per row. When neither BYTE nor CHAR is specified, the setting of NLS_LENGTH_ SEMANTICS at the time of column creation determines which is used. Consider the character set (single-byte or multibyte) before setting size.

NCHAR [(size)]

Fixed-length Unicode

 

character data of length

 

size characters. The

 

number of bytes is twice this

 

number for the AL16UTF16

 

encoding and 3 times this

 

number for the UTF8

 

encoding.)

Fixed for every row in the table (with trailing blanks). The upper limit is 2000 bytes per row. Default size is 1 character.

NVARCHAR2 (size)

Variable-length Unicode

 

character data of maximum

 

length size characters. The

 

number of bytes may be up

 

to 2 times size for a the

 

AL16UTF16 encoding and 3

 

times this number for the

 

UTF8 encoding. A size

 

must be specified.

Variable for each row. The upper limit is 4000 bytes per row.

2-4 Oracle Database Application Developer's Guide - Fundamentals

Summary of Oracle Built-In Datatypes

Table 2–1 (Cont.) Summary of Oracle Built-In Datatypes

Datatype

CLOB

NCLOB

LONG

 

Column Length / Default

Description

Values

Single-byte or multibyte character data. Both fixed-width and variable-width character sets are supported, and both use the CHAR character set.

Unicode national character set (NCHAR) data. Both fixed-width and variable-width character sets are supported, and both use the NCHAR character set.

Variable-length character data. Provided for backward compatibility.

Up to 232 - 1 bytes * (database block size), or 4

gigabytes * block size.1 See

Oracle Database Application Developer's Guide - Large Objects.

Up to 232 - 1 bytes * (database block size), or 4

gigabytes * block size. 1

See Oracle Database Application Developer's Guide - Large Objects.

Variable for each row in the table, up to 231 - 1 bytes, or 2 gigabytes, per row.

BINARY_FLOAT

32-bit floating-point

 

number.

BINARY_DOUBLE

64-bit floating-point

 

number.

NUMBER

Variable-length numeric

[(prec | prec, scale)]

data. Precision prec is the

 

the total number of digits;

 

scale scale is the number

 

of digits to the right of the

 

decimal point. Precision can

 

range from 1 to 38. Scale

 

can range from -84 to 127.

 

With precision specified,

 

this is a floating-point

 

number; with no precision

 

specified, it is a fixed-point

 

number.

4 bytes.

8 bytes.

Variable for each row. The maximum space available for a given column is 21 bytes per row.

Selecting a Datatype 2-5

Summary of Oracle Built-In Datatypes

Table 2–1

(Cont.) Summary of Oracle Built-In Datatypes

 

 

 

 

 

 

Column Length / Default

Datatype

Description

Values

DATE

Fixed-length date and time

 

data, ranging from Jan. 1,

 

4712 B.C.E. to Dec. 31, 9999

 

C.E.

Fixed at 7 bytes for each row in the table. Default format is a string (such as DD-MON-RR) specified by the NLS_DATE_FORMAT parameter.

INTERVAL YEAR [(yr_prec)] TO MONTH

A period of time,

Fixed at 5 bytes.

represented as years and

 

months. The yr_prec is

 

the number of digits in the

 

YEAR field of the date. The

 

precision can be from 0 to 9,

 

and defaults to 2 digits.

 

INTERVAL DAY [(day_prec)] TO SECOND [(frac_sec_prec)]

TIMESTAMP [(frac_sec_prec)]

A period of time, represented as days, hours, minutes, and seconds. The day_prec and frac_sec_ prec are the number of digits in the DAY and the fractional SECOND fields of the date, respectively. These precision values can each be from 0 to 9, and they default to 2 digits for day_ prec and 6 digits for frac_sec_prec.

A value representing a date and time, including fractional seconds. (The exact resolution depends on the operating system clock.)

The frac_sec_prec specifies the number of digits in the fractional second part of the SECOND date field. The frac_sec_ prec can be from 0 to 9, and defaults to 6 digits.

Fixed at 11 bytes.

Varies from 7 to 11 bytes, depending on the precision. The default is determined by the NLS_ TIMESTAMP_FORMAT initialization parameter.

2-6 Oracle Database Application Developer's Guide - Fundamentals

 

 

 

Summary of Oracle Built-In Datatypes

 

 

 

 

Table 2–1

(Cont.) Summary of Oracle Built-In Datatypes

 

 

 

 

 

 

 

Column Length / Default

 

Datatype

Description

Values

TIMESTAMP [(frac_sec_prec)] WITH TIME ZONE

TIMESTAMP [(frac_sec_prec)] WITH LOCAL TIME ZONE

BLOB

BFILE

A value representing a date and time, plus an associated time zone setting. The time zone can be an offset from UTC, such as '-5:0', or a region name, such as

'US/Pacific'.

The frac_sec_prec is as for datatype TIMESTAMP.

Similar to TIMESTAMP WITH TIME ZONE, except that the data is normalized to the database time zone when stored, and adjusted to match the client's time zone when retrieved.

The frac_sec_prec is as for datatype TIMESTAMP.

Unstructured binary data.

Address of a binary file stored outside the database. Enables byte-stream I/O access to external LOBs residing on the database server.

Fixed at 13 bytes. The default is determined by the NLS_TIMESTAMP_ TZ_FORMAT initialization parameter.

Varies from 7 to 11 bytes, depending on frac_ sec_prec. The default is determined by the NLS_ TIMESTAMP_FORMAT initialization parameter.

Up to 232 - 1 bytes * (database block size), or 4

gigabytes * block size.1 See

Oracle Database Application Developer's Guide - Large Objects.

The referenced file can be up to 232 - 1 bytes * (database block size), or 4

gigabytes * block size.1 See

Oracle Database Application Developer's Guide - Large Objects.

RAW (size)

Variable-length raw binary

 

data. A size, which is the

 

maximum number of bytes,

 

must be specified. Provided

 

for backward compatibility.

Variable for each row in the table, up to 2000 bytes per row.

Selecting a Datatype 2-7

Тут вы можете оставить комментарий к выбранному абзацу или сообщить об ошибке.

Оставленные комментарии видны всем.

Соседние файлы в папке Oracle 10g