Oracle database commonly used data types

Oracle database commonly used data types

Oracle data types are very rich, the official document https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT012 , here is a brief summary and introduction of commonly used ones.

 

Character data type

String, text

☆Char

A fixed-length format string. When it is stored in the database, there are not enough digits to fill in the spaces. Its declaration method is CHAR(size). Size is the length of the string. A value between 1-2000 bytes can be specified as the width of CHAR ( In bytes or characters). The default (default) value is 1 byte

It is not recommended to use, it will cause unnecessary trouble:

a. When comparing strings, if you don’t pay attention (char is not enough to fill in spaces), it will bring errors

b. When comparing strings, if the trim function is used, the index on the field will be invalid (sometimes it will cause serious performance problems)

c. Waste of storage space (the future storage size cannot be accurately calculated, only enough space can be left; the length of the string is the size of the space it occupies)

 

☆Varchar2 / Varchar

Note: varchar is an obsolete type, and Oracle currently recommends varchar2.

Used to save variable-length character string data. It is declared as Varchar2 (size), where the maximum byte length is specified by (size). The length of each line is variable, the maximum length is 4000 bytes per line, and there is no default value.

Before setting the length (size), consider whether the character set is single-byte or multi-byte. Because the VARCHAR2 data type only stores the characters assigned to the column (without spaces), the storage space required for VARCHAR2 is smaller than that of the CHAR data type.

Note: varchar2 occupies two bytes for all characters (generally), varchar only occupies two bytes for Chinese characters and full-width characters, numbers, English characters, etc. are all one byte;

When the locale is Chinese (SIMPLIFIED CHINESE_CHINA.ZHS16GBK), a VARCHAR2(200) data column can store 200 English characters or 100 Chinese characters.

VARCHAR2 treats empty strings as null, while varchar is still treated as empty strings; in most cases, it is recommended to use the varchar2 type to ensure better compatibility.

 

Large object type (Large Objects)

Including BLOB, CLOB, NCLOB and BFILE. They allow you to store and manipulate large unstructured data, such as pictures, text, video, sound, and so on.

☆BLOB type

The BLOB type stores unstructured binary data in the database, and can store up to 128T of binary data.

☆B CLOB and NCLOB types

CLOB and NCLOB types can store up to 128T character data. CLOB stores database character set data, and NCLOB stores Unicode character set data.

☆B BFILE type

The BFILE type stores unstructured binary data outside the database. BFILE data stores a file locator pointing to an external file. The number of BFILEs that can be stored is limited by the operating system. In addition, BFILE is read-only.

 

Numerical type

Numerical types can store positive and negative fixed-point and floating-point numbers, zero, infinity, and undefined operation results (such as non-numeric NaN).

☆NUMBER type

The NUMBER type is used to store fixed-point and floating-point numbers. It can store values ​​of almost any size (38-bit precision) and is commonly used in different versions of Oracle databases.

 

You can choose to specify NUMBER type precision and numerical range:

column_name NUMBER (precision, scale)

If precision is not specified, the database will save the value according to the given value. If the scale (value range) is not specified, the value range is 0. Oracle guarantees the portability of values ​​with a precision of less than or equal to 38 digits. The precision can be specified as *. In this case, the precision is 38 digits, and the numerical range is still given. as follows:

column_name NUMBER (*, scale)

The following table shows how the value range affects data storage. Take the input 7,456,123.89 as an example:

Appointed as

Stored as

NUMBER

7456123.89

NUMBER(*,1)

7456123.9

NUMBER(9)

7456124

NUMBER(9,2)

7456123.89

NUMBER(9,1)

7456123.9

NUMBER(6)

not accepted, exceeds precision

NUMBER(7,-2)

7456100

 

☆Floating point type

Oracle database specifically provides two data types for floating-point numbers, BINARY_FLOAT and BINARY_DOUBLE. They support all the basic functions provided by NUMBER. And because NUMBER uses decimal precision, BINARY_FLOAT and BINARY_DOUBLE use binary precision, which provides them with faster numerical calculation speed and often reduces storage requirements.

 

BINARY_FLOAT and BINARY_DOUBLE are approximate numeric types. They store approximate representations of decimal values, rather than exact representations. For example, the decimal number 0.1 cannot be accurately expressed as BINARY_FLOAT or BINARY_DOUBLE. They are often used for scientific calculations and are similar in behavior to FLOAT and DOUBLE in Java and XML Schema.

 

BINARY_FLOAT

BINARY_FLOAT is a 32-bit single-precision floating-point number type, which requires 5 bytes of storage space, including a length byte.

 

BINARY_DOUBLE

BINARY_DOUBLE is a 64-bit double-precision floating-point number type, which requires 9 bytes of storage space, including a length byte.

 

值                 BINARY_FLOAT        BINARY_DOUBLE

Maximum positive value 3.40282E+38F 1.79769313486231E+308

Minimum positive value 1.17549E-38F 2.22507485850720E-308

 

Date and time type

Date and time types include DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE. The time interval types include INTERVAL YEAR TO MONTH and INTERVAL DAY TO SECOND.

 

☆DATE type

The DATE type stores date and time information. For each DATE type value, Oracle stores the following information: century, year, month, day, hour, minute, and second. You can specify a literal value for a DATE type value, and you can also use the TO_DATE function to convert a character or a value to a DATE type.

 

☆TIMESTAMP type

The TIMESTAMP data type is an extension of the DATE type. It stores the year, month, and day, plus hours, minutes, and seconds. This data type is useful for storing accurate time values.

 

rowid type

Each row record of each table in the Oracle database has a storage physical location, that is, the rowid pseudo-column of the table. Using rowid as the where condition has the highest access efficiency.

Although rowid's access efficiency is the highest, it is necessary to be cautious in practical applications. Two issues need to be paid attention to:

(1) Rowid stores the physical location of the table record. During data sorting, data backup and migration, the physical location of the record will change;

(2) Rowid is a proprietary data type of Oracle database and is not compatible with other databases.

 

Oracle also provides user-defined data types. You can use the keyword create type or type to define a custom type. I won't discuss it here. Please refer to https://blog.csdn.net/ththcc/article/details/79961982 .

 

If you want to learn more, you can read the link below

https://www.cnblogs.com/kliine/p/10018607.html

https://www.freecplus.net/8cdd1d008f844f77bdc8bca0d5f0e0b6.html

 

Guess you like

Origin blog.csdn.net/cnds123/article/details/114684695