The difference between int and number in oracle

Oracle does not have an int type. In order to be compatible with other databases, the int type is added as a subset of the number type.
The int type can only store integers;
number can store floating-point numbers or integers;
number(8,1) stores floating-point numbers with 1 decimal place and a total length of 8. If the number of decimal places is insufficient, it is filled with 0 ;
number(8) stores an integer with a total length of 8;
int is equivalent to number(22) and stores an integer with a total length of 22.
For example: --Create
table structure
SQL> create table tab(id0 int,id1 number,id2 number(8,1),id3 number(8));

Table created

SQL> --Insert
test data
SQL> insert into tab select 1,1.5,1.6,8 from dual;

1 row inserted
SQL> insert into tab select 1,1.55,1.6,8 from dual;

1 row inserted
SQL> insert into tab select 1,1.595,1,8 from dual;

1 row inserted

SQL> commit;

Commit complete

SQL> select * from tab;

     ID0        ID1        ID2       ID3
---------- ---------- ---------- ---------
      1        1.5        1.6         8
      1       1.55        1.6         8
      1      1.595        1.0         8

--查询数据字典表dba_tab_columns
SQL> select table_name,column_name,data_type,data_length,data_precision,data_scale from dba_tab_columns a
  2  where table_name='TAB'
  3  and owner='NETMAX'
  4  order by column_id;

TABLE_NAME        COLUMN_NAME        DATA_TYPE         DATA_LENGTH   DATA_PRECISION    DATA_SCALE
--------------- -------------- -----------------  ----------------    -----------      ----------
TAB ID0 NUMBER 22 0
TAB ID1 NUMBER 22               
TAB ID2 NUMBER 22 8 1
TAB ID3 NUMBER 22 8 0

SQL>

In the dba_tab_columns table,
Data_type represents the field type;
Data_length represents the length of the field type;
Data_Precision represents the total length of the precision of the field type, If it is null, it means that the total length of the precision is not fixed, and the longest is Data_Length;
Data_scale means the precision range of the field type. If it is 0, it means that it can only be stored as an integer.
If it is null, it means that it can store an integer or a floating-point number. The number of digits is indeterminate.
If it is an integer, it means the number of digits of precision stored.

Query the dba_tab_columns table and find that the ID0 field type int in the tab table has been converted to number (22).

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326871173&siteId=291194637