我想知道如何在Oracle DB中对Distinct用户定义类型(具有一个属性的对象类型)应用某种约束,以使值(价格值)不能为负数?
我有这种类型:
CREATE OR REPLACE TYPE price_info AS OBJECT(
value NUMBER,
MEMBER FUNCTION get_value RETURN NUMBER)
答案 0 :(得分:2)
SQL> create table prices
2 (price price_info
3 , check ( price.value >= 0));
Table created.
SQL> insert into prices values (price_info(-1));
insert into prices values (price_info(-1))
*
ERROR at line 1:
ORA-02290: check constraint (SYSTEM.SYS_C0012070) violated