Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to figure out the correct constraint syntax for the following statement:

"For a given measurement, when Value is present, the Outlier Indicator must be NULL (and, conversely, the Value must be NULL if the Outlier Indicator is present).

'Value' and 'Outlier Indicator' are two columns that I have in a table.

What I have been doing so far is

  1. Right Click on table name in the left pane to open "Edit Table"
  2. Click "Edit"
  3. Click on "Constraints" in the left pane
  4. Click on the Green Plus > "New Check Constraint"

What this does open up a new text section in the "Edit Table" box called "Check Condition" where I have to specify the constraint in a syntax that Oracle SQL Developer can understand.

This method has worked so far with other constraints that I have enforced but for some reason I cannot figure out how to word this particular one.

Any help will be appreciated, thanks.

This is all happening in Oracle SQL Developer, btw.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
144 views
Welcome To Ask or Share your Answers For Others

1 Answer

You would do this in code as;

alter t add constraint chk_t_cols
    check ( (Value is null and outlier is not null) or (value is not null and outlier is null) )

The part after the check is what you would type in the box in the GUI.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...