表number列的数据插入insert小测试

SQL> desc test_trim;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 A                                                  NUMBER(3,1) --列类型为number(3,1),表示整数位和小数位共3位,小数位为1位,所以整数位只能为2位
 B                                                  VARCHAR2(20)

SQL> truncate table test_trim;

Table truncated.

SQL> insert into test_trim values(20.39,'c');

1 row created.

SQL> insert into test_trim values(20.34,'b');

1 row created.

SQL> insert into test_trim values(20.359,'a');--这里小数位采用四取五入

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test_trim;

         A B
---------- --------------------
      20.4 c
      20.3 b
      20.4 a  --四舍五入的插入列值到表中

SQL> insert into test_trim values(20.959,'d');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test_trim;

         A B
---------- --------------------
      20.4 c
      20.3 b
      20.4 a
        21 d

SQL> insert into test_trim values(100,'t');--不允许插入,因为整数位只能是2位
insert into test_trim values(100,'t')
                             *
ERROR at line 1:
ORA-01438: value larger than specified precision allowed for this column


SQL> insert into test_trim values(99.99,'tb');--这个也插不进来,虽然整位数是2位,但小数位四舍五入后,整数变成100,所以不能插入
insert into test_trim values(99.99,'tb')
                             *
ERROR at line 1:

请使用浏览器的分享功能分享到微信等