Oracle 11g不能在建立具有重複列的函數索引了

來源:互聯網
上載者:User

把一個測試系統的資料從Oracle 10g遷移到11g中後,聽開發人員說他們有個建立索引的SQL語句執行失敗,但是在10g裡面是能夠正常執行。這個索引是一個具有重複列的函數索引,可能是手誤並且這個索引沒怎麼用,所以就一直沒注意這個索引。自己感覺挺有意思的,於是就自己實驗了一下:

1、先來看11g的情況:

[oracle@instsvr1 ~]$ sql

SQL*Plus: Release 11.2.0.2.0 Production on Fri Mar 16 11:29:33 2012

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

srcbdb@SYS> conn vip
Enter password: 
Connected.

非函數索引如果具有重複的列是不允許建立的:

srcbdb@VIP> create index lzb on T_SYS_PARAM (param_id,PARAM_ID);
create index lzb on T_SYS_PARAM (param_id,PARAM_ID)
                                          *
ERROR at line 1:
ORA-00957: duplicate column name


在11g裡面即使是函數索引,但是具有重複的列也是不允許建立的:

srcbdb@VIP>   create index lzb on t_sys_param(nvl(PARAM_NAME,'*'),nvl(PARAM_NAME,'*'));
  create index lzb on t_sys_param(nvl(PARAM_NAME,'*'),nvl(PARAM_NAME,'*'))
                                                                     *
ERROR at line 1:
ORA-54015: Duplicate column expression was specified

2、再來看10g的情況

[oracle@dctest1 ~]$ sql


SQL*Plus: Release 10.2.0.4.0 - Production on Mon Mar 19 19:32:20 2012


Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.



Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


dgut@SYS> conn vip
Enter password: 
Connected.

在10g裡面非函數索引如果具有重複的列也是不允許建立的:
dgut@VIP> create index lzb on T_SYS_PARAM (param_id,PARAM_ID);
create index lzb on T_SYS_PARAM (param_id,PARAM_ID)
                                          *
ERROR at line 1:
ORA-00957: duplicate column name


最後來看神奇的一幕,在10g裡面如果是函數索引,即使是具有重複的列,索引依然能建立成功:
dgut@VIP> create index lzb on t_sys_param(nvl(PARAM_NAME,'*'),nvl(PARAM_NAME,'*'));

Index created.

總結:雖然建立具有重複列的函數索引沒什麼意義,甚至更差,但是這個11g和10g的使用差別挺有意思的就記錄了下來,只能所11g更嚴謹了,呵呵!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.