The maximum length of integer bits of Oracle's number is 38 (the maximum length of decimal places is 127), and the maximum length of varchar2 is 4000

SQL> alter table can_do modify id number(39);
alter table can_do modify id number(39)
                                    *
ERROR at line 1:
ORA-01727: numeric precision specifier is out of range (1 to 38)


SQL> alter table can_do modify name varchar2(4001);
alter table can_do modify name varchar2(4001)
                                        *
ERROR at line 1:
ORA-00910: specified length too long for its datatype


SQL>

Description: The default value of number is 38, and the range of number is (1~38 ). varchar2 has no default value, length must be specified. (1~4000)

Tip: Regarding the definition of number type in Oracle, number(p[,s]), p is: precision, s is: scale

Range: 1 <= p <=38, -84 <= s < = 127
save data range: -1.0e-130 <= number value < 1.0e+126  
The range stored in the machine: 1 ~ 22 bytes

number(p,s) Meaning: the right side of the decimal point does not exceed s digits, and the total number of digits to the left and right of the decimal point does not exceed p digits.

If it is defined as: id number, precision and scale are not specified, which is equivalent to number(38,7).

At most 7 digits to the right of the decimal point, and the total number of digits to the left and right of the decimal point does not exceed 38 digits.

If defined as: id number(5), the precision is 5, the scale is 0, there are no digits to the right of the decimal point, and there are at most 5 digits to the left of the decimal point. , if the input number is with decimal places such as: 12345.71, Oracle will automatically round up to:

12346, if the input number is 12345.48, it will be automatically rounded to: 12345.

If it is defined as: salary number(6,2), the precision is 6 and the scale is 2, that is, there are at most two digits to the right of the decimal point, and the total number of digits to the left and right of the decimal point does not exceed 6 digits (excluding the decimal point ".").

About the experiment after id number type definition:

SQL> create table can_do_temp (id number primary key,name varchar2(100));

Table created

SQL> desc can_do_temp;
Name Null? Type
------------ ----------------------------- -------- ------------- ---------------
ID NOT NULL NUMBER
NAME VARCHAR2(100)

SQL> select * from can_do_temp;

        ID NAME
---------- ---------------------- -
-
1.0000E+39 1
1.0000E+39 2
1.0000E+40 3
1.0000E+38 4
1.0000E+37 5
1.0000E+38 6According

to normal considerations, the maximum value that id can absorb is 38 9s: [ 9999999999999999999999999999999999999]

select length('999999999999999999999999999999999999') from dual;

that is to say, the maximum id of the table can_do_temp is 1.0000E+38

, so how does 1.0000E+39 get inserted?

If you use the power function, it can be inserted, such as:

SQL> insert into can_do_temp b (id,name) values ​​(power(10,40)-1,'1');

1 row created.

SQL> commit;

Commit complete.

But if you do not use the power function but write 39 9s directly, it will prompt a primary key conflict, as follows

SQL> insert into can_do_temp b (id,name) values ​​(999999999999999999999999999999999999,'1');
insert into can_do_temp b (id,name) values ​​(999999999999999999999999999999999999,'1')
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C005211) violated I

don't know if this is an Oracle bug or Oracle itself does not limit the maximum number of bits number.

Try hard enough :

SQL> insert into can_do_temp b (id,name) values ​​(power(10,100)-1,'9');

1 row created.

SQL> commit;

Commit complete.

SQL> alter table can_do_temp modify age number(38,128);
alter table can_do_temp modify age number(38,128)
                                             *
ERROR at line 1:
ORA-01728: numeric scale specifier is out of range (-84 to 127)


SQL> alter table can_do_temp modify age number(39,7);
alter table can_do_temp modify age number(39,7)
                                          *
ERROR at line 1:
ORA-01727: numeric precision specifier is out of range (1 to 38)

SQL> alter table can_do_temp modify age number(3,4);

Table altered.

SQL> desc can_do_temp;
Name                                      Null?    Type
----------------------------------------- -------- ------------------------
ID                                        NOT NULL NUMBER
NAME VARCHAR2(100)
AGE NUMBER(3,4)

SQL> insert into can_do_temp values(1,'14',2.1234);
insert into can_do_temp values(1,'14',2.1234)
                                      *
ERROR at line 1:
ORA-01438 : value larger than specified precision allowed for this column

is recommended not to be written as: id number when defining the data type,

that is, the format that does not specify precision (scale) is deprecated.

And the general definition format is p>3.

【Written on 2009-01-21】

Guess you like

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