简体   繁体   中英

Constraint on subtype attribute (Oracle)

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

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

Thanks

The closest I can come is...

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM