oracle - 对子类型属性的约束 (Oracle)

标签 oracle constraints

如果我有一个类型 x_typ 和子类型 y_typ,是否可以创建一个 x_typ 的对象表,但对 y_typ 属性之一施加约束,即

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

谢谢

最佳答案

我能来的最近的是...

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

关于oracle - 对子类型属性的约束 (Oracle),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2330678/

相关文章:

oracle - schema_version 没有选择权限?

haskell - 有没有办法在 Haskell 的类型类中实现约束?

haskell - 从参数的约束推断类型族的约束

java.lang.ArrayIndexOutOfBoundsException at oracle.jdbc.driver.T4CTTIrxd.readBitVector(T4CTTIrxd.java :135)

java - 无法使用 hibernate 从 oracle 表中选择数据

oracle - 为 Delphi + Oracle 构建自动化

ios - 更改约束常量后是否需要 setNeedsLayout 和 layoutIfNeeded?

ios 自动布局约束问题

postgresql - 更新列或 Column 或 ColumnS 时触发触发器

oracle - 从Hive访问Oracle NoSQL