<?xml version="1.0" encoding="GBK" ?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dcterms="http://purl.org/dc/terms/">
 <channel>
  	  <title><![CDATA[ilonng]]></title>
	  <link>http://chenzs19850728.blog.163.com</link>
	  <description><![CDATA[thinking 我,典型的男人,典型的穷人,典型的80后,典型的单身汉,典型的安徽人,典型的当代大学生,典型的小人物,典型的……,典型的中国人！]]></description>
	  <language>zh-CN</language>
	  <pubDate>Fri, 8 Aug 2008 18:31:42 +0800</pubDate>
	  <lastBuildDate>Fri, 8 Aug 2008 18:31:42 +0800</lastBuildDate>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <generator><![CDATA[NetEase Space]]></generator>
	  <managingEditor><![CDATA[chenzs19850728]]></managingEditor>
	  <webMaster><![CDATA[小霸王]]></webMaster>
		  <ttl>120</ttl>
	  <image>
	  	<title><![CDATA[ilonng]]></title>
	  	<url>http://ava.blog.163.com/photo/R3iimTUoqOJtk0KBjk6tSg==/174795960537518343.jpg</url>
	  	<link>http://chenzs19850728.blog.163.com</link>
	  </image>
  <item>
  	<title><![CDATA[mysql连接通道中的字符集和校验规则]]></title>	
    <link>http://chenzs19850728.blog.163.com/blog/static/7629609200868104214954</link>
    <description><![CDATA[<div><P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 这里首先需要解释的是，我想应该就是连接通道的含义了。那什么是连接通道呢？<BR>&nbsp;&nbsp;&nbsp; 所谓连接通道，就是客户端和服务器端保持连接的一个通道，它是逻辑上的一个概念。客户端通过连接通道发送sql语句到服务器端，服务端执行，将结果再通过连接通道返回至客户端。the connection is the pass when you connect to the server.</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 这个过程中，有几个临界点（逻辑上概念），是我们需要注意的，mysql也就在这几个临界点上做了文章。<BR>&nbsp;&nbsp;&nbsp; 1、当语句离开客户端的时候：<BR>&nbsp;&nbsp;&nbsp; 从客户端出来的，包括sql语句本身（这里里面就包含字符串和关键字等了），以及character_set_client系统变量。为什么要包含这个变量呢？这个变量的作用说明2点，也是它的作用：一是表示该语句中的字符集是使用character_set_client指定的字符集编码的，二是通过此系统变量来告诉服务器所发送来的语句中的字符集编码。<BR>&nbsp;&nbsp;&nbsp; 2、当服务器端接受到客户端的语句的时候：<BR>&nbsp;&nbsp;&nbsp; mysql会使用character_set_connection/collation_connection指定的字符集以及校验规则，将客户端的字符串，做一个从character_set_client到character_set_connection的转换。<BR>&nbsp;&nbsp;&nbsp; 3、当服务器处理好结果以后，在把结果传给客户端前：<BR>&nbsp;&nbsp;&nbsp; mysql会先将结果转换成character_set_results指定的字符集，然后传回给客户端。</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 当字符串在mysql服务器的时候，最终以什么格式存储到mysql数据库中，这个是受到具体的数据表级别、列级别字符集设置的控制了。</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 从上面的介绍中，我们就知道和连接通道相关几个参数了，他们分别是character_set_client/connection/results，可以如下查看：<BR>mysql&gt; show variables like 'char%';<BR>+--------------------------+-------------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+-------------------+<BR>| character_set_client&nbsp;&nbsp;&nbsp;&nbsp; | latin1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_connection | latin1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_database&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_results&nbsp;&nbsp;&nbsp; | latin1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| .........................| ......&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+-------------------+<BR>8 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'colla%';<BR>+----------------------+-------------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+----------------------+-------------------+<BR>| collation_connection | latin1_swedish_ci |<BR>| collation_database&nbsp;&nbsp; | gbk_bin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| collation_server&nbsp;&nbsp;&nbsp;&nbsp; | latin1_swedish_ci |<BR>+----------------------+-------------------+<BR>3 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 下面我们来做个实验，来证明一下这个结果：<BR>&nbsp;&nbsp;&nbsp; 首先保证character_set_connection与character_set_results以及底层存储字符集的一致性，看看character_set_client的效果。<BR>mysql&gt; show variables like 'char%';<BR>+--------------------------+------------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+------------------+<BR>| character_set_client&nbsp;&nbsp;&nbsp;&nbsp; | latin1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_connection | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_database&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_results&nbsp;&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| .........................| ......&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+------------------+<BR>8 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; create table t (a varchar(10));&nbsp; --&nbsp; 这里没有指定字符集，就默认使用了database的字符集gbk了<BR>Query OK, 0 rows affected (0.08 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; insert into t values('中国');<BR>Query OK, 1 row affected (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; select * from t;<BR>+-------+<BR>| a&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+-------+<BR>| ???ú |<BR>+-------+<BR>1 row in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 由此可以看到由于latin1与gbk对汉字的编码方式不一样（或者说latin1根本就不能正确编码汉字），在这个collection过程中，从character_set_client到character_set_connection转换时，就把你输入的好好的汉字转换成乱码了。那么，如果让过程不发生转换呢？</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; set character_set_client=gbk;<BR>Query OK, 0 rows affected (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; insert into t values('人民');<BR>Query OK, 1 row affected (0.02 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; select * from t;<BR>+-------+<BR>| a&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+-------+<BR>| ???ú |<BR>| 人民&nbsp; |<BR>+-------+<BR>2 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 可见，这里是能正确存储和显示的，很简单，因为任何转换都没有发生，当然就不会出现乱码了。</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 接着做实验，我们让character_set_connection发生变化：<BR>mysql&gt; set character_set_connection=latin1;<BR>Query OK, 0 rows affected (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; insert into t values ('共和国');<BR>Query OK, 1 row affected (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; select * from t;<BR>+-------+<BR>| a&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+-------+<BR>| ???ú |<BR>| 人民&nbsp; |<BR>| ???&nbsp;&nbsp; |<BR>+-------+<BR>3 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 可见，这里character_set_client=gbk,character_set_connection=latin1,character_set_database=gbk。首先，client到connection过程中，汉字被转换成乱码（这个过程可能就会丢失信息）；然后存储数据的时候，又从connection到存储的字符集（gbk）发生一次转换，乱码被转换成“更”乱码。这里如果connection与client的字符集有种包容性关系的话，如character_set_client=gbk, character_set_connection=utf8,character_set_results=gbk,底层存储也是gbk编码，由于utf8“兼容”所有的字符集，故在转换过程中不会发生信息丢失，查询的时候也不会是乱码，如下：</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'char%';<BR>+--------------------------+-----------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+-----------------+<BR>| character_set_client&nbsp;&nbsp;&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_connection | utf8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_database&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_results&nbsp;&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| .........................| ......&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+-----------------+<BR>8 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; create table t (a varchar(10)) charset=gbk;<BR>Query OK, 0 rows affected (0.05 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; insert into t values('中国');<BR>Query OK, 1 row affected (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; select * from t;<BR>+------+<BR>| a&nbsp;&nbsp;&nbsp; |<BR>+------+<BR>| 中国 |<BR>+------+<BR>1 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 我来解释一下这个过程，假设“中国”的gbk编码是1234，而utf8的编码是4321，utf8的编码为1234的假设是“淘宝”。client的“中国”的编码1234进入connection，仍然是1234（但实际上它的含义已经发生变化为“淘宝”），存储的时候connection的1234编码到表存储也是1234，刚好正确表达了“中国”的意思，查询返回时，由于results也是gbk，所以不发生转换，正确显示。很显然，如果results又是一种与gbk不兼容的字符集如latin1，查询又会出问题，如下：</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; set character_set_results=latin1;<BR>Query OK, 0 rows affected (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; select * from t;<BR>+------+<BR>| a&nbsp;&nbsp;&nbsp; |<BR>+------+<BR>| ??&nbsp;&nbsp; |<BR>+------+<BR>1 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 当我们改变底层存储的字符集的时候，会怎样？请看如下实验：<BR>mysql&gt; show variables like 'char%';<BR>+--------------------------+---------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+---------------+<BR>| character_set_client&nbsp;&nbsp;&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_connection | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_database&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_results&nbsp;&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| .........................| ......&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+---------------+<BR>8 rows in set (0.01 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; create table t (a varchar(10)) charset=latin1;<BR>Query OK, 0 rows affected (0.05 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; insert into t values('淘宝');<BR>Query OK, 1 row affected, 1 warning (0.02 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; select * from t;<BR>+------+<BR>| a&nbsp;&nbsp;&nbsp; |<BR>+------+<BR>| ??&nbsp;&nbsp; |<BR>+------+<BR>1 row in set (0.00 sec)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp; 很显然，由于latin1字符集无法存储汉字，故出现乱码。</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp; 下面，我们只改变results字符集，看看效果如何：<BR>mysql&gt; show variables like 'char%';<BR>+--------------------------+----------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+----------------+<BR>| character_set_client&nbsp;&nbsp;&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_connection | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_database&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_results&nbsp;&nbsp;&nbsp; | latin1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| .........................| ......&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+----------------+<BR>8 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; create table t (a varchar(10)) charset=gbk;<BR>Query OK, 0 rows affected (0.08 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; insert into t values('淘宝');<BR>Query OK, 1 row affected (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; select * from t;<BR>+------+<BR>| a&nbsp;&nbsp;&nbsp; |<BR>+------+<BR>| ??&nbsp;&nbsp; |<BR>+------+<BR>1 row in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 很显然，底层为gbk编码的字符串转换成latin1的字符集的字符，变成乱码，传给客户端，再次转换成gbk字符集，变成“更”乱码，故显示乱码。</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 下面，我再介绍几个“简约”命令。<BR>&nbsp;&nbsp;&nbsp; SET NAMES 'x'，(SET NAMES 'charset_name' COLLATE 'collation_name')相当于：<BR>SET character_set_client = x;<BR>SET character_set_results = x;<BR>SET character_set_connection = x;</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'char%';<BR>+--------------------------+----------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+----------------+<BR>| character_set_client&nbsp;&nbsp;&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_connection | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_results&nbsp;&nbsp;&nbsp; | latin1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| .........................| ......&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+----------------+<BR>8 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; set names 'ascii';<BR>Query OK, 0 rows affected (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'char%';<BR>+--------------------------+----------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+----------------+<BR>| character_set_client&nbsp;&nbsp;&nbsp;&nbsp; | ascii&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_connection | ascii&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_results&nbsp;&nbsp;&nbsp; | ascii&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| .........................| ......&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+----------------+</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; SET CHARACTER SET 'x',相当于：<BR>SET character_set_client = x;<BR>SET character_set_results = x;<BR>SET collation_connection = @@collation_database;<BR>&nbsp;&nbsp;&nbsp; 这里collation_connection = @@collation_database的意思就是把collation_connection的设置的collation_database的值，由于collation肯定能确定character set，故其又相当于多做了个设置：把character_set_connetion设置成character_set_database的值。请看如下实验：</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'char%';<BR>+--------------------------+-------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+-------------+<BR>| character_set_client&nbsp;&nbsp;&nbsp;&nbsp; | latin1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_connection | latin1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_database&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_results&nbsp;&nbsp;&nbsp; | latin1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| .......................&nbsp; | ......&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+-------------+<BR>8 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'collat%';<BR>+----------------------+-------------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+----------------------+-------------------+<BR>| collation_connection | latin1_swedish_ci |<BR>| collation_database&nbsp;&nbsp; | gbk_bin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| collation_server&nbsp;&nbsp;&nbsp;&nbsp; | latin1_swedish_ci |<BR>+----------------------+-------------------+<BR>3 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; set character set 'ascii';<BR>Query OK, 0 rows affected (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'char%';<BR>+--------------------------+-------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+-------------+<BR>| character_set_client&nbsp;&nbsp;&nbsp;&nbsp; | ascii&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_connection | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_database&nbsp;&nbsp; | gbk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| character_set_results&nbsp;&nbsp;&nbsp; | ascii&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| .......................&nbsp; | ......&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+--------------------------+-------------+<BR>8 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'collat%';<BR>+----------------------+-------------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+----------------------+-------------------+<BR>| collation_connection | gbk_bin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| collation_database&nbsp;&nbsp; | gbk_bin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>| collation_server&nbsp;&nbsp;&nbsp;&nbsp; | latin1_swedish_ci |<BR>+----------------------+-------------------+<BR>3 rows in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 通过以上的介绍，所以为了防止出现乱码，我们可以把character_set_client,character_set_connection,character_set_database,character_set_results设置成同样的值，把collation_connection和collation_database也设置成同样的值，这样就“一劳永逸”了。程序连接mysql的时候，一般都会显示设置character_set_client的值，如java连接中，一般都有如下的一段代码来显示设置这个值：<BR>jdbc:mysql://10.1.6.174:3306/notify?connectTimeout=1000&amp;characterEncoding=utf8</FONT></P></div>]]></description>
	    <author><![CDATA[小霸王]]></author>
	    <comments>http://chenzs19850728.blog.163.com/blog/static/7629609200868104214954</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://chenzs19850728.blog.163.com/blog/static/7629609200868104214954</guid>
    <pubDate>Tue, 8 Jul 2008 22:42:14 +0800</pubDate>
    <dcterms:modified>2008-07-08T22:42:14+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[mysql字符集与校验规则的设置]]></title>	
    <link>http://chenzs19850728.blog.163.com/blog/static/7629609200868104124489</link>
    <description><![CDATA[<div><P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 默认情况下，我们可以在4个级别分别设定mysql的字符集和校验规则，分别是server、database、table和column。实际上，我们甚至还可以单独对一串字符串设定其字符集和校验规则。下面就分别来对四个级别的设定说明一下：<BR>&nbsp;&nbsp;&nbsp; server:<BR>&nbsp;&nbsp;&nbsp; 在启动mysql服务的时候，可以指定mysql server的字符集和校验规则，通过如下方式：<BR>mysqld --character-set-server=latin1 --collation-server=latin1_swedish_ci<BR>&nbsp;&nbsp;&nbsp; 如果不亲自指定它们，那么mysql就会使用默认值。一般是latin1和latin1_swedish_ci。当然这个默认值是可以修改的，但是方法只有一种，那就是重编译源代码。采用如下方式：<BR>./configure --with-charset=gbk&nbsp; --with-collation=gbk_bin<BR>&nbsp;&nbsp;&nbsp; 如何查询当前的server的字符集和校验规则的值，可以查看系统参数character_set_server和collation_server：<BR>mysql&gt; show variables like 'character_set_server%';<BR>+----------------------+--------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp; |<BR>+----------------------+--------+<BR>| character_set_server | latin1 |<BR>+----------------------+--------+<BR>1 row in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'collation_server%';<BR>+------------------+-------------------+<BR>| Variable_name&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+------------------+-------------------+<BR>| collation_server | latin1_swedish_ci |<BR>+------------------+-------------------+<BR>1 row in set (0.00 sec)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; server的字符集和校验规则的唯一作用就是，当database的字符集和校验规则没有指定的时候，就默认使用server的对应值。</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; database:<BR>&nbsp;&nbsp;&nbsp; 我们在创建和修改数据库的时候，可以指定其字符集和校验规则：<BR>CREATE DATABASE db_name<BR>&nbsp;&nbsp;&nbsp; [[DEFAULT] CHARACTER SET charset_name]<BR>&nbsp;&nbsp;&nbsp; [[DEFAULT] COLLATE collation_name];<BR>ALTER DATABASE db_name<BR>&nbsp;&nbsp;&nbsp; [[DEFAULT] CHARACTER SET charset_name]<BR>&nbsp;&nbsp;&nbsp; [[DEFAULT] COLLATE collation_name];<BR>&nbsp;&nbsp;&nbsp; 对应查看当前数据库的字符集和校验规则的系统参数是'character_set_database'和'collation_database'，如下：<BR>mysql&gt; show variables like 'character_set_database';<BR>+------------------------+-------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value |<BR>+------------------------+-------+<BR>| character_set_database | gbk&nbsp;&nbsp; |<BR>+------------------------+-------+<BR>1 row in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>mysql&gt; show variables like 'collation_database';<BR>+--------------------+---------+<BR>| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp; |<BR>+--------------------+---------+<BR>| collation_database | gbk_bin |<BR>+--------------------+---------+<BR>1 row in set (0.00 sec)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 数据库的字符集和校验规则的作用有二，其一是当没有在表级别知道它们，那么默认就使用数据库基本的值；其二是在“load data infile”时也起到了作用。</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; table:<BR>&nbsp;&nbsp;&nbsp; 在创建表或者修改表结构的时候，我们可以通过如下方式指定这个表的字符集和校验规则：<BR>CREATE TABLE tbl_name (column_list)<BR>&nbsp;&nbsp;&nbsp; [[DEFAULT] CHARACTER SET charset_name] [COLLATE collation_name]]</FONT></P>
<P><FONT face=宋体 size=2>ALTER TABLE tbl_name<BR>&nbsp;&nbsp;&nbsp; [[DEFAULT] CHARACTER SET charset_name] [COLLATE collation_name]</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; column:<BR>&nbsp;&nbsp;&nbsp; 具体的表的具体的某个字段，我们也可以指定其字符集和校验规则，如下：<BR>col_name {CHAR | VARCHAR | TEXT} (col_length)<BR>&nbsp;&nbsp;&nbsp; [CHARACTER SET charset_name] [COLLATE collation_name]</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 那么，这四个级别的字符集和校验规则的指定（级别高低server&gt;database&gt;table&gt;column）,mysql最终以何种形式来存储和显示字符串的呢？<BR>1、本级别中，如果同时指定character set和collate，那么就使用指定的值；<BR>2、本级别中，只指定character set而没有指定collate，那么就使用指定的character set值和其对应的默认的collation值；<BR>3、本级别中，只指定collate而没有指定character set，那么就使用指定的collation值和其所对应的character set值；<BR>4、本级别中，都没有指定这2个值，那么默认就使用上一级别的对应的值。</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 国家字符集：<BR>&nbsp;&nbsp;&nbsp; mysql中国家字符集的概念，其表示使用预先定义的字符集，在mysql5.1中使用utf8作为其预先的定义的字符集。<BR>&nbsp;&nbsp;&nbsp; 因此，下面几种类型的定义，其实是等效的：<BR>CHAR(10) CHARACTER SET utf8<BR>NATIONAL CHARACTER(10)<BR>NCHAR(10)<BR>&nbsp;&nbsp;&nbsp; 下面几种类型也是等效的：<BR>VARCHAR(10) CHARACTER SET utf8<BR>NATIONAL VARCHAR(10)<BR>NCHAR VARCHAR(10)<BR>NATIONAL CHARACTER VARYING(10)<BR>NATIONAL CHAR VARYING(10)</FONT></P>
<P><FONT face=宋体 size=2>&nbsp;&nbsp; 字符串的字符集和校验规则的设置问题，请稍等！</FONT></P></div>]]></description>
	    <author><![CDATA[小霸王]]></author>
	    <comments>http://chenzs19850728.blog.163.com/blog/static/7629609200868104124489</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://chenzs19850728.blog.163.com/blog/static/7629609200868104124489</guid>
    <pubDate>Tue, 8 Jul 2008 22:41:24 +0800</pubDate>
    <dcterms:modified>2008-07-08T22:41:24+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[mysql字符集和校验规则概念小介]]></title>	
    <link>http://chenzs19850728.blog.163.com/blog/static/762960920086810392831</link>
    <description><![CDATA[<div><FONT face=宋体 size=2>&nbsp;&nbsp;&nbsp; 刚刚接触mysql的人（like me），可能对这2个概念不是太理解，这里小小解释一下，希望能说明清楚这个问题。<BR>&nbsp;&nbsp;&nbsp; 字符集，character set，就是一套表示字符的符号和这些的符号的底层编码；而校验规则，则是在字符集内用于比较字符的一套规则。字符集还是比较容易理解的，主要是校验规则，下面我简单举个例子来说明一下：<BR>如在某个字符集“X”的A与a，他们的底层编码分别是A=0,a=100。这里符号“A”“a”和底层编码“0”“100”就是字符集的概念范围。假设我们要比较A与a的大小，我们得到a&gt;A，因为我们是根据其底层编码进行比较的，这就是这个字符集“X”的一种校验规则“Z”（根据底层编码来比较）。假设，现在有另外一种校验规则，是先取其相反数，然后再比较大小，那么就很显然的得到a&lt;A，这就是字符集“X”的另外一种校验规则“Z1”。由此可见，一种字符集可能存在多个与之对应的校验规则（一对多关系）。<BR>&nbsp;&nbsp;&nbsp; 关于字符集与校验规则，mysql能：<BR>1、使用字符集来存储字符串，支持多种字符集；<BR>2、使用校验规则来比较字符串，同种字符集还能使用多种校验规则来比较；<BR>3、在同一台服务器、同一个数据库或者甚至在同一个表中使用不同字符集或校对规则来混合组合字符串；<BR>4、可以在任何级别（服务器、数据库、表、字段、字符串），定义不同的字符集和校验规则。<BR>&nbsp;&nbsp;&nbsp; 查询你的mysql数据库所支持的字符集种类，可以如下：<BR>mysql&gt; show character set;<BR>+----------+-----------------------------+---------------------+--------+<BR>| Charset&nbsp; | Description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Default collation&nbsp;&nbsp; | Maxlen |<BR>+----------+-----------------------------+---------------------+--------+<BR>| big5&nbsp;&nbsp;&nbsp;&nbsp; | Big5 Traditional Chinese&nbsp;&nbsp;&nbsp; | big5_chinese_ci&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 |<BR>| dec8&nbsp;&nbsp;&nbsp;&nbsp; | DEC West European&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | dec8_swedish_ci&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| .........| ......................&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | ................&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; . |<BR>| eucjpms&nbsp; | UJIS for Windows Japanese&nbsp;&nbsp; | eucjpms_japanese_ci |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 |<BR>+----------+-----------------------------+---------------------+--------+<BR>36 rows in set (0.00 sec)<BR>&nbsp;&nbsp; 这里的maxlen表示要用最大多少个字节来存储字符集的单个词，default collation表示该字符集的默认校验规则。<BR>&nbsp;&nbsp; 你也可以利用like来进行筛选，如下：<BR>mysql&gt; show character set like 'latin%';<BR>+---------+-----------------------------+-------------------+--------+<BR>| Charset | Description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Default collation | Maxlen |<BR>+---------+-----------------------------+-------------------+--------+<BR>| latin1&nbsp; | cp1252 West European&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | latin1_swedish_ci |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| latin2&nbsp; | ISO 8859-2 Central European | latin2_general_ci |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| latin5&nbsp; | ISO 8859-9 Turkish&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | latin5_turkish_ci |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| latin7&nbsp; | ISO 8859-13 Baltic&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | latin7_general_ci |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>+---------+-----------------------------+-------------------+--------+<BR>4 rows in set (0.00 sec)<BR>&nbsp;&nbsp;&nbsp; 查询你的mysql数据库所支持字符集的校验规则，可以如下：<BR>mysql&gt; show collation;<BR>+----------------------+----------+-----+---------+----------+---------+<BR>| Collation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Charset&nbsp; | Id&nbsp; | Default | Compiled | Sortlen |<BR>+----------------------+----------+-----+---------+----------+---------+<BR>| big5_chinese_ci&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | big5&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; 1 | Yes&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| big5_bin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | big5&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp; 84 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| dec8_swedish_ci&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | dec8&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; 3 | Yes&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |<BR>| ........&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | ....&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp; .. | ...&nbsp;&nbsp;&nbsp;&nbsp; | ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; . |<BR>| eucjpms_bin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | eucjpms&nbsp; |&nbsp; 98 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>+----------------------+----------+-----+---------+----------+---------+<BR>127 rows in set (0.00 sec)<BR>&nbsp;&nbsp; 这里compiled表示该collation所对应的character set是否被编译到此mysql数据库，通过此点就可以知道该mysql数据库是否支持某个字符集。sortlen表示要在内存中排序时，该字符集的字符要占用多少个字节。<BR>&nbsp;&nbsp; 你也可以利用like来进行筛选，如下：<BR>mysql&gt; show collation like 'latin1%';<BR>+-------------------+---------+----+---------+----------+---------+<BR>| Collation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Charset | Id | Default | Compiled | Sortlen |<BR>+-------------------+---------+----+---------+----------+---------+<BR>| latin1_german1_ci | latin1&nbsp; |&nbsp; 5 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| latin1_swedish_ci | latin1&nbsp; |&nbsp; 8 | Yes&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| latin1_danish_ci&nbsp; | latin1&nbsp; | 15 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| latin1_german2_ci | latin1&nbsp; | 31 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 |<BR>| latin1_bin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | latin1&nbsp; | 47 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| latin1_general_ci | latin1&nbsp; | 48 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| latin1_general_cs | latin1&nbsp; | 49 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>| latin1_spanish_ci | latin1&nbsp; | 94 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 |<BR>+-------------------+---------+----+---------+----------+---------+<BR>8 rows in set (0.00 sec)<BR>&nbsp;&nbsp;&nbsp; 大家可能已经发现collation的名字似乎有规律可循，其实的确也是这样的，并且它也有些特征，如下：<BR>1、两个不同的字符集不能有相同的校验规则（字符集：校验规则 = 1：n）；<BR>2、每个字符集都有一个校验规则，就是对应的DEFAULT=YES的那个collation；<BR>3、collation命名规则：字符集名_对应的语言名_ci/cs/bin，其中ci表示大小写不敏感性，cs表示大小写敏感性，bin表示二进制。</FONT></div>]]></description>
	    <author><![CDATA[小霸王]]></author>
	    <comments>http://chenzs19850728.blog.163.com/blog/static/762960920086810392831</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://chenzs19850728.blog.163.com/blog/static/762960920086810392831</guid>
    <pubDate>Tue, 8 Jul 2008 22:39:02 +0800</pubDate>
    <dcterms:modified>2008-07-08T22:39:51+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[快速复制一张大表讨论]]></title>	
    <link>http://chenzs19850728.blog.163.com/blog/static/7629609200841461443371</link>
    <description><![CDATA[<div><P><FONT face=宋体>有这样的一类需求，快速复制一张表，而这张表的数据量又非常的大。比方说本来是分区表，要把它重新变成非分区表，怎么能够快速的完成这样的操作呢？我下面给出2种大致的方法：</FONT></P>
<P><FONT face=宋体>第一，就是利用CTAS方式来创建一张新表，当然要想加快速度，在数据库不是force logging的前提下，可以使用nologging方式来创建表<BR>SQL&gt; create table auction_auctions_bak<BR>&nbsp; 2&nbsp; tablespace tbs_taobao<BR>&nbsp; 3&nbsp; nologging<BR>&nbsp; 4&nbsp; as<BR>&nbsp; 5&nbsp; select * from auction_auctions;</FONT></P>
<P><FONT face=宋体>Table created.</FONT></P>
<P><FONT face=宋体>SQL&gt; select count(*) from auction_auctions;</FONT></P>
<P><FONT face=宋体>&nbsp; COUNT(*)<BR>----------<BR>&nbsp;&nbsp; 4179779</FONT></P>
<P><FONT face=宋体>SQL&gt; select count(*) from auction_auctions_bak;</FONT></P>
<P><FONT face=宋体>&nbsp; COUNT(*)<BR>----------<BR>&nbsp;&nbsp; 4179779</FONT></P>
<P><FONT face=宋体>在建立完成表以后，要注意将表的属性重新变成logging：<BR>SQL&gt; select logging from tabs where table_name='AUCTION_AUCTIONS_BAK';</FONT></P>
<P><FONT face=宋体>LOG<BR>---<BR>NO</FONT></P>
<P><FONT face=宋体>SQL&gt; alter table auction_auctions_bak logging;</FONT></P>
<P><FONT face=宋体>Table altered.</FONT></P>
<P><FONT face=宋体>当然也可以这样：CREATE TABLE ... AS SELECT .. WHERE 1=2;然后使用 INSERT /*+ APPEND */ INTO .. SELECT ...。</FONT></P>
<P><FONT face=宋体>最后将表名更改过来，建立一下新的索引，然后就可以了。</FONT></P>
<P><FONT face=宋体>SQL&gt; drop table auction_auctions;</FONT></P>
<P><FONT face=宋体>Table dropped.</FONT></P>
<P><FONT face=宋体>SQL&gt; rename auction_auctions_bak to auction_auctions;</FONT></P>
<P><FONT face=宋体>Table renamed.</FONT></P>
<P><FONT face=宋体>第二，在原理上，它其实和第一种方式差不多，就是阻止数据库记录日志来加快速度，大概过程如下：<BR>1、exp出原表（建议compress=n）<BR>2、drop 原表<BR>3、以nologging的方式，新建与原表同名的空表<BR>4、imp原表至空表中，注意要把ignore设置为y<BR>5、更改新表的属性为logging</FONT></P>
<P><FONT face=宋体>我这次分别都对两种方式做了测试，结果第二种方式远远快于第一种方式，大概是其10倍的速度。注意以上两种方式都是在数据库没有force logging的前提下完成的。如果数据库被force logging了，那么怎样才能加快复制速度，这个大家可以说说。</FONT></P></div>]]></description>
	    <author><![CDATA[小霸王]]></author>
	    <comments>http://chenzs19850728.blog.163.com/blog/static/7629609200841461443371</comments>
    <slash:comments>3</slash:comments>
    <guid isPermaLink="true">http://chenzs19850728.blog.163.com/blog/static/7629609200841461443371</guid>
    <pubDate>Wed, 14 May 2008 18:14:43 +0800</pubDate>
    <dcterms:modified>2008-05-14T18:14:43+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[怪异ORA-01502，创建唯一约束却无唯一索引]]></title>	
    <link>http://chenzs19850728.blog.163.com/blog/static/762960920084135524753</link>
    <description><![CDATA[<div><P><FONT face=宋体 size=2>我们都知道，唯一约束是基于唯一索引的，如果没有唯一索引，那么在建立唯一约束的时候会自动创建相应的唯一索引。而今天我在创建唯一约束以后，发生了一件怪异的事情。</FONT></P>
<P><FONT face=宋体 size=2>下面是过程描述。<BR>因业务要求，要求在一表（test）上一列增加一个唯一约束，由于是在开发环境，数据量也很小，我采用了如下的方法来创建：<BR>SQL&gt; alter table test<BR>&nbsp; 2&nbsp;&nbsp;&nbsp; add constraint UK_ET_AIRSUP_USERS_supp_WW unique (air_supply_wangwang)<BR>&nbsp; 3&nbsp;&nbsp;&nbsp; using index <BR>&nbsp; 4&nbsp;&nbsp;&nbsp; tablespace TBS_ET_IND<BR>&nbsp; 5&nbsp;&nbsp;&nbsp; online<BR>&nbsp; 6&nbsp;&nbsp;&nbsp; compute statistics;</FONT></P>
<P><FONT face=宋体 size=2>Table altered.</FONT></P>
<P><FONT face=宋体 size=2>理论上按照这种方式，已经完全完成工作了。可是，后来测试人员测试的是，却告诉我发生了如下错误：<BR>ORA-01502: index '.' or partition of such index is in unusable state</FONT></P>
<P><FONT face=宋体 size=2>查询错误描述，可以很清楚的发现问题的原因：<BR>[oracle@crmtest worksh]$ oerr ora 01502<BR>01502, 00000, "index '%s.%s' or partition of such index is in unusable state"<BR>// MERGE: 1489 RENUMBERED TO 1502<BR>// *Cause: An attempt has been made to access an index or index partition<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; that has been marked unusable by a direct load or by a DDL<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; operation<BR>// *Action: DROP the specified index, or REBUILD the specified index, or<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; REBUILD the unusable index partition</FONT></P>
<P><FONT face=宋体 size=2>昨天都是没有问题，因此我就怀疑我今天这个唯一约束出了问题，查询了一下表的index：<BR>SQL&gt; select index_name,index_type,status from user_indexes where table_name = upper('test');</FONT></P>
<P><FONT face=宋体 size=2>INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX_TYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STATUS<BR>------------------------------ --------------------------- --------<BR>PK_ET_AIRSUPPLY_USERS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID<BR>UK_ET_AIRSUPPLY_USERS_NICK&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID</FONT></P>
<P><FONT face=宋体 size=2>怪异的时候发生了，怎么没有相应的唯一索引呢？确定看看唯一约束有没有什么问题：<BR>SQL&gt; alter table test<BR>&nbsp; 2&nbsp; modify constraint UK_ET_AIRSUP_USERS_SUPP_WW enable validate;</FONT></P>
<P><FONT face=宋体 size=2>Table altered.</FONT></P>
<P><FONT face=宋体 size=2>再看看结果如何：<BR>SQL&gt; select index_name,index_type,status from user_indexes where table_name = upper('test');</FONT></P>
<P><FONT face=宋体 size=2>INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX_TYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STATUS<BR>------------------------------ --------------------------- --------<BR>PK_ET_AIRSUPPLY_USERS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID<BR>UK_ET_AIRSUPPLY_USERS_NICK&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID</FONT></P>
<P><FONT face=宋体 size=2>SQL&gt; delete from test t where t.id in ('1','2','3')<BR>&nbsp; 2&nbsp; ;<BR>delete from test t where t.id in ('1','2','3')<BR>*<BR>ERROR at line 1:<BR>ORA-01502: index '.' or partition of such index is in unusable state</FONT></P>
<P><FONT face=宋体 size=2>还是不对。于是决定重建这个唯一约束：<BR>SQL&gt; select index_name,index_type,status from user_indexes where table_name = upper('test');</FONT></P>
<P><FONT face=宋体 size=2>INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX_TYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STATUS<BR>------------------------------ --------------------------- --------<BR>PK_ET_AIRSUPPLY_USERS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID<BR>UK_ET_AIRSUPPLY_USERS_NICK&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID</FONT></P>
<P><FONT face=宋体 size=2>SQL&gt; alter table test<BR>&nbsp; 2&nbsp; drop constraint UK_ET_AIRSUP_USERS_SUPP_WW;</FONT></P>
<P><FONT face=宋体 size=2>Table altered.</FONT></P>
<P><FONT face=宋体 size=2>SQL&gt; select index_name,index_type,status from user_indexes where table_name = upper('test');</FONT></P>
<P><FONT face=宋体 size=2>INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX_TYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STATUS<BR>------------------------------ --------------------------- --------<BR>PK_ET_AIRSUPPLY_USERS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID<BR>UK_ET_AIRSUPPLY_USERS_NICK&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID</FONT></P>
<P><FONT face=宋体 size=2>SQL&gt; delete from test t where t.id in ('1','2','3');</FONT></P>
<P><FONT face=宋体 size=2>0 rows deleted.</FONT></P>
<P><FONT face=宋体 size=2>SQL&gt; alter table test<BR>&nbsp; 2&nbsp;&nbsp;&nbsp; add constraint UK_ET_AIRSUP_USERS_supp_WW unique (air_supply_wangwang)<BR>&nbsp; 3&nbsp;&nbsp;&nbsp; using index <BR>&nbsp; 4&nbsp;&nbsp;&nbsp; tablespace TBS_ET_IND<BR>&nbsp; 5&nbsp;&nbsp;&nbsp; online<BR>&nbsp; 6&nbsp;&nbsp;&nbsp; compute statistics;</FONT></P>
<P><FONT face=宋体 size=2>Table altered.</FONT></P>
<P><FONT face=宋体 size=2>SQL&gt; delete from test t where t.id in ('1','2','3');</FONT></P>
<P><FONT face=宋体 size=2>0 rows deleted.</FONT></P>
<P><FONT face=宋体 size=2>SQL&gt; rollback;</FONT></P>
<P><FONT face=宋体 size=2>Rollback complete.</FONT></P>
<P><FONT face=宋体 size=2>SQL&gt; select index_name,index_type,status from user_indexes where table_name = upper('test');</FONT></P>
<P><FONT face=宋体 size=2>INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX_TYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STATUS<BR>------------------------------ --------------------------- --------<BR>PK_ET_AIRSUPPLY_USERS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID<BR>UK_ET_AIRSUPPLY_USERS_NICK&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID<BR>UK_ET_AIRSUP_USERS_SUPP_WW&nbsp;&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALID</FONT></P>
<P><BR><FONT face=宋体 size=2>SQL&gt; select * from v$version;</FONT></P>
<P><FONT face=宋体 size=2>BANNER<BR>----------------------------------------------------------------<BR>Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production<BR>PL/SQL Release 9.2.0.6.0 - Production<BR>CORE&nbsp;&nbsp;&nbsp; 9.2.0.6.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Production<BR>TNS for Linux: Version 9.2.0.6.0 - Production<BR>NLSRTL Version 9.2.0.6.0 - Production<BR>这个时候问题已经解决。但是这个事件有点诡异，这个错误也无法重现，只是想提醒一下，可能会出现这种现象，虽然它几率很小。</FONT></P>
<P><FONT face=宋体 size=2>为了避免此类错误的出现，最好的解决方法，至少在生产库上做操作，可以先自己手工创建唯一索引，然后在创建约束，这样就万无一失了。</FONT></P></div>]]></description>
	    <author><![CDATA[小霸王]]></author>
	    <comments>http://chenzs19850728.blog.163.com/blog/static/762960920084135524753</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://chenzs19850728.blog.163.com/blog/static/762960920084135524753</guid>
    <pubDate>Tue, 13 May 2008 17:05:24 +0800</pubDate>
    <dcterms:modified>2008-05-13T17:06:12+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[使用nid更改数据库名]]></title>	
    <link>http://chenzs19850728.blog.163.com/blog/static/7629609200848101225953</link>
    <description><![CDATA[<div><P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">如果想更改数据库名，即修改<SPAN lang=EN-US>db_name</SPAN>参数。在</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Oracle 9iR2提供了一个工具nid，可以通过它来完成这项工作，这样就避免了重建控制文件等繁琐方式来实现了。</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">nid工具可以只用来更改数据库名（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">db_name</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">），或者只更改数据库的id（dbid），或者两个同时更改。</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">当涉及到更改db_name的时候，由于数据库名还存在与参数文件中，因此，更改数据库名时也要更改相应的参数。如果你使用了spfile，那么要重建它。另外，还需要重建密码文件。</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">有个nid工具的详细使用情况，在metalink 文章 </SPAN><STRONG><SPAN lang=EN-US style="FONT-FAMILY: 'Arial','sans-serif'">Note:224266.1</SPAN></STRONG><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">有详细的记载。</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">首先，我们来看看nid的使用帮助：</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">[oracle@testdbc oracle]$ nid</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">DBNEWID: Release 9.2.0.6.0 - Production</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Copyright (c) 1995, 2002, Oracle Corporation.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>All rights reserved.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Keyword<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Description<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>(Default)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">----------------------------------------------------</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">TARGET<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Username/Password<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>(NONE)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">DBNAME<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>New database name<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>(NONE)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">LOGFILE<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Output Log<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>(NONE)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">REVERT<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Revert failed change<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NO</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">SETNAME<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Set a new database name only<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>NO</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">APPEND<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Append to output log<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NO</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">HELP<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Displays these messages<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NO</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">这里来解释一下几个问题：<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">(I):</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">如果你只想更改数据库的<SPAN lang=EN-US>id</SPAN>（<SPAN lang=EN-US>dbid</SPAN>），那么你只需要指定<SPAN lang=EN-US>target</SPAN>参数就可以了，具体的操作过程，请参考如下：<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">1. Backup the database</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">2. SHUTDOWN IMMEDIATE of the database</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">3. STARTUP MOUNT</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">4. Open one session and run NID with sysdba privileges</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>% nid TARGET=SYS/password@test_db </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">5. Shutdown IMMEDIATE of the database</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">6. Set the DB_NAME initialization parameter in the initialization parameter </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>file to the new database name </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">7. Create a new password file </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">8. Startup of the database with open resetlogs</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">(II):</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">如果你想只更改数据库名（<SPAN lang=EN-US>db_name</SPAN>），那么你需要设置<SPAN lang=EN-US>SETNAME</SPAN>参数为<SPAN lang=EN-US>Y</SPAN>，同时指定<SPAN lang=EN-US>DBNAME</SPAN>参数，具体的操作过程，请参考如下：<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">1. Backup the database</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">2. SHUTDOWN IMMEDIATE of the database</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">3. STARTUP MOUNT</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">4. Open one session and run NID with sysdba privileges</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>% nid TARGET=SYS/password@test_db DBNAME=test_db2 SETNAME=Y</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>- the value of DBNAME is the new dbname of the database</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>- SETNAME must be set to Y. The default is N and causes the </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>DBID to be changed also.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">5. shutdown IMMEDIATE of the database</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">6. Set the DB_NAME initialization parameter in the initialization parameter</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>file to the new database name</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">7. Create a new password file </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">8. Startup of the database(without resetlogs)</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">(III):</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">如果你想同时更改数据库名（<SPAN lang=EN-US>db_name</SPAN>）和数据库<SPAN lang=EN-US>ID</SPAN>（<SPAN lang=EN-US>dbid</SPAN>），那么你要指定<SPAN lang=EN-US>DBNAME</SPAN>参数，同时设置<SPAN lang=EN-US>SETNAME</SPAN>为<SPAN lang=EN-US>N</SPAN>（其值默认也为<SPAN lang=EN-US>N</SPAN>），具体操作过程，请参考如下：<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">1. Backup of the database. </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">2. Shutdown IMMEDIATE of the database</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">3. STARTUP MOUNT</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">4. Open one session and run NID with sysdba privileges</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>% nid TARGET=SYS/password@test_db DBNAME=test_db2</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>- the value of DBNAME is the new dbname of the database</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">5. After DBNEWID successfully changes the DBID,Shutdown IMMEDIATE of the database </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt 13.5pt; TEXT-INDENT: -13.5pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: -1.5" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">6. Set the DB_NAME initialization parameter in the initialization parameter file to the new database name. </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">7. Create a new password file. </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-hansi-theme-font: minor-latin; mso-hansi-font-family: Calibri">8. Startup of the database with open resetlogs</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">(IV):</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">如果你只更改了数据库名</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">，</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">而没有更改数据库</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">id</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">，</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">那么你打开数据库就不需要</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">open resetlogs</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">了</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">&nbsp;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">下面是我自己做的一次操作，<SPAN lang=EN-US>DBNAME</SPAN>和<SPAN lang=EN-US>DBID</SPAN>同时更改。<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">1．数据库启动到mount状态</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">SQL&gt; startup mount</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">ORACLE instance started.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">total System Global Area<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>923904016 bytes</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Fixed Size<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>452624 bytes</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Variable Size<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>385875968 bytes</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Database Buffers<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>536870912 bytes</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Redo Buffers<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>704512 bytes</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Database mounted.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">2. </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">NID</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">更改</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">[oracle@testdb2 dbs]$ nid target=sys/syspassword dbname=testdb2</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">DBNEWID: Release 9.2.0.6.0 - Production</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Copyright (c) 1995, 2002, Oracle Corporation.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>All rights reserved.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Connected to database <SPAN style="COLOR: red">TESTDB1 (DBID=287286795)<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>-- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">注意这里的数据库名和数据库<SPAN lang=EN-US>id</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Control Files in database:</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>/cx300_testdb2/data1/control01.ctl</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>/cx300_testdb2/data2/control02.ctl</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>/cx300_testdb2/data3/control03.ctl</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Change database ID and database name TESTDB1 to TESTDB2? (Y/[N]) <SPAN style="COLOR: red">=&gt; Y – </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">这里有个手工确认过程</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Proceeding with operation</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Changing database ID from 287286795 to 975736982</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Changing database name from TESTDB1 to TESTDB2</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Control File /cx300_testdb2/data1/control01.ctl – modified <SPAN style="COLOR: red"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>-- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">更改控制文件中相关控制信息，这里估计是致控制文件于某种状态，以便后面信息的更改。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Control File /cx300_testdb2/data2/control02.ctl - modified</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Control File /cx300_testdb2/data3/control03.ctl - modified</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Datafile /cx300_testdb2/data2/system01.dbf - dbid changed, wrote new name<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: red">-- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">这里开始更改数据文件中的信息<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Datafile /cx300_testdb2/data2/tbs_taobao_3.dbf - dbid changed, wrote new name</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 2.0" align=left><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">…………………………………………<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Datafile /cx300_testdb2/data3/tbs_temp2.dbf - dbid changed, wrote new name</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Control File /cx300_testdb2/data1/control01.ctl - dbid changed, wrote new name<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: red">--- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">这里开始更改控制文件中的信息<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Control File /cx300_testdb2/data2/control02.ctl - dbid changed, wrote new name</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Control File /cx300_testdb2/data3/control03.ctl - dbid changed, wrote new name</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Database name changed to TESTDB2.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: red">–- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">数据库名更改完毕</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Modify parameter file and generate a new password file before restarting. <SPAN style="COLOR: red">–- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">这里提示要在再次启动数据库时要更改<SPAN lang=EN-US>parameter file</SPAN>和<SPAN lang=EN-US>password file</SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Database ID for database TESTDB2 changed to 975736982. <SPAN style="COLOR: red">–- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">数据库<SPAN lang=EN-US>id</SPAN>更改完毕</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">All previous backups and archived redo logs for this database are unusable.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Shut down database and open with RESETLOGS option.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: red">–- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">由于更改了<SPAN lang=EN-US>dbid</SPAN>，所以要以<SPAN lang=EN-US>resetlogs</SPAN>选项打开数据库<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Succesfully changed database name and ID.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">DBNEWID - Completed succesfully.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">3</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">．<SPAN lang=EN-US>Shutdown database</SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">SQL&gt; shutdown immediate</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">ORA-01109: database not open</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">Database dismounted.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">ORACLE instance shut down.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">4</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">．</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">修改初始化参数文件</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">###########################################</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">db_domain=""</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">db_name=testdb2</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"># db_name=testdb1</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">########################################### </SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">5</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">．</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">重建口令文件</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">orapwd file=/opt/oracle/product/9.2/dbs/orapwdev-db2 password=syspassword</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">6.Startup mount,resetlogs</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">打开</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">alter database open resetlogs;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">7</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">．创建新的<SPAN lang=EN-US>spfile</SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">create spfile from pfile='/opt/oracle/product/9.2/dbs/initdev-db2.ora';</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">8</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">．</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">对数据库做个全备份</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">&nbsp;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-fareast-font-family: 宋体">我这里其实在开始的时候还少了一步，就是在更改之前，要对全库做备份。这个很重要，备份最重要！<SPAN lang=EN-US></SPAN></SPAN></P></div>]]></description>
	    <author><![CDATA[小霸王]]></author>
	    <comments>http://chenzs19850728.blog.163.com/blog/static/7629609200848101225953</comments>
    <slash:comments>2</slash:comments>
    <guid isPermaLink="true">http://chenzs19850728.blog.163.com/blog/static/7629609200848101225953</guid>
    <pubDate>Thu, 8 May 2008 22:12:25 +0800</pubDate>
    <dcterms:modified>2008-05-08T22:12:25+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[sequence]]></title>	
    <link>http://chenzs19850728.blog.163.com/blog/static/762960920083710532829</link>
    <description><![CDATA[<div><P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 14pt; COLOR: blue; LINE-HEIGHT: 150%; FONT-FAMILY: 华文楷体">概述<SPAN lang=EN-US></SPAN></SPAN></B></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体">Oracle</SPAN><SPAN style="FONT-FAMILY: 宋体">的<SPAN lang=EN-US>sequence</SPAN>，就是序列号，它提供一系列的按照事先指定的方式进行增长的数字。<SPAN lang=EN-US>oracle sequence</SPAN>的最大值是<SPAN lang=EN-US>38</SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ansi-language: FR">个整数。【</SPAN><B><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Bold">Sequences </SPAN></B><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">are database objects from which multiple users can generate unique integers.</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ansi-language: FR">】。一般来说，<SPAN lang=FR>sequence</SPAN>常用于生成数据库的主键。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><SPAN lang=EN-US style="FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>Oracle</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ansi-language: FR">将</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体">sequence</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ansi-language: FR">的定义存储在数据字典之中</SPAN><SPAN style="FONT-FAMILY: 宋体">，</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ansi-language: FR">因此</SPAN><SPAN style="FONT-FAMILY: 宋体">，</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ansi-language: FR">所有的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体">sequence</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ansi-language: FR">都在数据库的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体">SYSTEM</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ansi-language: FR">表空间里面。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体">引用<SPAN lang=EN-US>sequence</SPAN>的当前值使用<SPAN lang=EN-US>CURRVAL</SPAN>，而生成<SPAN lang=EN-US>sequence</SPAN>的下一个值使用<SPAN lang=EN-US>NEXTVAL</SPAN>来实现。初始化一个刚刚新建的<SPAN lang=EN-US>sequence</SPAN>使用<SPAN lang=EN-US>NEXTVAL</SPAN>，它会返回新<SPAN lang=EN-US>sequence</SPAN>的第一值。另外还要注意，</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ansi-language: FR">在一个全新的会话中，使用<SPAN lang=FR>CURRVAL</SPAN>之前必须至少使用一次<SPAN lang=FR>NEXTVAL</SPAN>。</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><SPAN lang=EN-US style="FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN lang=FR style="FONT-FAMILY: 宋体; mso-ansi-language: FR">sequence</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是独立于表的</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: FR">，</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">也就是说一个</SPAN><SPAN lang=FR style="mso-ansi-language: FR"><FONT face="Times New Roman">sequence</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以同时被多个表使用来生成主键。</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><SPAN lang=EN-US><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>sequence</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是独立于事务的，就是说序列的增加不需要等待事务的完成，也就是说序列是异步于事务而增长的。这种现象就说明，如果你根本访问不了别的用户用</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">sequence</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">产生的值，也就是说你只能访问到你当前产生的值，即使其他用户已经增加了</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">sequence</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值；还说明如果你事务回滚，</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">sequence</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不会回滚，它所发生的改变是一维的。请看一个例子：</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体">-- session 1</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">SQL&gt; select distinct sid from v$mystat;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>SID</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">----------</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>147</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">SQL&gt; create sequence seqtest;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">Sequence created.</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">SQL&gt; select seqtest.nextval from dual;<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: red">-- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体">第一次初始化<SPAN lang=EN-US>sequence</SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>NEXTVAL</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">----------</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">SQL&gt; select seqtest.nextval from dual;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>NEXTVAL</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">----------</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体">-- session 2</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">SQL&gt; select distinct sid from v$mystat;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>SID</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">----------</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>143</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">SQL&gt; select seqtest.currval from dual; <SPAN style="COLOR: red">-- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体">在一个新会话中，第一次使用<SPAN lang=EN-US>currval</SPAN>之前必须先使用<SPAN lang=EN-US>nextval</SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">select seqtest.currval from dual</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>*</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">ERROR at line 1:</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">ORA-08002: sequence SEQTEST.CURRVAL is not yet defined in this session</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">SQL&gt; select seqtest.nextval from dual; <SPAN style="COLOR: red">-- </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体">是<SPAN lang=EN-US>sequence</SPAN>值增加<SPAN lang=EN-US>1</SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>NEXTVAL</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">----------</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>3</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体">-- session 1</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体">，</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 宋体">虽然这个时候<SPAN lang=EN-US>session</SPAN>已经增加了<SPAN lang=EN-US>sequence</SPAN>的值，但是<SPAN lang=EN-US>session 1</SPAN>只能看到自己增加的<SPAN lang=EN-US>sequence</SPAN>的部分。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">SQL&gt; select seqtest.currval from dual;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>CURRVAL</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">----------</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><SPAN lang=EN-US><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果在一个语句中，有多个部分使用了</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">NEXTVAL</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，那么只有第一个</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">NEXTVAL</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">会使</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">sequence</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">改变一次，其他的不会是</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">sequence</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">发生变化。请看：</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">SQL&gt; select seqtest.nextval,seqtest.nextval,seqtest.nextval from dual;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>NEXTVAL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>NEXTVAL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>NEXTVAL</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">---------- ---------- ----------</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>5</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><SPAN lang=EN-US><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>sequence</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以在下列场合中使用：</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">1. VALUES </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">clause of </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">INSERT </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">statements</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">2. The </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">SELECT </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">list of a </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">SELECT </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">statement</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">3. The </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">SET </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">clause of an </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">UPDATE </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">statement</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><SPAN lang=EN-US><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">而不能在下列场合使用：</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: ZapfDingbats">■ </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">A <SPAN style="COLOR: blue">subquery</SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: ZapfDingbats">■ </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">A <SPAN style="COLOR: blue">view</SPAN> query or materialized view query</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: ZapfDingbats">■ </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">A </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">SELECT </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">statement with the </SPAN><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">DISTINCT</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier"> </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">operator</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: ZapfDingbats">■ </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">A </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">SELECT </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">statement with a </SPAN><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">GROUP BY</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier"> </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">or </SPAN><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">ORDER BY</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier"> </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">clause</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: ZapfDingbats">■ </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">A </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Courier">SELECT </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: Palatino-Roman">statement that is combined with another </SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kern