Check constraint on a type

狂风中的少年 提交于 2019-12-11 10:35:45

问题


I have something like this:

CREATE TYPE oAuthors AS OBJECT (
    ... ,
    contract CHAR(1),

    CONSTRUCTOR FUNCTION oAuthors (...
);

The thing is that I wanted to add a constraint to allow only 0 or 1 in contract.
I tried to do so right after the declaration of the column by adding

CONSTRAINT contract_bit CHECK (contract IN ('0','1')),

I also tried to do it in an ALTER sentence, but the problem is that this is not a table so it won't recognize it, and using ALTER TYPE doesn't work (although I was just trying, I don't know how to do it).

So basically I have no idea if this is possible by using a constraint, should I create a trigger or something?


回答1:


You can't define constraint on object type: http://docs.oracle.com/cd/B28359_01/server.111/b28286/clauses002.htm

You can define constraints syntactically in two ways:

  • As part of the definition of an individual column or attribute. This is called inline specification.
  • As part of the table definition. This is called out-of-line specification

Constraint clauses can appear in the following statements:

  • CREATE TABLE (see CREATE TABLE)
  • ALTER TABLE (see ALTER TABLE)
  • CREATE VIEW (see CREATE VIEW)
  • ALTER VIEW (see ALTER VIEW)

Here is how you enforce constraints on objects: http://docs.oracle.com/cd/B28359_01/appdev.111/b28371/adobjdes.htm#i452285



来源:https://stackoverflow.com/questions/23954390/check-constraint-on-a-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!