ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 表number列的数据插入insert小测试

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

原创 Linux操作系统 作者:wisdomone1 时间:2010-08-13 23:13:26 0 删除 编辑

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:

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-670955/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
提供针对oracle初学者及进阶的数据库培训,欢迎大家咨询: 微信: wisdomone 微信公众号: lovedb 工作经历: 中国普天 北京科蓝 北京云和恩墨 北京神州新桥

注册时间:2008-04-04

  • 博文量
    2189
  • 访问量
    12689906