oracle PL SQL 正数子类型

oracle PL SQL positive number subtype

我想创建一个正数 (6, 2) 子类型。 为此,我尝试了:

declare
    subtype st_positive_number is number(6, 0) > 0;
    v_positive_number positive(6, 2);
begin 
    null;
end;

但是上面的 none 尝试有效。 有人可以帮忙吗?

您想如何使用它?如果它是关于创建一个 table 其列只接受正数,那么创建一个检查约束,例如

SQL> create table test (id number constraint ch_pos check (id > 0))

Table created.

SQL> insert into test (id) values (100);

1 row created.

SQL> insert into test (id) values (-100);
insert into test (id) values (-100)
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CH_POS) violated

如果这不是你要找的,你能再解释一下吗?

您需要用一个范围来约束子类型,并且您希望将该子类型分配给变量,例如:

declare
    subtype st_positive_number is PLS_INTEGER RANGE 0..999999;
    v_positive_number st_positive_number;
begin 
    v_positive_number := 999999;
end;
/