Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Andres.

Asked: September 24, 2017 - 6:12 am UTC

Last updated: September 29, 2017 - 1:09 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi!
First i want to thank you for the many Responses that where usefull for me.

Í need a constraint or trigger that controls if the row inserted or updated contains a range of numbers that is already contained in another row of the same table.

Example:
Create table test as select 1 as id, 10 as n_from, 20 as n_to from dual;

Table test has now a record with numbers from 10 (n_from) to 20 (n_to).

How can I prevent an insert of a row like this (id, n_from, n_to)
2,11,12
Or
2,13,20

Both ranges are contained into the range 10-20.
Í need to raise an error when an existing range contains the new/updated range.

Í know how to do this with procedures but i need doing this in a constraint (cannot use querys) or trigger (mutating) to avoid the problem even in manualy inserted/updated rows.

Sorry for my english.


and Connor said...

It's a lot more complicated that you think when you have multi-user systems.

Here's a previous example of how to tackle it:

https://asktom.oracle.com/pls/asktom/asktom.search?tag=avoiding-overlap-values

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Thanks!!!

Andres R Barcia, September 25, 2017 - 2:56 pm UTC

Hi!
I'm very grateful.
Next time i'll search better. I didn't find the article because i never searched using the word "overlap"

Regards.

Database feature?

John Keymer, September 27, 2017 - 8:50 am UTC

I posted the following idea asking for this as a database feature:

https://community.oracle.com/ideas/17453

I was hoping that with temporal validity it might become somewhat easier from a technical implementation perspective.
Connor McDonald
September 29, 2017 - 1:09 pm UTC

Basically I think this is just a specific case of assertions:

https://community.oracle.com/ideas/13028

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library