<tfoot id='QM229'></tfoot>
<i id='QM229'><tr id='QM229'><dt id='QM229'><q id='QM229'><span id='QM229'><b id='QM229'><form id='QM229'><ins id='QM229'></ins><ul id='QM229'></ul><sub id='QM229'></sub></form><legend id='QM229'></legend><bdo id='QM229'><pre id='QM229'><center id='QM229'></center></pre></bdo></b><th id='QM229'></th></span></q></dt></tr></i><div id='QM229'><tfoot id='QM229'></tfoot><dl id='QM229'><fieldset id='QM229'></fieldset></dl></div>

      • <bdo id='QM229'></bdo><ul id='QM229'></ul>

    1. <legend id='QM229'><style id='QM229'><dir id='QM229'><q id='QM229'></q></dir></style></legend>

      <small id='QM229'></small><noframes id='QM229'>

      Oracle:基于函数的索引选择性唯一性

      时间:2023-10-25

      <small id='XOavX'></small><noframes id='XOavX'>

      1. <legend id='XOavX'><style id='XOavX'><dir id='XOavX'><q id='XOavX'></q></dir></style></legend>
          • <bdo id='XOavX'></bdo><ul id='XOavX'></ul>
            <i id='XOavX'><tr id='XOavX'><dt id='XOavX'><q id='XOavX'><span id='XOavX'><b id='XOavX'><form id='XOavX'><ins id='XOavX'></ins><ul id='XOavX'></ul><sub id='XOavX'></sub></form><legend id='XOavX'></legend><bdo id='XOavX'><pre id='XOavX'><center id='XOavX'></center></pre></bdo></b><th id='XOavX'></th></span></q></dt></tr></i><div id='XOavX'><tfoot id='XOavX'></tfoot><dl id='XOavX'><fieldset id='XOavX'></fieldset></dl></div>
          • <tfoot id='XOavX'></tfoot>

              <tbody id='XOavX'></tbody>

              • 本文介绍了Oracle:基于函数的索引选择性唯一性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我必须维护历史,所以我使用 is_deleted 列,它可以有Y"或N".但是对于 is_deleted 'N' 的任何实例,我应该有 (a,b,c) 复合列的 uniwue 条目.

                I have to maintain history and so I am using is_deleted column which can have 'Y' or 'N'. But for any instance of is_deleted 'N' I should have uniwue entry for (a,b,c) composite columns.

                当我尝试创建基于函数的唯一索引时,出现错误.

                When I am tryin to create function based unique index I am getting error.

                CREATE UNIQUE INDEX fn_unique_idx ON table1  (CASE WHEN is_deleted='N' then (id, name, type) end);
                

                错误在第 1 行:ORA-00907: 缺少右括号

                ERROR at line 1: ORA-00907: missing right parenthesis

                请帮忙.

                谢谢

                推荐答案

                你需要类似的东西

                CREATE UNIQUE INDEX fn_unique_idx 
                    ON table1 (CASE WHEN is_deleted='N' THEN id ELSE null END,
                               CASE WHEN is_deleted='N' THEN name ELSE null END,
                               CASE WHEN is_deleted='N' THEN type ELSE null END);
                

                约束作用的例子

                SQL> create table table1 (
                  2    id number,
                  3    name varchar2(10),
                  4    type varchar2(10),
                  5    is_deleted varchar2(1)
                  6  );
                
                Table created.
                
                SQL> CREATE UNIQUE INDEX fn_unique_idx
                  2      ON table1 (CASE WHEN is_deleted='N' THEN id ELSE null END,
                  3                 CASE WHEN is_deleted='N' THEN name ELSE null END,
                  4                 CASE WHEN is_deleted='N' THEN type ELSE null END);
                
                Index created.
                
                SQL> insert into table1 values( 1, 'Foo', 'Bar', 'N' );
                
                1 row created.
                
                SQL> insert into table1 values( 1, 'Foo', 'Bar', 'Y' );
                
                1 row created.
                
                SQL> insert into table1 values( 1, 'Foo', 'Bar', 'Y' );
                
                1 row created.
                
                SQL> insert into table1 values( 1, 'Foo', 'Bar', 'N' );
                insert into table1 values( 1, 'Foo', 'Bar', 'N' )
                *
                ERROR at line 1:
                ORA-00001: unique constraint (SCOTT.FN_UNIQUE_IDX) violated
                
                
                SQL> insert into table1 values( 1, 'Foo', 'Zee', 'N' );
                
                1 row created.
                

                这篇关于Oracle:基于函数的索引选择性唯一性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:用于查找冗余索引的 T-SQL 下一篇:聚集索引和非聚集索引的区别

                相关文章

                <legend id='GImVq'><style id='GImVq'><dir id='GImVq'><q id='GImVq'></q></dir></style></legend>
                    • <bdo id='GImVq'></bdo><ul id='GImVq'></ul>
                    <tfoot id='GImVq'></tfoot>
                    <i id='GImVq'><tr id='GImVq'><dt id='GImVq'><q id='GImVq'><span id='GImVq'><b id='GImVq'><form id='GImVq'><ins id='GImVq'></ins><ul id='GImVq'></ul><sub id='GImVq'></sub></form><legend id='GImVq'></legend><bdo id='GImVq'><pre id='GImVq'><center id='GImVq'></center></pre></bdo></b><th id='GImVq'></th></span></q></dt></tr></i><div id='GImVq'><tfoot id='GImVq'></tfoot><dl id='GImVq'><fieldset id='GImVq'></fieldset></dl></div>

                    <small id='GImVq'></small><noframes id='GImVq'>