Subtype Attribute Constraint (Oracle)

If I have type x_typ and subtype y_typ, is it possible to create an object table x_typ, but set a restriction on one of the attributes y_typ ie

create table x_table of x_typ ( constraint constr_y check (y_typ.attribute1 < 5); ); 

thanks

+4
source share
1 answer

The closest I can come ...

 CREATE OR REPLACE TYPE x_typ AS OBJECT (record_type varchar2(1)) NOT FINAL; / CREATE OR REPLACE TYPE y_typ UNDER x_typ (attribute1 number) ; / create table x_table (x_col x_typ); alter table x_table add constraint x_cons check ( 1 = case when x_col is of (y_typ) then treat (x_col as y_typ).attribute1 else 1 end); 
+1
source

Source: https://habr.com/ru/post/1302304/


All Articles