Oracle12c learning - commonly used data types

1. String type

   String data types can also be divided into fixed-length types (CHAR/NCHAR) and variable-length types (VARCHAR2/NVARCHAR2) according to storage space.

    The so-called fixed length: It means that although the input field value is less than the limit length of the field, when actually storing the data, the space will be automatically filled to the right before the content of the field value is stored in the data block. Although this method wastes space, the storage efficiency is better than that of variable-length types. At the same time, it can also reduce the occurrence of data row migration.

The so-called variable length: when the input field value is less than the limit length of the field, the content of the field value is directly stored in the data block without filling blanks, which can save the space of the data block .

(1) CHAR(size) type, fixed-length string, non-NULL CHAR(12) always contains 12 bytes of information. If the length is not enough, it will be filled with spaces to reach its maximum length. If it exceeds, an error will be reported directly. A CHAR field can store up to 2,000 bytes of information. If the CHAR length is not specified when creating a table, it defaults to 1.

For example: create table test1:

It can also be viewed through the dump() function:


As can be seen from the above figure, the type number of char(16) is 96, the length is 16, the following 97, 98, 99 are the values ​​of the ascall code corresponding to abc, followed by spaces.

As shown in the two figures above, a CHAR field can store up to 2,000 bytes of information.

(2) VARCHAR2(size), variable-length character string, the VARCHAR2 field can store up to 4,000 bytes of information.

For example: create table test3:


As shown in the figure above, VARCHAR2(size) is a variable-length string type.

For CHAR and VARCHAR2, if the length of the characters used is fixed, it is recommended to use CHAR(size), because it is more efficient to access. If the stored data is changed, it is recommended to use VARCHAR(size).

(3) NARCHAR(size) This is a fixed-length string containing data in UNICODE format. NCHAR fields can store up to 2,000 bytes of information. Its maximum length depends on the national character set.

For example: create table test4:


Create table test5


As can be seen from the above three figures, in NCHAR(size), both Chinese characters and English letters occupy one character space. In CHAR (szie), a Chinese character occupies two character spaces.

For example table test6;


(4) NVARCHAR2(size) type This is a variable-length string containing data in UNICODE format. NVARCHAR2 can store up to 4,000 bytes of information.


2. Numerical type

NUMBER(P,S) is the most common number type, which can store data in the range of 10^ 130 ~ 10^ 126 (excluding this value), and requires storage space ranging from 1 to 22 bytes (BYTE).

P is the English abbreviation of Precison, that is, the precision abbreviation, which means the number of significant digits, which cannot exceed 38 significant digits at most.

S is the English abbreviation of Scale, and the range that can be used is -84~127. When Scale is positive, it represents the number of digits from the decimal point to the least significant digit, and when it is negative, it represents the number of digits from the most significant digit to the decimal point.

Actual Data

Specified As

Stored As

123.89

NUMBER

123.89

123.89

NUMBER(3)

124

123.89

NUMBER(6,2)

123.89

123.89

NUMBER(6,1)

123.9

123.89

NUMBER(3)

124

123.89

NUMBER(4,2)

exceeds precision

123.89

NUMBER(6,-2)

100

.01234

NUMBER(4,5)

.01234

.00012

NUMBER(4,5)

.00012

.000127

NUMBER(4,5)

.00013

.0000012

NUMBER(2,7)

.0000012

.00000123

NUMBER(2,7)

.0000012

1.2e-4

NUMBER(2,5)

0.00012

1.2e-5

NUMBER(2,5)

0.00001

3. Date and time type

(1) DATE type

DATE is the most commonly used data type, the date data type stores date and time information. Although date and time information can be represented in character or numeric types, the date data type has special associated properties. For each date value, Oracle stores the following information: century, year, month, date, hour, minute, and second. Usually takes up 7 bytes of storage space.

For example: create table test7;


Note that the format of the Oracle creation date matches.

(2) TIMESTAMP type

This is a 7-byte or 12-byte fixed-width date/time data type. It is different from DATE data type because TIMESTAMP can contain fractional seconds, TIMESTAMP with fractional seconds can hold up to 9 digits to the right of the decimal point


 




















Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324775476&siteId=291194637