<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[刘佳的技术日志、博客]]></title> 
<link>http://www.52zhe.cn/index.php</link> 
<description><![CDATA[技术的事，喜欢就研究。]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[刘佳的技术日志、博客]]></copyright>
<item>
<link>http://www.52zhe.cn/read.php/.htm</link>
<title><![CDATA[Oracle开发中用户的删除，也就是模式的删除。]]></title> 
<author>kook &lt;admin@yourname.com&gt;</author>
<category><![CDATA[Oracle]]></category>
<pubDate>Tue, 15 May 2007 06:13:28 +0000</pubDate> 
<guid>http://www.52zhe.cn/read.php/.htm</guid> 
<description>
<![CDATA[ 
	相信大家都有这样的经验。在开发过程中都有需要重新创建用户（模式）。而当这个用户有链接的时候，就是提示你无法删除。是吧？<br/><br/>如下：<br/><div class="code"><br/>drop user username cascade<br/><br/>然后，你就查这个用户的session,用Kill把它干掉。<br/><br/>select sid,serial# from v$session where username=&#039;username&#039;;<br/><br/>SID SERIAL#<br/>-----------<br/>8 &nbsp; &nbsp; 25 <br/><br/>ALTER SYSTEM KILL SESSION &#039;8,25&#039;;<br/>这样再执行drop就没有问题了。<br/></div><br/><span style="color: #FF0000;">后补：<br/>查杀所有用户的Session<br/>select 'alter system kill session '''&#124;&#124;sid&#124;&#124;','&#124;&#124;serial#&#124;&#124;''' immediate;' from v$session where username='TEST';</span><br/><br/>可是这样很麻烦。如果确定整个数据库没有什么重要链接，告诉你一招，系统级别的杀人方法，限于linux<br/><div class="code">ps -ef&#124;grep LOCAL=NO&#124;cut -c 9-15&#124;xargs kill -9</div><br/>这样就杀掉所有的oracle的链接，无一幸免。<br/><br/>其实这样也不好，如果可以以用户连接，只是删除掉对象内表，视图，包，触发器，存储过程就好了。<br/>事实上一个网上的哥们写了这样一个东西。如下：<br/><div class="code"><br/>DECLARE<br/>TYPE name_list IS TABLE OF VARCHAR2(40);<br/>TYPE type_list IS TABLE OF VARCHAR2(20);<br/><br/>Tab_name name_list:=name_list();<br/>Tab_type type_list:=type_list();<br/><br/>sql_str VARCHAR2(500);<br/>BEGIN<br/>sql_str := &#039;select uo.object_name,uo.object_type from user_objects uo where uo.object_type not in(&#039;&#039;INDEX&#039;&#039;,&#039;&#039;LOB&#039;&#039;) order by uo.object_type desc&#039;;<br/>EXECUTE IMMEDIATE sql_str BULK COLLECT INTO tab_name,tab_type;<br/><br/>FOR i IN Tab_name.FIRST.. Tab_name.LAST LOOP<br/>sql_str := &#039;DROP &#039; &#124;&#124; Tab_type(i) &#124;&#124; &#039; &#039; &#124;&#124; Tab_name(i);<br/>EXECUTE IMMEDIATE sql_str;<br/>END LOOP;<br/>END;<br/></div><br/>这招不错，可是这个有时候好用，有时候就不好用。至今，我都是交替使用。这招不行，用另外一招。希望哪位大侠提供个更好的解决办法。<br/>
]]>
</description>
</item><item>
<link>http://www.52zhe.cn/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] Oracle开发中用户的删除，也就是模式的删除。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.52zhe.cn/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>