<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>惜分飞 &#187; ORA-00955</title>
	<atom:link href="https://www.xifenfei.com/tag/ora-00955/feed" rel="self" type="application/rss+xml" />
	<link>https://www.xifenfei.com</link>
	<description>提供7*24专业数据库(Oracle,SQL Server,MySQL,PostgreSQL等)恢复和技术支持@Tel:17813235971</description>
	<lastBuildDate>Thu, 22 Oct 2026 15:45:06 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>使用dml语句删除index测试(取代ddl)</title>
		<link>https://www.xifenfei.com/2015/08/%e4%bd%bf%e7%94%a8dml%e8%af%ad%e5%8f%a5%e5%88%a0%e9%99%a4index%e6%b5%8b%e8%af%95-%e5%8f%96%e4%bb%a3ddl.html</link>
		<comments>https://www.xifenfei.com/2015/08/%e4%bd%bf%e7%94%a8dml%e8%af%ad%e5%8f%a5%e5%88%a0%e9%99%a4index%e6%b5%8b%e8%af%95-%e5%8f%96%e4%bb%a3ddl.html#comments</comments>
		<pubDate>Sun, 16 Aug 2015 17:01:14 +0000</pubDate>
		<dc:creator><![CDATA[惜分飞]]></dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[dml删index]]></category>
		<category><![CDATA[ORA-00955]]></category>

		<guid isPermaLink="false">https://www.xifenfei.com/?p=6032</guid>
		<description><![CDATA[联系：手机/微信(+86 17813235971) QQ(107644445)  &#8230; <a href="https://www.xifenfei.com/2015/08/%e4%bd%bf%e7%94%a8dml%e8%af%ad%e5%8f%a5%e5%88%a0%e9%99%a4index%e6%b5%8b%e8%af%95-%e5%8f%96%e4%bb%a3ddl.html">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="xifenfeicopyright">
<p>联系：<a href="https://www.xifenfei.com/about_xifenfei" target="_blank">手机/微信(+86 17813235971)   QQ(107644445)</a><a target="_blank" href="http://wpa.qq.com/msgrd?v=3&#038;uin=107644445&#038;site=qq&#038;menu=yes"><img src="https://www.xifenfei.com/wp-content/themes/img/site_qq.jpg" alt="QQ咨询惜分飞" title="QQ咨询惜分飞"/></a></p>
<p>标题：<a href="https://www.xifenfei.com/2015/08/%e4%bd%bf%e7%94%a8dml%e8%af%ad%e5%8f%a5%e5%88%a0%e9%99%a4index%e6%b5%8b%e8%af%95-%e5%8f%96%e4%bb%a3ddl.html" target="_blank">使用dml语句删除index测试(取代ddl)</a></p>
<p>作者：<a href="https://www.xifenfei.com" target="_blank">惜分飞</a>©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]</p>
</div>
<p>在有些极端情况下,数据库由于某种原因无法执行ddl操作,但是可以执行dml语句,我们可以通过dml语句来替代ddl操作(非官方支持,纯属个人闲着无聊中的测试,请勿模仿,否则后果自负)<br />
<strong>创建测试用户xifenfei</strong></p>
<pre class="brush: sql; title: ; notranslate">
[oracle@web103 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Sun Aug 16 23:04:25 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL&gt; create user xifenfei identified by &quot;www.xifenfei.com&quot;;

User created.

SQL&gt; grant dba to xifenfei;

Grant succeeded.
</pre>
<p><strong>创建测试index，并使用10046跟踪</strong></p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; conn xifenfei/&quot;www.xifenfei.com&quot;
Connected.
SQL&gt; create table t_xifenfei as select * from dba_objects;

Table created.

SQL&gt;  alter session set events '10046 trace name context forever, level 12';

Session altered.

SQL&gt;  select value from v$diag_info where name='Default Trace File';

VALUE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/test/test/trace/test_ora_18838.trc

SQL&gt; create index ind_xifenfei_1 on t_xifenfei(object_id,data_object_id);

Index created.

SQL&gt; exit
SQL&gt; exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
</pre>
<p><strong>分析trace文件,找出来核心操作步骤</strong></p>
<pre class="brush: bash; title: ; notranslate">
--插入创建index的记录到obj$中
insert into obj$(owner#,name,namespace,obj#,type#,ctime,mtime,stime,status,
  remoteowner,linkname,subname,dataobj#,flags,oid$,spare1,spare2,spare3) 
values
(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17,:18)

--插入index的信息到seg$中
insert into seg$ (file#,block#,type#,ts#,blocks,extents,minexts,maxexts,
  extsize,extpct,user#,iniexts,lists,groups,cachehint,hwmincr, spare1, 
  scanhint, bitmapranges) 
values
 (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,DECODE(:17,0,NULL,
  :17),:18,:19)

--继续分配index的空间
update seg$ set type#=:4,blocks=:5,extents=:6,minexts=:7,maxexts=:8,extsize=
  :9,extpct=:10,user#=:11,iniexts=:12,lists=decode(:13, 65535, NULL, :13),
  groups=decode(:14, 65535, NULL, :14), cachehint=:15, hwmincr=:16, spare1=
  DECODE(:17,0,NULL,:17),scanhint=:18, bitmapranges=:19 
where
 ts#=:1 and file#=:2 and block#=:3

--插入index对应的列信息到icol$中
insert into icol$(obj#,bo#,intcol#,pos#,segcol#,segcollength,offset,col#,
  spare1,spare2,spare3) 
values
(:1,:2,:3,:4,0,0,0,:5,:6,:7,:8)

--插入index信息到ind$中
insert into ind$(bo#,obj#,ts#,file#,block#,intcols,type#,flags,property,
  pctfree$,initrans,maxtrans,blevel,leafcnt,distkey,lblkkey,dblkkey,clufac,
  cols,analyzetime,samplesize,dataobj#,degree,instances,rowcnt,pctthres$,
  indmethod#,trunccnt,spare1,spare4,spare2,spare6)
values
(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17,:18,:19,:20,:21,
  :22,decode(:23,1,null,:23),decode(:24,1,null,:24),:25, :32*256+:26,:27,:28,
  :29,:30,:31,:33)
</pre>
<p>通过这里我们基本上可以整体概况出来创建index主要操作了obj$,seg$,icol$,ind$几张基表,那么如果我们想通过dml语句删除index,那可以尝试人工删除这些新增记录<br />
<br />
<strong>分析人工dml语句删除index</strong></p>
<pre class="brush: sql; title: ; notranslate">
[oracle@web103 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Sun Aug 16 23:31:49 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL&gt; conn xifenfei/&quot;www.xifenfei.com&quot;
Connected.
SQL&gt; select object_id,data_object_id from user_objects where object_name='IND_XIFENFEI_1';

 OBJECT_ID DATA_OBJECT_ID
---------- --------------
    114642         114642

SQL&gt; select object_id,data_object_id from user_objects where object_name='T_XIFENFEI';

 OBJECT_ID DATA_OBJECT_ID
---------- --------------
    114641         114641

SQL&gt;  SELECT OBJ#,DATAOBJ# FROM SYS.OBJ$ WHERE NAME='IND_XIFENFEI_1';

      OBJ#   DATAOBJ#
---------- ----------
    114642     114642
--通过上面语句我们可以确定,IND_XIFENFEI_1 index的obj#和dataobj#都是为114642,而且可以直接查询obj$基表获得

SQL&gt; SELECT OBJ#,DATAOBJ#,TS#,FILE#,BLOCK# FROM SYS.IND$ WHERE OBJ#=114642;

      OBJ#   DATAOBJ#        TS#      FILE#     BLOCK#
---------- ---------- ---------- ---------- ----------
    114642     114642          4          4     323994
--ind$结合obj$.obj#的信息,可以获得ts#,file#,block#

SQL&gt; SELECT TABLESPACE_NAME,HEADER_FILE,HEADER_BLOCK FROM DBA_SEGMENTS WHERE SEGMENT_NAME='IND_XIFENFEI_1';

TABLESPACE_NAME                HEADER_FILE HEADER_BLOCK
------------------------------ ----------- ------------
USERS                                    4       323994

SQL&gt; SELECT TS# FROM V$TABLESPACE WHERE NAME='USERS';

       TS#
----------
         4
--这里证明ind$中的相关ts#,file#,block#和seg#中存储一致

SQL&gt;  SELECT COL#,POS# FROM  SYS.icol$ WHERE  OBJ#=114642;

      COL#       POS#
---------- ----------
         4          1
         5          2

SQL&gt; SELECT COL#,NAME from SYS.COL$ where OBJ# =114641;

      COL# NAME
---------- ------------------------------
         1 OWNER
         2 OBJECT_NAME
         3 SUBOBJECT_NAME
         4 OBJECT_ID
         5 DATA_OBJECT_ID
         6 OBJECT_TYPE
         7 CREATED
         8 LAST_DDL_TIME
         9 TIMESTAMP
        10 STATUS
        11 TEMPORARY
        12 GENERATED
        13 SECONDARY
        14 NAMESPACE
        15 EDITION_NAME

15 rows selected.
--这里证明icol$中存储的列，正好和我们创建index指定列一致
</pre>
<p><strong>人工dml删除index</strong></p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; conn  / as sysdba
Connected.
SQL&gt; delete from obj$ where obj#=114642 and dataobj#=114642;

1 row deleted.

SQL&gt; delete from sys.seg$ where file#=4 and ts#=4 and block#=323994;

1 row deleted.

SQL&gt; delete from icol$ where obj#=114642;

2 rows deleted.

SQL&gt; delete from ind$ where obj#=114642 and file#=4 and ts#=4 and block#=323994;

1 row deleted.

SQL&gt; commit;

Commit complete.
</pre>
<p><strong>检查dml语句删除index效果</strong></p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt;  select object_id,data_object_id from user_objects where object_name='IND_XIFENFEI_1';

no rows selected

SQL&gt;  SELECT TABLESPACE_NAME,HEADER_FILE,HEADER_BLOCK FROM DBA_SEGMENTS WHERE SEGMENT_NAME='IND_XIFENFEI_1';

no rows selected

SQL&gt; select * from dba_indexes where index_name='IND_XIFENFEI_1';

no rows selected
</pre>
<p>从数据字典层面看，index IND_XIFENFEI_1确实已经被删除<br />
<br />
<strong>尝试重建同名index</strong><br />
从数据字典层面查询,该index已经被删除,但是创建报ORA-00955: name is already used by an existing object错误</p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; create index xifenfei.ind_xifenfei_1 on xifenfei.t_xifenfei(object_id,data_object_id);
create index xifenfei.ind_xifenfei_1 on xifenfei.t_xifenfei(object_id,data_object_id)
                      *
ERROR at line 1:
ORA-00955: name is already used by an existing object
</pre>
<p><strong>解决重建同名index报ORA-00955错误</strong></p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; ALTER SESSION SET EVENTS '955 trace name errorstack level 3';

Session altered.

SQL&gt; create index xifenfei.ind_xifenfei_1 on xifenfei.t_xifenfei(object_id,data_object_id);
create index xifenfei.ind_xifenfei_1 on xifenfei.t_xifenfei(object_id,data_object_id)
                      *
ERROR at line 1:
ORA-00955: name is already used by an existing object


SQL&gt;  select value from v$diag_info where name='Default Trace File';

VALUE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/test/test/trace/test_ora_20277.trc

--分析trace文件发现创建index执行计划部分
============
Plan Table
============
------------------------------------------------+-----------------------------------+
| Id  | Operation               | Name          | Rows  | Bytes | Cost  | Time      |
------------------------------------------------+-----------------------------------+
| 0   | CREATE INDEX STATEMENT  |               |       |       |   548 |           |
| 1   |  INDEX BUILD NON UNIQUE | IND_XIFENFEI_1|       |       |       |           |
| 2   |   SORT CREATE INDEX     |               |  127K | 3302K |       |           |
| 3   |    INDEX FAST FULL SCAN | IND_XIFENFEI_1|       |       |       |           |
------------------------------------------------+-----------------------------------+
--从这里大概知道原因了，创建index之时，由于shared pool里面依旧记录了老的index信息，因此再次创建index之时，
--直接从老index读取信息，而且明确也依旧是在shared pool里面检查未通过，从而出现了ORA-00955错误

SQL&gt; alter system flush shared_pool;

System altered.

SQL&gt; create index xifenfei.ind_xifenfei_1 on xifenfei.t_xifenfei(object_id,data_object_id);

Index created.

SQL&gt; select obj#,dataobj# from SYS.obj$ where name='IND_XIFENFEI_1';

      OBJ#   DATAOBJ#
---------- ----------
    114643     114643

SQL&gt; select object_type,object_name from dba_objects where object_id=114643;

OBJECT_TYPE
-------------------
OBJECT_NAME
--------------------------------------------------------------------------------
INDEX
IND_XIFENFEI_1


SQL&gt; select index_name from dba_indexes where table_name='T_XIFENFEI' AND OWNER='XIFENFEI';

INDEX_NAME
------------------------------
IND_XIFENFEI_1
</pre>
<p><strong>补充说明</strong><br />
1.在不同的数据库版本,不同的平台可能操作语句以后一定的出入,依据你测试为准<br />
2.在dml删除index操作中,可能还涉及到一些其他外围表处理,比如统计信息等<br />
3.切勿在生产库中测试,否则可能导致数据库数据字典混乱,后果非常严重</p>
<div id="crp_related"><ul><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2013/06/%e9%80%9a%e8%bf%87%e5%9f%ba%e8%a1%a8%e8%8e%b7%e5%8f%96segment-header-block.html" rel="bookmark" class="crp_title">通过基表获取segment header block</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/09/object_id%e5%92%8cdata_object_id%e5%8c%ba%e5%88%ab%e4%b8%8e%e8%81%94%e7%b3%bb.html" rel="bookmark" class="crp_title">object_id和data_object_id区别与联系</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/05/%e4%bd%bf%e7%94%a8dblink%e5%af%bc%e8%87%b4%e7%9a%84-opaque_transform.html" rel="bookmark" class="crp_title">使用dblink导致的/*+ OPAQUE_TRANSFORM */</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/12/%e5%88%9b%e5%bb%ba%e6%94%af%e6%8c%81null-index.html" rel="bookmark" class="crp_title">创建包含null值index</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/09/bbed_wrap%e8%84%9a%e6%9c%ac%e8%8e%b7%e5%8f%96%e6%95%b0%e6%8d%ae%e5%9d%97%e5%86%85%e5%ae%b9.html" rel="bookmark" class="crp_title">bbed_wrap脚本获取数据块内容</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/08/%e8%a1%a8%e5%9c%a8%e7%ba%bf%e9%87%8d%e5%ae%9a%e4%b9%89%e6%97%a0%e4%b8%bb%e9%94%ae.html" rel="bookmark" class="crp_title">表在线重定义(无主键)</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2013/07/oracle-12c-%e5%9c%a8datapump%e6%96%b9%e9%9d%a2%e5%a2%9e%e5%bc%ba%e5%8f%82%e6%95%b0.html" rel="bookmark" class="crp_title">ORACLE 12C 在datapump方面增强参数</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2016/02/exp%e8%b7%b3%e8%bf%87%e6%9f%90%e4%ba%9b%e8%a1%a8%e5%af%bc%e5%87%ba%e6%95%b0%e6%8d%ae.html" rel="bookmark" class="crp_title">exp跳过某些表导出数据</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/05/sql-profile-%e4%bd%bf%e7%94%a8.html" rel="bookmark" class="crp_title">sql profile 使用</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/12/%e9%80%9a%e8%bf%87rowid%e6%89%be%e5%9b%9e%e5%9d%8f%e5%9d%97%e6%95%b0%e6%8d%ae.html" rel="bookmark" class="crp_title">通过ROWID找回坏块数据</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/04/oracle_rowid%e5%88%86%e6%9e%90.html" rel="bookmark" class="crp_title">ORACLE ROWID 分析</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2018/06/truncate-table-recovery.html" rel="bookmark" class="crp_title">truncate table 无论drop storage还是reuse storage不影响数据恢复</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>https://www.xifenfei.com/2015/08/%e4%bd%bf%e7%94%a8dml%e8%af%ad%e5%8f%a5%e5%88%a0%e9%99%a4index%e6%b5%8b%e8%af%95-%e5%8f%96%e4%bb%a3ddl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
