Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is there a PL/SQL equivalent to filtered indexes?

Dibs_501Feb 29 2016 — edited Feb 29 2016

Greetings!

Last week I queries this community as I was looking for a way to set up an index on my table that performed the following: for any given value of aval_tplts_id, there are not 2 other rows (X and Y) such that X.aval_tplts_id_defined_by=Y.aval_tplts_alt_id_defined_by and
X.aval_tplts_alt_id_defined_by=Y.aval_tplts_id_defined_by.

I got several replies, all of them very helpful and was provided with the following piece of code:

CREATE UNIQUE INDEX dependency_unique
     ON template_dependencies ( aval_tplts_id
      , LEAST (aval_tplts_id_defined_by, aval_tplts_alt_id_defined_by)
      , GREATEST (aval_tplts_id_defined_by, aval_tplts_alt_id_defined_by)
      );


This works perfectly, except in cases where two rows of identical aval_tplts_id values also have a value of NULL for aval_tplts_alt_id_defined_by.


My initial thought was to insert a WHERE clause or similar somewhere in the index creation, though I don't see any way to do that directly in PL/SQL (I found some documentation for SQL Server involving this, though it doesn't appear to be a feature in Oracle).

Is there any way to create this index to ignore the value of aval_tplts_alt_id_defined_by when that value is NULL?

This post has been answered by Paulzip on Feb 29 2016
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 28 2016
Added on Feb 29 2016
10 comments
247 views