Oracle SQL无符号整数 [英] Oracle SQL unsigned integer

查看:861
本文介绍了Oracle SQL无符号整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Oracle中,什么等于MySQL的UNSIGNED?

In Oracle, what is the equivalent to MySQL's UNSIGNED?

我有以下查询,只有它不起作用:

I have the following query, only it doesn't work:

CREATE TABLE foo
(
  id INT UNSIGNED NOT NULL PRIMARY KEY
);

我的目的是节省空间,因为对于某些字段,我不会使用负值.或者,它会回答我的问题,即有人确认我要的内容在Oracle 11g中是不可能的,或者是否有可能,但不是一件容易的事(每个未签名的int多于3行代码).

My purpose is to save space, because for some fields I won't be using negative values. Alternatively, it would answer my question of someone confirms that what I'm asking for is impossible in Oracle 11g, or if it's possible, but not straightforward to do (more than 3 lines of code per unsigned int).

此外,它不一定与 int 有关.我也使用smallint和tinyint.

Also, It's not necessarily about int. I also use smallint and tinyint.

推荐答案

如果要匹配显示的限制,请

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

这篇关于Oracle SQL无符号整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆