Oracle SQL unsigned integer

只谈情不闲聊 提交于 2019-12-05 21:48:55

If you want to match the restrictions shown here, you can use a check constraint:

SQL> create table foo (id number primary key, 
    constraint foo_uint_id check (id between 0 and 4294967295));

Table created.

SQL> insert into foo (id) values (-1);

insert into foo (id) values (-1)
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.FOO_UINT) violated

SQL> insert into foo (id) values (0);

1 row created.

SQL> insert into foo (id) values (4294967295);

1 row created.

SQL> insert into foo (id) values (4294967296);

insert into foo (id) values (4294967296)
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.FOO_UINT_ID) violated

SQL> select * from foo;

        ID
----------
         0
4294967295

Here http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements001.htm#i54330 is the definitive list of Oracle's built in datatypes.

If you want the semantics of integers, then number(n) is basically your only option. Personally I use integer which is a slightly shorter way of saying number(38).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!