﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-qileilove-随笔分类-DB2</title><link>http://www.blogjava.net/qileilove/category/53093.html</link><description>不想做屌丝的码农，不是好项目经理！屌丝生涯从此开始！</description><language>zh-cn</language><lastBuildDate>Fri, 07 Nov 2014 12:09:00 GMT</lastBuildDate><pubDate>Fri, 07 Nov 2014 12:09:00 GMT</pubDate><ttl>60</ttl><item><title>Java对存储过程的调用方法</title><link>http://www.blogjava.net/qileilove/archive/2014/11/07/419644.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 07 Nov 2014 02:29:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/11/07/419644.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/419644.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/11/07/419644.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/419644.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/419644.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">一、<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Java</strong></u></a>怎样实现对存储过程的调用：</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">　　A：不带输出參数的</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">create procedure getsum</div><div style="word-break: break-all; margin: 10px 0px;">@n int =0&lt;--此处为參数--&gt;</div><div style="word-break: break-all; margin: 10px 0px;">as</div><div style="word-break: break-all; margin: 10px 0px;">declare @sum int&lt;--定义变量--&gt;</div><div style="word-break: break-all; margin: 10px 0px;">declare @i int</div><div style="word-break: break-all; margin: 10px 0px;">set @sum=0</div><div style="word-break: break-all; margin: 10px 0px;">set @i=0</div><div style="word-break: break-all; margin: 10px 0px;">while @i&lt;=@n begin</div><div style="word-break: break-all; margin: 10px 0px;">set @sum=@sum+@i</div><div style="word-break: break-all; margin: 10px 0px;">set @i=@i+1</div><div style="word-break: break-all; margin: 10px 0px;">end</div><div style="word-break: break-all; margin: 10px 0px;">print 'the sum is '+ltrim(rtrim(str(@sum)))</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　在<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">SQL</strong></u></a>中运行：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　exec getsum 100</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　在JAVA中调用：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　JAVA能够调用 可是在JAVA程序却不能去显示该存储过程的结果 由于上面的存储过程的參数类型int 传递方式是in(按值)方式</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.sql.*;</div><div style="word-break: break-all; margin: 10px 0px;">public class ProcedureTest</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">public static void main(String args[]) throws Exception</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">//载入驱动</div><div style="word-break: break-all; margin: 10px 0px;">DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());</div><div style="word-break: break-all; margin: 10px 0px;">//获得连接</div><div style="word-break: break-all; margin: 10px 0px;">Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");</div><div style="word-break: break-all; margin: 10px 0px;">//创建存储过程的对象</div><div style="word-break: break-all; margin: 10px 0px;">CallableStatement c=conn.prepareCall("{call getsum(?)}");</div><div style="word-break: break-all; margin: 10px 0px;">//给存储过程的參数设置值</div><div style="word-break: break-all; margin: 10px 0px;">c.setInt(1,100); //将第一个參数的值设置成100</div><div style="word-break: break-all; margin: 10px 0px;">//运行存储过程</div><div style="word-break: break-all; margin: 10px 0px;">c.execute();</div><div style="word-break: break-all; margin: 10px 0px;">conn.close();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　B：带输出參数的</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　1:返回int</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">alter procedure getsum</div><div style="word-break: break-all; margin: 10px 0px;">@n int =0,</div><div style="word-break: break-all; margin: 10px 0px;">@result int output</div><div style="word-break: break-all; margin: 10px 0px;">as</div><div style="word-break: break-all; margin: 10px 0px;">declare @sum int</div><div style="word-break: break-all; margin: 10px 0px;">declare @i int</div><div style="word-break: break-all; margin: 10px 0px;">set @sum=0</div><div style="word-break: break-all; margin: 10px 0px;">set @i=0</div><div style="word-break: break-all; margin: 10px 0px;">while @i&lt;=@n begin</div><div style="word-break: break-all; margin: 10px 0px;">set @sum=@sum+@i</div><div style="word-break: break-all; margin: 10px 0px;">set @i=@i+1</div><div style="word-break: break-all; margin: 10px 0px;">end</div><div style="word-break: break-all; margin: 10px 0px;">set @result=@sum</div></td></tr></tbody></table><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　在查询分析器中运行：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　declare @myResult int</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　exec getsum 100,@myResult output</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　print @myResult</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　在JAVA中调用：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.sql.*;</div><div style="word-break: break-all; margin: 10px 0px;">public class ProcedureTest</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">public static void main(String args[]) throws Exception</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">//载入驱动</div><div style="word-break: break-all; margin: 10px 0px;">DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());</div><div style="word-break: break-all; margin: 10px 0px;">//获得连接</div><div style="word-break: break-all; margin: 10px 0px;">Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");</div><div style="word-break: break-all; margin: 10px 0px;">//创建存储过程的对象</div><div style="word-break: break-all; margin: 10px 0px;">CallableStatement c=conn.prepareCall("{call getsum(?,?)}");</div><div style="word-break: break-all; margin: 10px 0px;">//给存储过程的第一个參数设置值</div><div style="word-break: break-all; margin: 10px 0px;">c.setInt(1,100);</div><div style="word-break: break-all; margin: 10px 0px;">//注冊存储过程的第二个參数</div><div style="word-break: break-all; margin: 10px 0px;">c.registerOutParameter(2,java.sql.Types.INTEGER);</div><div style="word-break: break-all; margin: 10px 0px;">//运行存储过程</div><div style="word-break: break-all; margin: 10px 0px;">c.execute();</div><div style="word-break: break-all; margin: 10px 0px;">//得到存储过程的输出參数值</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println (c.getInt(2));</div><div style="word-break: break-all; margin: 10px 0px;">conn.close();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　2:返回varchar</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　存储过程带游标：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　在存储过程中带游标 使用游标不停的遍历orderid</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　create procedure CursorIntoProcedure</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　@pname varchar(8000) output</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　as</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　--定义游标</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　declare cur cursor for select orderid from orders</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　--定义一个变量来接收游标的值</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　declare @v varchar(5)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　--打开游标</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　open cur</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　set @pname=''--给@pname初值</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　--提取游标的值</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　fetch next from cur into @v</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　while @@fetch_status=0</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　begin</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　set @pname=@pname+';'+@v</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　fetch next from cur into @v</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　end</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　print @pname</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　--关闭游标</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　close cur</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　--销毁游标</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　deallocate cur</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　运行存储过程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　exec CursorIntoProcedure ''</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　JAVA调用：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.sql.*;</div><div style="word-break: break-all; margin: 10px 0px;">public class ProcedureTest</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">public static void main(String args[]) throws Exception</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">//载入驱动</div><div style="word-break: break-all; margin: 10px 0px;">DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());</div><div style="word-break: break-all; margin: 10px 0px;">//获得连接</div><div style="word-break: break-all; margin: 10px 0px;">Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");</div><div style="word-break: break-all; margin: 10px 0px;">CallableStatement c=conn.prepareCall("{call CursorIntoProcedure(?)}");</div><div style="word-break: break-all; margin: 10px 0px;">c.registerOutParameter(1,java.sql.Types.VARCHAR);</div><div style="word-break: break-all; margin: 10px 0px;">c.execute();</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println (c.getString(1));</div><div style="word-break: break-all; margin: 10px 0px;">conn.close();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　<strong style="word-break: break-all; line-height: normal !important;">　C：删除数据的存储过程</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　存储过程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">drop table 学生基本信息表</div><div style="word-break: break-all; margin: 10px 0px;">create table 学生基本信息表</div><div style="word-break: break-all; margin: 10px 0px;">(</div><div style="word-break: break-all; margin: 10px 0px;">StuID int primary key,</div><div style="word-break: break-all; margin: 10px 0px;">StuName varchar(10),</div><div style="word-break: break-all; margin: 10px 0px;">StuAddress varchar(20)</div><div style="word-break: break-all; margin: 10px 0px;">)</div><div style="word-break: break-all; margin: 10px 0px;">insert into 学生基本信息表 values(1,'三毛','wuhan')</div><div style="word-break: break-all; margin: 10px 0px;">insert into 学生基本信息表 values(2,'三毛','wuhan')</div><div style="word-break: break-all; margin: 10px 0px;">create table 学生成绩表</div><div style="word-break: break-all; margin: 10px 0px;">(</div><div style="word-break: break-all; margin: 10px 0px;">StuID int,</div><div style="word-break: break-all; margin: 10px 0px;">Chinese int,</div><div style="word-break: break-all; margin: 10px 0px;">PyhSics int</div><div style="word-break: break-all; margin: 10px 0px;">foreign key(StuID) references 学生基本信息表(StuID)</div><div style="word-break: break-all; margin: 10px 0px;">on delete cascade</div><div style="word-break: break-all; margin: 10px 0px;">on update cascade</div><div style="word-break: break-all; margin: 10px 0px;">)</div><div style="word-break: break-all; margin: 10px 0px;">insert into 学生成绩表 values(1,99,100)</div><div style="word-break: break-all; margin: 10px 0px;">insert into 学生成绩表 values(2,99,100)</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　创建存储过程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　create procedure delePro</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　@StuID int</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　as</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　delete from 学生基本信息表 where StuID=@StuID</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　--创建完成</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　exec delePro 1 --运行存储过程</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　--创建存储过程</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　create procedure selePro</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　as</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　select * from 学生基本信息表</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　--创建完成</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　exec selePro --运行存储过程</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　在JAVA中调用：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.sql.*;</div><div style="word-break: break-all; margin: 10px 0px;">public class ProcedureTest</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">public static void main(String args[]) throws Exception</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">//载入驱动</div><div style="word-break: break-all; margin: 10px 0px;">DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());</div><div style="word-break: break-all; margin: 10px 0px;">//获得连接</div><div style="word-break: break-all; margin: 10px 0px;">Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");</div><div style="word-break: break-all; margin: 10px 0px;">//创建存储过程的对象</div><div style="word-break: break-all; margin: 10px 0px;">CallableStatement c=conn.prepareCall("{call delePro(?)}");</div><div style="word-break: break-all; margin: 10px 0px;">c.setInt(1,1);</div><div style="word-break: break-all; margin: 10px 0px;">c.execute();</div><div style="word-break: break-all; margin: 10px 0px;">c=conn.prepareCall("{call selePro}");</div><div style="word-break: break-all; margin: 10px 0px;">ResultSet rs=c.executeQuery();</div><div style="word-break: break-all; margin: 10px 0px;">while(rs.next())</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">String Stu=rs.getString("StuID");</div><div style="word-break: break-all; margin: 10px 0px;">String name=rs.getString("StuName");</div><div style="word-break: break-all; margin: 10px 0px;">String add=rs.getString("StuAddress");</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println ("学号:"+" "+"姓名:"+" "+"地址");</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println (Stu+" "+name+" "+add);</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">c.close();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><strong style="word-break: break-all; line-height: normal !important;">D：改动数据的存储过程</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　创建存储过程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　create procedure ModPro</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　@StuID int,</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　@StuName varchar(10)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　as</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　update 学生基本信息表 set StuName=@StuName where StuID=@StuID</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　运行存储过程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　exec ModPro 2,'四毛'</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　JAVA调用存储过程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 975px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.sql.*;</div><div style="word-break: break-all; margin: 10px 0px;">public class ProcedureTest</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">public static void main(String args[]) throws Exception</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">//载入驱动</div><div style="word-break: break-all; margin: 10px 0px;">DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());</div><div style="word-break: break-all; margin: 10px 0px;">//获得连接</div><div style="word-break: break-all; margin: 10px 0px;">Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");</div><div style="word-break: break-all; margin: 10px 0px;">//创建存储过程的对象</div><div style="word-break: break-all; margin: 10px 0px;">CallableStatement c=conn.prepareCall("{call ModPro(?,?)}");</div><div style="word-break: break-all; margin: 10px 0px;">c.setInt(1,2);</div><div style="word-break: break-all; margin: 10px 0px;">c.setString(2,"美女");</div><div style="word-break: break-all; margin: 10px 0px;">c.execute();</div><div style="word-break: break-all; margin: 10px 0px;">c=conn.prepareCall("{call selePro}");</div><div style="word-break: break-all; margin: 10px 0px;">ResultSet rs=c.executeQuery();</div><div style="word-break: break-all; margin: 10px 0px;">while(rs.next())</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">String Stu=rs.getString("StuID");</div><div style="word-break: break-all; margin: 10px 0px;">String name=rs.getString("StuName");</div><div style="word-break: break-all; margin: 10px 0px;">String add=rs.getString("StuAddress");</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println ("学号:"+" "+"姓名:"+" "+"地址");</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println (Stu+" "+name+" "+add);</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">c.close();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　<strong style="word-break: break-all; line-height: normal !important;">　E：查询数据的存储过程(模糊查询)</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　存储过程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　create procedure FindCusts</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　@cust varchar(10)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　as</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　select customerid from orders where customerid</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　like '%'+@cust+'%'</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　运行：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　execute FindCusts 'alfki'</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　在JAVA中调用：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 975px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.sql.*;</div><div style="word-break: break-all; margin: 10px 0px;">public class ProcedureTest</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">public static void main(String args[]) throws Exception</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">//载入驱动</div><div style="word-break: break-all; margin: 10px 0px;">DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());</div><div style="word-break: break-all; margin: 10px 0px;">//获得连接</div><div style="word-break: break-all; margin: 10px 0px;">Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");</div><div style="word-break: break-all; margin: 10px 0px;">//创建存储过程的对象</div><div style="word-break: break-all; margin: 10px 0px;">CallableStatement c=conn.prepareCall("{call FindCusts(?)}");</div><div style="word-break: break-all; margin: 10px 0px;">c.setString(1,"Tom");</div><div style="word-break: break-all; margin: 10px 0px;">ResultSet rs=c.executeQuery();</div><div style="word-break: break-all; margin: 10px 0px;">while(rs.next())</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">String cust=rs.getString("customerid");</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println (cust);</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">c.close();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　<strong style="word-break: break-all; line-height: normal !important;">　F：添加数据的存储过程</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　存储过程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　create procedure InsertPro</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　@StuID int,</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　@StuName varchar(10),</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　@StuAddress varchar(20)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　as</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　insert into 学生基本信息表 values(@StuID,@StuName,@StuAddress)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　调用存储过程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　exec InsertPro 5,'555','555'</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　在JAVA中运行：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 975px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.sql.*;</div><div style="word-break: break-all; margin: 10px 0px;">public class ProcedureTest</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">public static void main(String args[]) throws Exception</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">//载入驱动</div><div style="word-break: break-all; margin: 10px 0px;">DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());</div><div style="word-break: break-all; margin: 10px 0px;">//获得连接</div><div style="word-break: break-all; margin: 10px 0px;">Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");</div><div style="word-break: break-all; margin: 10px 0px;">//创建存储过程的对象</div><div style="word-break: break-all; margin: 10px 0px;">CallableStatement c=conn.prepareCall("{call InsertPro(?,?,?)}");</div><div style="word-break: break-all; margin: 10px 0px;">c.setInt(1,6);</div><div style="word-break: break-all; margin: 10px 0px;">c.setString(2,"Liu");</div><div style="word-break: break-all; margin: 10px 0px;">c.setString(3,"wuhan");</div><div style="word-break: break-all; margin: 10px 0px;">c.execute();</div><div style="word-break: break-all; margin: 10px 0px;">c=conn.prepareCall("{call selePro}");</div><div style="word-break: break-all; margin: 10px 0px;">ResultSet rs=c.executeQuery();</div><div style="word-break: break-all; margin: 10px 0px;">while(rs.next())</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">String stuid=rs.getString("StuID");</div><div style="word-break: break-all; margin: 10px 0px;">String name=rs.getString("StuName");</div><div style="word-break: break-all; margin: 10px 0px;">String address=rs.getString("StuAddress");</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println (stuid+" "+name+" "+address);</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">c.close();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　<strong style="word-break: break-all; line-height: normal !important;">G：在JAVA中创建存储过程 而且在JAVA中直接调用</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 975px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.sql.*;</div><div style="word-break: break-all; margin: 10px 0px;">public class ProcedureTest</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">public static void main(String args[]) throws Exception</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">//载入驱动</div><div style="word-break: break-all; margin: 10px 0px;">DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());</div><div style="word-break: break-all; margin: 10px 0px;">//获得连接</div><div style="word-break: break-all; margin: 10px 0px;">Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");</div><div style="word-break: break-all; margin: 10px 0px;">Statement stmt=conn.createStatement();</div><div style="word-break: break-all; margin: 10px 0px;">//在JAVA中创建存储过程</div><div style="word-break: break-all; margin: 10px 0px;">stmt.executeUpdate("create procedure OOP as select * from 学生成绩表");</div><div style="word-break: break-all; margin: 10px 0px;">CallableStatement c=conn.prepareCall("{call OOP}");</div><div style="word-break: break-all; margin: 10px 0px;">ResultSet rs=c.executeQuery();</div><div style="word-break: break-all; margin: 10px 0px;">while(rs.next())</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">String chinese=rs.getString("Chinese");</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println (chinese);</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">conn.close();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div></div></div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/419644.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-11-07 10:29 <a href="http://www.blogjava.net/qileilove/archive/2014/11/07/419644.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用java简单的实现单链表的基本操作</title><link>http://www.blogjava.net/qileilove/archive/2013/09/10/403876.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 10 Sep 2013 02:47:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/09/10/403876.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/403876.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/09/10/403876.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/403876.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/403876.html</trackback:ping><description><![CDATA[<p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　此代码仅供参考，如有疑问欢迎评论：</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612.2222290039063px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">package com.tyxh.link;<br style="word-break: break-all; line-height: normal !important;" />//节点类<br style="word-break: break-all; line-height: normal !important;" />public class Node {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; protected Node next; //指针域<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; protected int data;//数据域<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public Node( int data) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this. data = data;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; //显示此节点<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public void display() {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System. out.print( data + " ");<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />}</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">package com.tyxh.link;<br style="word-break: break-all; line-height: normal !important;" />//单链表<br style="word-break: break-all; line-height: normal !important;" />public class LinkList {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public Node first; // 定义一个头结点<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; private int pos = 0;// 节点的位置</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">&nbsp;&nbsp;&nbsp;&nbsp; public LinkList() {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this. first = null;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">&nbsp;&nbsp;&nbsp;&nbsp; // 插入一个头节点<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public void addFirstNode( int data) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node node = new Node(data);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node. next = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first = node;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">&nbsp;&nbsp;&nbsp;&nbsp; // 删除一个头结点,并返回头结点<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public Node deleteFirstNode() {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node tempNode = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first = tempNode. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return tempNode;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">&nbsp;&nbsp;&nbsp;&nbsp; // 在任意位置插入节点 在index的后面插入<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public void add(int index, int data) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node node = new Node(data);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node current = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node previous = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ( pos != index) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; previous = current;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current = current. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos++;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node. next = current;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; previous. next = node;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos = 0;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">&nbsp;&nbsp;&nbsp;&nbsp; // 删除任意位置的节点<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public Node deleteByPos( int index) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node current = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node previous = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ( pos != index) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos++;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; previous = current;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current = current. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(current == first) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first = first. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos = 0;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; previous. next = current. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return current;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">&nbsp;&nbsp;&nbsp;&nbsp; // 根据节点的data删除节点(仅仅删除第一个)<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public Node deleteByData( int data) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node current = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node previous = first; //记住上一个节点<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (current. data != data) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (current. next == null) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return null;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; previous = current;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current = current. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(current == first) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first = first. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; previous. next = current. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return current;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">&nbsp;&nbsp;&nbsp;&nbsp; // 显示出所有的节点信息<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public void displayAllNodes() {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node current = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (current != null) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current.display();<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current = current. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System. out.println();<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">&nbsp;&nbsp;&nbsp;&nbsp; // 根据位置查找节点信息<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public Node findByPos( int index) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node current = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( pos != index) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current = current. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos++;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return current;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">&nbsp;&nbsp;&nbsp;&nbsp; // 根据数据查找节点信息<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public Node findByData( int data) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node current = first;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (current. data != data) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (current. next == null)<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return null;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current = current. next;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return current;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />}</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">package com.tyxh.link;<br style="word-break: break-all; line-height: normal !important;" />//测试类<br style="word-break: break-all; line-height: normal !important;" />public class TestLinkList {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LinkList linkList = new LinkList();<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.addFirstNode(20);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.addFirstNode(21);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.addFirstNode(19);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //19,21,20<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.add(1, 22); //19,22,21,20<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.add(2, 23); //19,22,23,21,20<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.add(3, 99); //19,22,23,99,21,20<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.displayAllNodes();<br style="word-break: break-all; line-height: normal !important;" />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node node = linkList.deleteFirstNode();<br style="word-break: break-all; line-height: normal !important;" />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("node : " + node.data);<br style="word-break: break-all; line-height: normal !important;" />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.displayAllNodes();<br style="word-break: break-all; line-height: normal !important;" />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node = linkList.deleteByPos(2);<br style="word-break: break-all; line-height: normal !important;" />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("node : " + node.data);<br style="word-break: break-all; line-height: normal !important;" />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.displayAllNodes();<br style="word-break: break-all; line-height: normal !important;" />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.deleteFirstNode();<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node node = linkList.deleteByData(19);<br style="word-break: break-all; line-height: normal !important;" />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node node = linkList.deleteByPos(0);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System. out.println( "node : " + node. data);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linkList.displayAllNodes();<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node node1 = linkList.findByPos(0);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System. out.println( "node1: " + node1. data);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node node2 = linkList.findByData(22);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System. out.println( "node2: " + node2. data);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp; }<br style="word-break: break-all; line-height: normal !important;" />}</p></td></tr></tbody></table><img src ="http://www.blogjava.net/qileilove/aggbug/403876.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-09-10 10:47 <a href="http://www.blogjava.net/qileilove/archive/2013/09/10/403876.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>导入Excel数据到Oracle数据库的脚本</title><link>http://www.blogjava.net/qileilove/archive/2013/09/06/403741.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 06 Sep 2013 02:43:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/09/06/403741.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/403741.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/09/06/403741.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/403741.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/403741.html</trackback:ping><description><![CDATA[<p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　在cmd运行窗口中输入：sqlldr customermanager/123@orcl control="E:\CustomerData\excelInputOracle\insert.ctl" log=E:\CustomerData\excelInputOracle\log.txt skip=1</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　说明：</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　{</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　sqlldr是sqlloader的命令语句</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　customermanager/123@orcl是连接<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">数据库</strong></u></a>，用户名/密码@服务名</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　control控制命令 后接控制文本的地址</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　log 定义<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">日志</strong></u></a>文件的存放</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　skip跳过前几行，因为文件第一行是表头，因此跳过第一行</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　先在数据库里建立相同的字段名称&nbsp; 详细见 insert.ctl文件</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　还得把excel数据保存成csv格式文件</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　}</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;">　　insert.ctl文件就是一个txt文本文件，拷贝以下内容到这个文件（注意修改）</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 23.99305534362793px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612.2222290039063px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">load data<br style="word-break: break-all; line-height: normal !important;" />CHARACTERSET ZHS16GBK<br style="word-break: break-all; line-height: normal !important;" />infile 'E:\CustomerData\excelInputOracle\20130726.csv'<br style="word-break: break-all; line-height: normal !important;" />append into table ORIGINAL_DATA<br style="word-break: break-all; line-height: normal !important;" />fields terminated by ','<br style="word-break: break-all; line-height: normal !important;" />optionally enclosed by '"'<br style="word-break: break-all; line-height: normal !important;" />trailing nullcols<br style="word-break: break-all; line-height: normal !important;" />(ZCRQ,<br style="word-break: break-all; line-height: normal !important;" />XQSLH,<br style="word-break: break-all; line-height: normal !important;" />LWDW,<br style="word-break: break-all; line-height: normal !important;" />FZ,<br style="word-break: break-all; line-height: normal !important;" />FJ,<br style="word-break: break-all; line-height: normal !important;" />FHR,<br style="word-break: break-all; line-height: normal !important;" />DZ,<br style="word-break: break-all; line-height: normal !important;" />DJ,<br style="word-break: break-all; line-height: normal !important;" />HZPM,<br style="word-break: break-all; line-height: normal !important;" />HZPL,<br style="word-break: break-all; line-height: normal !important;" />YSTZHZ,<br style="word-break: break-all; line-height: normal !important;" />QQCS,<br style="word-break: break-all; line-height: normal !important;" />QQLX,<br style="word-break: break-all; line-height: normal !important;" />PZCS,<br style="word-break: break-all; line-height: normal !important;" />PZCZ,<br style="word-break: break-all; line-height: normal !important;" />ZCCS,<br style="word-break: break-all; line-height: normal !important;" />ZCCZ,<br style="word-break: break-all; line-height: normal !important;" />YDJH,<br style="word-break: break-all; line-height: normal !important;" />YWC,<br style="word-break: break-all; line-height: normal !important;" />SHE,<br style="word-break: break-all; line-height: normal !important;" />JY,<br style="word-break: break-all; line-height: normal !important;" />HYSR,<br style="word-break: break-all; line-height: normal !important;" />HPSR,<br style="word-break: break-all; line-height: normal !important;" />JSJJ,<br style="word-break: break-all; line-height: normal !important;" />FQ,<br style="word-break: break-all; line-height: normal !important;" />DQ)</p></td></tr></tbody></table><img src ="http://www.blogjava.net/qileilove/aggbug/403741.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-09-06 10:43 <a href="http://www.blogjava.net/qileilove/archive/2013/09/06/403741.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sqlite查询数据库</title><link>http://www.blogjava.net/qileilove/archive/2013/08/27/403339.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 27 Aug 2013 02:11:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/08/27/403339.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/403339.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/08/27/403339.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/403339.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/403339.html</trackback:ping><description><![CDATA[<table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612.2222290039063px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">//每次只返回一条记录，如果要保存所有记录，不能用局部变量。<br style="word-break: break-all; line-height: normal !important;" />int _callback(void *olt_temp, int argc, char *value[], char *name[])<br style="word-break: break-all; line-height: normal !important;" />{<br style="word-break: break-all; line-height: normal !important;" />&nbsp;//olt_temp： 与sqlite3_exec中的第四个参数相同<br style="word-break: break-all; line-height: normal !important;" />&nbsp;//argc: 字段数<br style="word-break: break-all; line-height: normal !important;" />&nbsp;//value： 值&nbsp;<br style="word-break: break-all; line-height: normal !important;" />&nbsp;//name： 字段名<br style="word-break: break-all; line-height: normal !important;" />&nbsp;return 0; //0表示成功，继续收到其它数据，<br style="word-break: break-all; line-height: normal !important;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //其它值表示终止,不会再继续收到数据。<br style="word-break: break-all; line-height: normal !important;" />}</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">sqlite3* m_pDB;<br style="word-break: break-all; line-height: normal !important;" />if(0 != ::sqlite3_open16(path, &amp;m_pDB))<br style="word-break: break-all; line-height: normal !important;" />{<br style="word-break: break-all; line-height: normal !important;" />&nbsp;//error<br style="word-break: break-all; line-height: normal !important;" />&nbsp;//return false;<br style="word-break: break-all; line-height: normal !important;" />}</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;"><br style="word-break: break-all; line-height: normal !important;" />int ire = sqlite3_exec(pDB, pSql, _callback, NULL, &amp;m_pErrMsg);<br style="word-break: break-all; line-height: normal !important;" />if (NULL != m_pErrMsg)<br style="word-break: break-all; line-height: normal !important;" />{<br style="word-break: break-all; line-height: normal !important;" />&nbsp;::sqlite3_free(m_pErrMsg);<br style="word-break: break-all; line-height: normal !important;" />&nbsp;m_pErrMsg = NULL;<br style="word-break: break-all; line-height: normal !important;" />}</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;"><br style="word-break: break-all; line-height: normal !important;" />if (0 != ire)<br style="word-break: break-all; line-height: normal !important;" />{<br style="word-break: break-all; line-height: normal !important;" />&nbsp;//执行失败<br style="word-break: break-all; line-height: normal !important;" />&nbsp;//return false;<br style="word-break: break-all; line-height: normal !important;" />}</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">sqlite3_close(m_pDB);</p></td></tr></tbody></table><img src ="http://www.blogjava.net/qileilove/aggbug/403339.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-08-27 10:11 <a href="http://www.blogjava.net/qileilove/archive/2013/08/27/403339.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>看曹政如何减少SQL请求</title><link>http://www.blogjava.net/qileilove/archive/2013/06/17/400626.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 17 Jun 2013 02:05:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/06/17/400626.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/400626.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/06/17/400626.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/400626.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/400626.html</trackback:ping><description><![CDATA[<p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　首先为了防止某些专业挑刺人士无限制发挥，先声明几个前提</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1：索引优化是基础<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">工作</strong></u></a>，没做好这个其他的不用提，但本文不展开此内容。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2：优化<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">数据库</strong></u></a>查询有非常多的分支，减少<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">SQL</strong></u></a>请求只是其中一个领域，其他分支本文不涉及。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　3：在部分场景下，甚至需要增加SQL以解决诸如分布式或其他问题，本文不涉及。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　4：运维优化和其他优化手段本文不涉及。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　5：产品业务逻辑优化本文不涉及。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　6：其他本文没提到的内容欢迎自行联想，技术水准高超者请忽略本文。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">　　第一、查询请求的分析和裁剪</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　线上系统，出现请求较多，数据压力较大（索引优化到位的前提下），我会让程序员输出一段时间的查询请求。（通常数据库操作有封装对象，直接记录<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">日志</strong></u></a>即可，建议写入/dev/shm 以减少i/o压力，如果请求频次实在很高，可以取一定比例写入日志），然后基于日志分析。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1、完全一致的查询请求有多少，平均每秒会出现多少这样的查询。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　比如常见的，所有页面都加载系统信息 select * from systeminfo;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2、基于同一数据表同一主键的查询有多少，平均每秒会出现多少这样的查询</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　比如 select name from userinfo where uid=10134;&nbsp; select email from userinfo where uid=10134;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　这两种请求，是可以通过建立缓存机制来优化的，</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　而且做了这个分析，会有一个很好的数据认知</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　当前数据库每秒处理多少查询请求，其中可优化的冗余请求有多少，如果建立缓存可以减少多少请求。提升系统支撑性多少？</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　对于一些不是特别出色的开源系统，分析一下会发现，可裁剪的查询请求是非常巨大的。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">　　第二、更新请求的分析和裁剪</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　更新请求也可以优化，</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　我们一般用mysql的情况下，是先解开binlog文件，还原为文本文件，然后分析</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　基于同一数据表，同一主键的更新请求有多少，平均每个时间段出现多少这样的请求</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　举例1：</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　update user set lastacttime=.... where uid=10314; 经常更新最后活跃时间</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　举例2：</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　update posts set views=views+1 where pid=10004211; 更新同一个帖子显示数字</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　如果这样的请求较多，那么可以有针对性的建立队列，定时异步更新。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　在异步更新过程中</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　范例1 多条请求只要记住同一主键最后一条即可；</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　范例2 多条请求可以在程序中合并，对数据库操作只进行一次。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　这样更新请求频次就极大下降了。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　如果线上有实时性要求，线上可以保持一个内存数据做同步更新。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　方法其实很简单，但是很有效</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">　　简单总结</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　第一，要随时了解自己的读写请求频次情况</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　第二，一定时间范围内针对同数据表，同主键的读写请求，均是可优化，可裁剪的，但是也要考虑当时的系统负载构成和请求频次、影响度，抓大放小，解决主要问题即可。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　就这样，其他方面，参见前提说明。</p><img src ="http://www.blogjava.net/qileilove/aggbug/400626.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-06-17 10:05 <a href="http://www.blogjava.net/qileilove/archive/2013/06/17/400626.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>批量迁移Oracle数据文件，日志文件及控制文件</title><link>http://www.blogjava.net/qileilove/archive/2013/06/13/400504.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 13 Jun 2013 02:27:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/06/13/400504.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/400504.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/06/13/400504.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/400504.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/400504.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 有些时候需要将Oracle的多个数据文件以及日志文件重定位或者迁移到新的分区或新的位置，比如磁盘空间不足，或因为特殊需求。对于这种情形可以采取批量迁移的方式将多个数据文件或者日志文件实现一次性迁移。当然备份恢复也是其中的方式之一。本文主要描述如何使用批量方式来迁移数据文件，日志文件。如需要也可以将整个数据库迁移到新的位置以及重命名数据库。　　1、环境及需求&nbsp; robin@SZDB:~&g...&nbsp;&nbsp;<a href='http://www.blogjava.net/qileilove/archive/2013/06/13/400504.html'>阅读全文</a><img src ="http://www.blogjava.net/qileilove/aggbug/400504.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-06-13 10:27 <a href="http://www.blogjava.net/qileilove/archive/2013/06/13/400504.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用RMAN迁移数据库到异机</title><link>http://www.blogjava.net/qileilove/archive/2013/06/13/400503.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 13 Jun 2013 02:25:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/06/13/400503.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/400503.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/06/13/400503.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/400503.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/400503.html</trackback:ping><description><![CDATA[<p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　迁移<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">数据库</strong></u></a>的方法有多种，较为常用的则是使用RMAN来迁移。使用RMAN迁移数据库属于数据库的物理备份与恢复范畴，整个过程中数据库的相关信息是完整地镜像。因此，基于此种方式还原恢复的数据库用于<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>会使得与真实的生产环境差异相对较小。本文描述了使用RMAN来还原<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Oracle</strong></u></a>&nbsp;10g数据库的过程。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">　　一、主要步骤</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1、备份数据库</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2、ftp备份到目的服务器</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　3、为目标数据库创建项目目录</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　4、为目标数据库创建pfile或spfile（使用RMAN还原或复制原pfile到目的服务器）</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　5、还原控制文件</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　6、还原数据文件</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　7、OPEN 数据库</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　其实，这几个步骤比较好理解，整个实质是对数据库体系结构以及数据库整个启动过程的理解。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　下面对此进行一下描述</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　a、首先需要为实例的运行环境创建相应的目录，如dump位置，datafile位置，以及archive位置等等</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　如果是恢复到不同的路径，则后续RMAN时需要使用set newname for datafile 方式更新到控制文件</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　b、实例需要pfile来启动，因此需要恢复pfile或spfile，然后将数据库切换到nomount状态</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　c、接下来的一步是通过控制文件将数据库切换到mount状态，因此需要恢复控制文件，然后再mount</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　d、mount之后就可以对数据库进行还原（restore）操作</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　e、还原完毕之后是对数据库进行恢复（recovery）操作（restore和recover需要基于控制文件的备份信息或恢复目录）</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　f、最后是open数据库</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">　　二、迁移演示</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1、备份原数据库</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　此处演示的源数据库与目标数据库使用相同的版本为Oracle 10g R2(10.2.0.3)，<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">操作系统</strong></u></a>都为suse 10 +Sp3</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　备份过程略，有关备份脚本，请参考：linux 下RMAN备份<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">shell</strong></u></a>脚本：http://blog.csdn.net/robinson_0612/article/details/8029245</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2、ftp所有的备份文件到需要恢复的服务器上</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　打包整个备份集ftp到目标服务器或scp到目标服务器</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　下面是ftp到目标服务器解压后包含的文件</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;">oracle@2go-devDB01uv:/u02/database/SY5221_RMAN/20121013&gt; ls -hltr<br style="word-break: break-all;" />total 9.4G<br style="word-break: break-all;" />-rw-r--r-- 1 oracle oinstall 3.0K 2012-10-16 09:48 initSY5221.ora<br style="word-break: break-all;" />-rw-r--r-- 1 oracle oinstall 2.7G 2012-10-16 10:02 SY5221_lev0_201210130630_4unnkjvi_1_1<br style="word-break: break-all;" />-rw-r--r-- 1 oracle oinstall 3.1G 2012-10-16 10:04 SY5221_lev0_201210130630_4vnnkjvi_1_1<br style="word-break: break-all;" />-rw-r--r-- 1 oracle oinstall 938M 2012-10-16 10:07 SY5221_lev0_201210130630_arc_51nnkk2h_1_1<br style="word-break: break-all;" />-rw-r--r-- 1 oracle oinstall 935M 2012-10-16 10:08 SY5221_lev0_201210130630_arc_52nnkk2h_1_1<br style="word-break: break-all;" />-rw-r--r-- 1 oracle oinstall 930M 2012-10-16 10:10 SY5221_lev0_201210130630_arc_53nnkk31_1_1<br style="word-break: break-all;" />-rw-r--r-- 1 oracle oinstall&nbsp; 15M 2012-10-16 10:10 SY5221_lev0_cntl_bak_c-1468911009-20121013-00<br style="word-break: break-all;" />-rw-r--r-- 1 oracle oinstall&nbsp; 15M 2012-10-16 10:10 SY5221_lev0_cntl_bak_c-1468911009-20121013-01<br style="word-break: break-all;" />-rw-r--r-- 1 oracle oinstall 910M 2012-10-16 10:11 SY5221_lev0_201210130630_arc_54nnkk32_1_1</td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　3、创建所需的目录（使用oracle用户）</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">oracle@2go-devDB01uv:~&gt; more mkdir_sy5221.sh<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/flash_recovery_area<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/archive<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/backup<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/bdump<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/cdump<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/udump<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/controlf<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/oradata<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/redolog<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/undo<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/temp<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/ref_data<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/BNR<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/BNR/full<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/BNR/dump<br style="word-break: break-all; line-height: normal !important;" />mkdir -p /u02/database/SY5221/dbcreatelogs</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">ORACLE_SID=SY5221; export ORACLE_SID<br style="word-break: break-all; line-height: normal !important;" />oracle@2go-devDB01uv:~&gt; chmod u+x mkdir_sy5221.sh<br style="word-break: break-all; line-height: normal !important;" />oracle@2go-devDB01uv:~&gt; ./mkdir_sy5221.sh</p></td></tr></tbody></table><br /><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　4、创建密码文件</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#111;&#114;&#97;&#99;&#108;&#101;&#64;&#50;&#103;&#111;&#45;&#100;&#101;&#118;&#68;&#66;&#48;&#49;&#117;&#118;" style="word-break: break-all; color: #202859; text-decoration: none;">oracle@2go-devDB01uv</a>:~&gt; cd $ORACLE_HOME/dbs<br style="word-break: break-all;" /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#111;&#114;&#97;&#99;&#108;&#101;&#64;&#50;&#103;&#111;&#45;&#100;&#101;&#118;&#68;&#66;&#48;&#49;&#117;&#118;&#58;&#126;&#47;&#79;&#114;&#97;&#72;&#111;&#109;&#101;&#49;&#48;&#103;&#47;&#100;&#98;&#115;" style="word-break: break-all; color: #202859; text-decoration: none;">oracle@2go-devDB01uv:~/OraHome10g/dbs</a>&gt; orapwd file=orapwSY5221 password=oracle force=y entries=10<br style="word-break: break-all;" /># Author : Robinson<br style="word-break: break-all;" /># Blog :&nbsp;<a href="http://blog.csdn.net/robinson_061" style="word-break: break-all; color: #202859; text-decoration: none;">http://blog.csdn.net/robinson_061</a></td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　5、使用pfile启动实例到nomount状态</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#111;&#114;&#97;&#99;&#108;&#101;&#64;&#50;&#103;&#111;&#45;&#100;&#101;&#118;&#68;&#66;&#48;&#49;&#117;&#118;" style="word-break: break-all; color: #202859; text-decoration: none;">oracle@2go-devDB01uv</a>:~&gt; cp /u02/database/SY5221_RMAN/20121013/initSY5221.ora $ORACLE_HOME/dbs<br style="word-break: break-all;" /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#111;&#114;&#97;&#99;&#108;&#101;&#64;&#50;&#103;&#111;&#45;&#100;&#101;&#118;&#68;&#66;&#48;&#49;&#117;&#118;" style="word-break: break-all; color: #202859; text-decoration: none;">oracle@2go-devDB01uv</a>:~&gt; export ORACLE_SID=SY5221<br style="word-break: break-all;" /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#111;&#114;&#97;&#99;&#108;&#101;&#64;&#50;&#103;&#111;&#45;&#100;&#101;&#118;&#68;&#66;&#48;&#49;&#117;&#118;" style="word-break: break-all; color: #202859; text-decoration: none;">oracle@2go-devDB01uv</a>:~&gt; sqlplus / as sysdba<br style="word-break: break-all;" />SQL&gt; startup nomount;</td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　6、恢复控制文件并切换到mount状态</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;">#再开一个session<br style="word-break: break-all;" /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#111;&#114;&#97;&#99;&#108;&#101;&#64;&#50;&#103;&#111;&#45;&#100;&#101;&#118;&#68;&#66;&#48;&#49;&#117;&#118;" style="word-break: break-all; color: #202859; text-decoration: none;">oracle@2go-devDB01uv</a>:~&gt; export ORACLE_SID=SY5221<br style="word-break: break-all;" /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#111;&#114;&#97;&#99;&#108;&#101;&#64;&#50;&#103;&#111;&#45;&#100;&#101;&#118;&#68;&#66;&#48;&#49;&#117;&#118;" style="word-break: break-all; color: #202859; text-decoration: none;">oracle@2go-devDB01uv</a>:~&gt; $ORACLE_HOME/bin/rman target /<br style="word-break: break-all;" />RMAN&gt; restore controlfile from '/u02/database/SY5221_RMAN/20121013/SY5221_lev0_cntl.bak_c-1468911009-20121013-01';<br style="word-break: break-all;" />RMAN&gt; alter database mount;</td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　7、指定备份文件所在目录</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;">RMAN&gt; catalog start with '/u02/database/SY5221_RMAN/20121013'; #此命令用于扫描整个目录的备份片或者归档日志文件等</td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　8、还原数据库</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;">RMAN&gt; restore database;</td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　9、恢复数据库</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; recover database;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">unable to find archive log<br style="word-break: break-all; line-height: normal !important;" />archive log thread=1 sequence=143388<br style="word-break: break-all; line-height: normal !important;" />RMAN-00571: ===========================================================<br style="word-break: break-all; line-height: normal !important;" />RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============<br style="word-break: break-all; line-height: normal !important;" />RMAN-00571: ===========================================================<br style="word-break: break-all; line-height: normal !important;" />RMAN-03002: failure of recover command at 10/16/2012 11:32:54<br style="word-break: break-all; line-height: normal !important;" />RMAN-06054: media recovery requesting unknown log: thread 1 seq 143388 lowscn 608805162<br style="word-break: break-all; line-height: normal !important;" />#由于未复制联机日志文件，此时提示需要seqence 143388,scn 608805162</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">#在sqlplus提示符下继续介质恢复<br style="word-break: break-all; line-height: normal !important;" />SQL&gt; conn / as sysdba<br style="word-break: break-all; line-height: normal !important;" />Connected.<br style="word-break: break-all; line-height: normal !important;" />idle&gt; recover database until cancel;<br style="word-break: break-all; line-height: normal !important;" />ORA-00283: recovery session canceled due to errors<br style="word-break: break-all; line-height: normal !important;" />ORA-01610: recovery using the BACKUP CONTROLFILE option must be done</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">SQL&gt; recover database using backup controlfile until cancel;<br style="word-break: break-all; line-height: normal !important;" />ORA-00279: change 608805162 generated at 10/13/2012 06:31:44 needed for thread 1<br style="word-break: break-all; line-height: normal !important;" />ORA-00289: suggestion : /u02/database/SY5221/archive/arch_668881377_1_143388.arc<br style="word-break: break-all; line-height: normal !important;" />ORA-00280: change 608805162 for thread 1 is in sequence #143388</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">Specify log: {&lt;RET&gt;=suggested | filename | AUTO | CANCEL}<br style="word-break: break-all; line-height: normal !important;" />cancel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #输入cancel，完成介质恢复<br style="word-break: break-all; line-height: normal !important;" />Media recovery cancelled.</p></td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　10、open 数据库</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　#如果open 不成功，请尝试shutdown 之后再次open，如果仍然不成功使用隐藏参数_allow_resetlogs_corruption打开数据库</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">SQL&gt; alter database open resetlogs;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">Database altered.</p></td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　11、一致性关闭数据库并重启数据库</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">SQL&gt; shutdown immediate;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">SQL&gt; startup</p></td></tr></tbody></table><img src ="http://www.blogjava.net/qileilove/aggbug/400503.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-06-13 10:25 <a href="http://www.blogjava.net/qileilove/archive/2013/06/13/400503.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RMAN 提示符下执行SQL语句</title><link>http://www.blogjava.net/qileilove/archive/2013/06/09/400428.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Sun, 09 Jun 2013 03:36:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/06/09/400428.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/400428.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/06/09/400428.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/400428.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/400428.html</trackback:ping><description><![CDATA[<p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">在手动恢复<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">数据库</strong></u></a>时，有时候需要在SQL*Plus提示符以及<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">操作系统</strong></u></a>提示符，RMAN提示符下来回切换显得有些繁琐。实际上RMAN为我们提供了命令行下执行一些简单的<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">SQL</strong></u></a>语句以及PL/SQL的方法，以避免上述情形。本文描述了RMAN提示符下的一些常用命令及其用法。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">　　1、RMAN提示符下执行SQL语句</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　语法： SQL '&lt;command&gt;' ;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　语法比较简单，就是提示符下输入SQL，后接SQL命令，命令用单引号括起来</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　command 通常为可执行的SQL命令语句，也可以为PL/SQL块</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　使用限制</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　　　如果SQL语句中包含文件名，则文件名及路径需要使用两个单引号括起来，整个SQL语句首尾需要使用双引号</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　　　可以执行SQL查询语句，但是无任何结果输出</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　RMAN提示符下常用的命令</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　　　startup [nomount | mount], shutdown immediate<br style="word-break: break-all; line-height: normal !important;" />　　　　alter system archive log current<br style="word-break: break-all; line-height: normal !important;" />　　　　alter database open [resetlogs]</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">　　2、演示RMAN提示符下执行SQL语句</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　a、执行常用的starup, alter SQL 语句</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;"><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#111;&#98;&#105;&#110;&#64;&#83;&#90;&#68;&#66;" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;">robin@SZDB</a>:~&gt; export ORACLE_SID=GOBO1<br style="word-break: break-all; line-height: normal !important;" /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#111;&#98;&#105;&#110;&#64;&#83;&#90;&#68;&#66;" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;">robin@SZDB</a>:~&gt; rman target /</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">Recovery Manager: Release 10.2.0.3.0 - Production on Tue Jun 4 11:04:26 2013</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">Copyright (c) 1982, 2005,&nbsp;<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Oracle</strong></u></a>.&nbsp; All rights reserved.</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">connected to target database (not started)</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; startup nomount;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">Oracle instance started</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">Total System Global Area&nbsp;&nbsp;&nbsp;&nbsp; 536870912 bytes</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">Fixed Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2074080 bytes<br style="word-break: break-all; line-height: normal !important;" />Variable Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 314575392 bytes<br style="word-break: break-all; line-height: normal !important;" />Database Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 213909504 bytes<br style="word-break: break-all; line-height: normal !important;" />Redo Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6311936 bytes</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; alter database mount;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">using target database control file instead of recovery catalog<br style="word-break: break-all; line-height: normal !important;" />database mounted</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; alter database open;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">database opened</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; list copy of archivelog all;&nbsp;&nbsp; ---&gt;查看当前数据库的归档<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">日志</strong></u></a>，列出了1个已归档日志</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;"><br style="word-break: break-all; line-height: normal !important;" />List of Archived Log Copies<br style="word-break: break-all; line-height: normal !important;" />Key&nbsp;&nbsp;&nbsp;&nbsp; Thrd Seq&nbsp;&nbsp;&nbsp;&nbsp; S Low Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name<br style="word-break: break-all; line-height: normal !important;" />------- ---- ------- - ----------------- ----<br style="word-break: break-all; line-height: normal !important;" />2084&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp; 8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A 20130604 09:53:17 /u02/database/GOBO1/archive/arch_816906485_1_8.arc</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; sql ' alter system archive log current ';&nbsp;&nbsp; ---&gt;对当前日志进行归档</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">sql statement:&nbsp; alter system archive log current</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; list copy of archivelog all;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ---&gt;归档后可以看到多出了1个已归档日志</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">List of Archived Log Copies<br style="word-break: break-all; line-height: normal !important;" />Key&nbsp;&nbsp;&nbsp;&nbsp; Thrd Seq&nbsp;&nbsp;&nbsp;&nbsp; S Low Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name<br style="word-break: break-all; line-height: normal !important;" />------- ---- ------- - ----------------- ----<br style="word-break: break-all; line-height: normal !important;" />2084&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp; 8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A 20130604 09:53:17 /u02/database/GOBO1/archive/arch_816906485_1_8.arc<br style="word-break: break-all; line-height: normal !important;" />2085&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp; 9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A 20130604 10:46:36 /u02/database/GOBO1/archive/arch_816906485_1_9.arc</p></td></tr></tbody></table><br /><br /><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">b、执行SQL查询语句，如下，没有任何结果输出</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; sql 'select sysdate from dual';</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">sql statement: select sysdate from dual</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; sql ' select * from v$database ';</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">sql statement:&nbsp; select * from v$database</p></td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　c、执行带有路径及文件名的SQL语句</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">--下面的执行那个中没有使用双引号开头以及双单引号括住路径，收到错误提示<br style="word-break: break-all; line-height: normal !important;" />RMAN&gt; sql ' create tablespace ts1 datafile '/u02/database/GOBO1/oradata/ts1.dbf' size 10m ';</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN-00571: ===========================================================<br style="word-break: break-all; line-height: normal !important;" />RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============<br style="word-break: break-all; line-height: normal !important;" />RMAN-00571: ===========================================================<br style="word-break: break-all; line-height: normal !important;" />RMAN-00558: error encountered while parsing input commands<br style="word-break: break-all; line-height: normal !important;" />RMAN-01006: error signalled during parse<br style="word-break: break-all; line-height: normal !important;" />RMAN-02001: unrecognized punctuation symbol "/"</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">--下面的SQL语句被成功执行<br style="word-break: break-all; line-height: normal !important;" />RMAN&gt; sql "create tablespace ts1 datafile ''/u02/database/GOBO1/oradata/ts1.dbf'' size 10m";</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">sql statement: create tablespace ts1 datafile ''/u02/database/GOBO1/oradata/ts1.dbf'' size 10m</p></td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　d、执行PL/SQL块</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; sql ' begin dbms_lock.sleep(3); end;';</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">sql statement:&nbsp; begin dbms_lock.sleep(3); end;</p></td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　e、rman块命令方式执行PL/SQL块</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; run{<br style="word-break: break-all; line-height: normal !important;" />2&gt; sql ' begin dbms_lock.sleep(3); end; ';<br style="word-break: break-all; line-height: normal !important;" />3&gt; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">sql statement:&nbsp; begin dbms_lock.sleep(3); end;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; run {<br style="word-break: break-all; line-height: normal !important;" />2&gt; sql ' drop tablespace ts1 including contents and datafiles ';<br style="word-break: break-all; line-height: normal !important;" />3&gt; }</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">sql statement:&nbsp; drop tablespace ts1 including contents and datafiles</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; shutdown immediate;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">database closed<br style="word-break: break-all; line-height: normal !important;" />database dismounted<br style="word-break: break-all; line-height: normal !important;" />Oracle instance shut down</p></td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　f、切换到系统提示符下</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><table align="center" style="word-break: break-all; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border-style: solid; border-color: #999999; background-color: #dddddd; width: 612px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt; host;</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">robin@SZDB:~&gt; exit<br style="word-break: break-all; line-height: normal !important;" />exit<br style="word-break: break-all; line-height: normal !important;" />host command complete</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 1.8em !important;">RMAN&gt;</p></td></tr></tbody></table><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></p><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff; height: 21px; position: relative; width: 627.1875px;"></div><img src ="http://www.blogjava.net/qileilove/aggbug/400428.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-06-09 11:36 <a href="http://www.blogjava.net/qileilove/archive/2013/06/09/400428.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle 索引监控（monitor index）</title><link>http://www.blogjava.net/qileilove/archive/2013/06/08/400387.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Sat, 08 Jun 2013 04:34:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/06/08/400387.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/400387.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/06/08/400387.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/400387.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/400387.html</trackback:ping><description><![CDATA[合理的为<a href="javascript:;" target="_self"><u><strong>数据库</strong></u></a>表上创建战略性索引，可以极大程度的提高了查询性能。但事实上日常中我们所创建的索引并非战略性索引，恰恰是大量冗余或是根本没有用到的索引耗用了大量的存储空间，导致DML性能低下。<a href="javascript:;" target="_self"><u><strong>Oracle</strong></u></a> 提供了索引监控特性来初略判断未使用到的索引。本文描述如何使用Oracle 索引的监控。 
<p><strong>　　1、冗余索引的弊端</strong></p>
<p>　　大量冗余和无用的索引导致整个数据库性能低下，耗用了大量的CPU与I/O开销，具体表现如下:</p>
<p>　　a、耗用大量的存储空间(索引段的维护与管理)</p>
<p>　　b、增加了DML完成的时间</p>
<p>　　c、耗用大量统计信息(索引)收集的时间</p>
<p>　　d、结构性验证时间</p>
<p>　　f、增加了恢复所需的时间</p>
<p><strong>　　2、单个索引监控</strong></p>
<p>　　a、对于单个索引的监控，可以使用下面的命令来完成</p>
<p>
<table style="border-right: #999 1px solid; border-top: #999 1px solid; font-size: 12px; border-left: #999 1px solid; width: 98%; border-bottom: #999 1px solid; background-color: #dddddd" align="center">
<tbody>
<tr>
<td>alter index &lt;INDEX_NAME&gt; monitoring usage;</td></tr></tbody></table></p>
<p>　　b、关闭索引监控</p>
<p>
<table style="border-right: #999 1px solid; border-top: #999 1px solid; font-size: 12px; border-left: #999 1px solid; width: 98%; border-bottom: #999 1px solid; background-color: #dddddd" align="center">
<tbody>
<tr>
<td>alter index &lt;INDEX_NAME&gt; nomonitoring usage;</td></tr></tbody></table></p>
<p>　　c、观察监控结果（查询v$object_usage视图）</p>
<p>
<table style="border-right: #999 1px solid; border-top: #999 1px solid; font-size: 12px; border-left: #999 1px solid; width: 98%; border-bottom: #999 1px solid; background-color: #dddddd" align="center">
<tbody>
<tr>
<td>select * from v$object_usage</td></tr></tbody></table></p>
<p><strong>　　3、schema级别索引监控（不含SYS用户）</strong></p>
<p>　　a、直接执行脚本来开启索引监控</p>
<p>
<table style="border-right: #999 1px solid; border-top: #999 1px solid; font-size: 12px; border-left: #999 1px solid; width: 98%; border-bottom: #999 1px solid; background-color: #dddddd" align="center">
<tbody>
<tr>
<td>
<p><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#111;&#98;&#105;&#110;&#64;&#83;&#90;&#68;&#66;&#58;&#126;&#47;&#100;&#98;&#97;&#95;&#115;&#99;&#114;&#105;&#112;&#116;&#115;&#47;&#99;&#117;&#115;&#116;&#111;&#109;&#47;&#115;&#113;&#108;">robin@SZDB:~/dba_scripts/custom/sql</a>&gt; more idx_monitor_on.sql<br />SET HEADING OFF&nbsp; FEEDBACK OFF&nbsp; TERMOUT OFF&nbsp; ECHO OFF;<br />SET PAGESIZE 0;<br />SPOOL /tmp/mnt_idx.sql</p>
<p>SELECT 'ALTER INDEX ' || owner || '.' || index_name || ' MONITORING USAGE;'<br />&nbsp; FROM dba_indexes<br />&nbsp; WHERE owner IN (SELECT username<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM dba_users<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE account_status = 'OPEN')<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND owner NOT IN ('SYS', 'SYSTEM', 'PERFSTAT', 'MGMT_VIEW', 'MONITOR', 'SYSMAN', 'DBSNMP');</p>
<p>SPOOL OFF;<br />@/tmp/mnt_idx.sql;<br />SET HEADING ON FEEDBACK ON&nbsp; TERMOUT ON;<br />SET PAGESIZE 80;</p>
<p>SELECT index_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; monitoring,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; used,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start_monitoring,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end_monitoring<br />&nbsp; FROM v$object_usage;</p>
<p>ho rm -rf /tmp/mnt_idx.sql</p></td></tr></tbody></table></p>
<p>　　b、禁用索引监控</p>
<p>
<table style="border-right: #999 1px solid; border-top: #999 1px solid; font-size: 12px; border-left: #999 1px solid; width: 98%; border-bottom: #999 1px solid; background-color: #dddddd" align="center">
<tbody>
<tr>
<td>
<p><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#111;&#98;&#105;&#110;&#64;&#83;&#90;&#68;&#66;&#58;&#126;&#47;&#100;&#98;&#97;&#95;&#115;&#99;&#114;&#105;&#112;&#116;&#115;&#47;&#99;&#117;&#115;&#116;&#111;&#109;&#47;&#115;&#113;&#108;">robin@SZDB:~/dba_scripts/custom/sql</a>&gt; more idx_monitor_off.sql<br />SET HEADING OFF&nbsp; FEEDBACK OFF&nbsp; TERMOUT OFF&nbsp; ECHO OFF;<br />SET PAGESIZE 0;<br />SPOOL /tmp/un_mnt_idx.sql<br />SELECT 'ALTER INDEX ' || owner || '.' || index_name || ' NOMONITORING USAGE;'<br />&nbsp; FROM dba_indexes<br />&nbsp; WHERE owner IN (SELECT username<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM dba_users<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE account_status = 'OPEN')<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND owner NOT IN ('SYS', 'SYSTEM', 'PERFSTAT', 'MGMT_VIEW', 'MONITOR', 'SYSMAN', 'DBSNMP');</p>
<p>SPOOL OFF;<br />@/tmp/un_mnt_idx.sql;<br />SET HEADING ON FEEDBACK ON&nbsp; TERMOUT ON;<br />SET PAGESIZE 80;</p>
<p>SELECT index_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; monitoring,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; used,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start_monitoring,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end_monitoring<br />&nbsp; FROM v$object_usage;</p>
<p>ho rm -rf /tmp/un_mnt_idx.sql</p></td></tr></tbody></table></p>
<p>　　c、查看索引监控结果</p>
<p>
<table style="border-right: #999 1px solid; border-top: #999 1px solid; font-size: 12px; border-left: #999 1px solid; width: 98%; border-bottom: #999 1px solid; background-color: #dddddd" align="center">
<tbody>
<tr>
<td>set linesize 190<br />SELECT u.name owner,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; io.name index_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t.name table_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DECODE (BITAND (i.flags, 65536), 0, 'NO', 'YES') monitoring,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DECODE (BITAND (ou.flags, 1), 0, 'NO', 'YES') used,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ou.start_monitoring start_monitoring,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ou.end_monitoring end_monitoring<br />&nbsp; FROM sys.user$ u,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.obj$ io,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.obj$ t,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.ind$ i,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.object_usage ou<br />&nbsp;WHERE i.obj# = ou.obj# AND io.obj# = ou.obj# AND t.obj# = i.bo# AND u.user# = io.owner#<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND u.name=decode(upper('&amp;input_owner'),'ALL',u.name,upper('&amp;input_owner'));</td></tr></tbody></table></p>　4、演示索引监控 
<p>　　a、单个索引监控</p>
<p>
<table style="border-right: #999 1px solid; border-top: #999 1px solid; font-size: 12px; border-left: #999 1px solid; width: 98%; border-bottom: #999 1px solid; background-color: #dddddd" align="center">
<tbody>
<tr>
<td>
<p>--&gt;演示环境<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; select * from v$version where rownum&lt;2;</p>
<p>BANNER<br />----------------------------------------------------------------<br />Oracle Database 10g Release 10.2.0.3.0 - 64bit Production</p>
<p>--&gt;创建测试表<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; create table tb_emp as select * from emp;</p>
<p>--&gt;为测试表创建索引<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; create index i_tb_emp_empno on tb_emp(empno);</p>
<p>--&gt;收集统计信息<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; exec dbms_stats.gather_table_stats('SCOTT','TB_EMP',cascade=&gt;true);</p>
<p>--&gt;查看索引信息<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; @idx_info<br />Enter value for owner: scott<br />Enter value for table_name: tb_emp</p>
<p>Table Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CL_NAM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CL_POS STATUS&nbsp;&nbsp; IDX_TYP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DSCD<br />------------------------- ------------------------------ -------------------- ------ -------- --------------- ----<br />TB_EMP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I_TB_EMP_EMPNO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EMPNO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 VALID&nbsp;&nbsp;&nbsp; NORMAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ASC</p>
<p>--&gt;查看索引使用情况<br />--&gt;此时use列为NO，表明索引未被使用到<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; @idx_usage_tb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Enter value for 1: tb_emp<br />Enter value for 2: all<br />Enter value for 2: all</p>
<p>Table Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; USE START_MONITORING&nbsp;&nbsp;&nbsp; END_MONITORING<br />------------------------- ------------------------------ --- ------------------- -------------------<br />TB_EMP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I_TB_EMP_EMPNO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NO&nbsp; 03/19/2013 17:43:49</p>
<p>--&gt;实施即席查询<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; select empno,ename,job from tb_emp where empno=7788;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; EMPNO ENAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JOB<br />---------- ---------- ---------<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7788 SCOTT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANALYST</p>
<p>--&gt;再次查看时USE列已经为YES<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; @idx_usage_tb<br />Enter value for 1: tb_emp<br />Enter value for 2: all<br />Enter value for 2: all</p>
<p>Table Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; USE START_MONITORING&nbsp;&nbsp;&nbsp; END_MONITORING<br />------------------------- ------------------------------ --- ------------------- -------------------<br />TB_EMP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I_TB_EMP_EMPNO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES 03/19/2013 17:43:49</p>
<p>--&gt;禁用索引监控<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; alter index I_TB_EMP_EMPNO nomonitoring usage;</p>
<p>Index altered.</p></td></tr></tbody></table></p>
<p>　　b、schema级别的索引监控</p>
<p>
<table style="border-right: #999 1px solid; border-top: #999 1px solid; font-size: 12px; border-left: #999 1px solid; width: 98%; border-bottom: #999 1px solid; background-color: #dddddd" align="center">
<tbody>
<tr>
<td>
<p>--&gt;切换到另外一个数据库cnbo1<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">scott@CNMMBO</a>&gt; conn <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#111;&#101;&#120;&#95;&#97;&#100;&#109;&#105;&#110;&#47;&#120;&#120;&#120;&#120;&#120;&#64;&#99;&#110;&#98;&#111;&#49;">goex_admin/xxxxx@cnbo1</a><br />Connected.</p>
<p>--&gt;下面的查询表明没有表开启索引监控<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#111;&#101;&#120;&#95;&#97;&#100;&#109;&#105;&#110;&#64;&#67;&#78;&#66;&#79;&#49;">goex_admin@CNBO1</a>&gt; @idx_usage;</p>
<p>no rows selected</p>
<p>--&gt;开启索引监控<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#111;&#101;&#120;&#95;&#97;&#100;&#109;&#105;&#110;&#64;&#67;&#78;&#66;&#79;&#49;">goex_admin@CNBO1</a>&gt; @idx_monitor_on</p>
<p>INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MON USE START_MONITORING&nbsp;&nbsp;&nbsp; END_MONITORING<br />------------------------------ --- --- ------------------- -------------------<br />PK_AAH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES NO&nbsp; 03/19/2013 17:48:32<br />IDX_GOAAE1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES NO&nbsp; 03/19/2013 17:48:32<br />PK_GOAAT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES NO&nbsp; 03/19/2013 17:48:32<br />PK_GOAACTL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES NO&nbsp; 03/19/2013 17:48:32<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; ................</p>
<p>--&gt;关闭索引监控<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#111;&#101;&#120;&#95;&#97;&#100;&#109;&#105;&#110;&#64;&#67;&#78;&#66;&#79;&#49;">goex_admin@CNBO1</a>&gt; @idx_monitor_off<br />INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MON USE START_MONITORING&nbsp;&nbsp;&nbsp; END_MONITORING<br />------------------------------ --- --- ------------------- -------------------<br />PK_GOARL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NO&nbsp; NO&nbsp; 03/19/2013 17:48:30 03/19/2013 17:50:02<br />IDX_GOAQU1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NO&nbsp; NO&nbsp; 03/19/2013 17:48:30 03/19/2013 17:50:02<br />IDX_GOAQU2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NO&nbsp; NO&nbsp; 03/19/2013 17:48:30 03/19/2013 17:50:02</p>
<p>--&gt;连接到原来的db，查看曾经开启索引监控的使用情况<br /><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#111;&#101;&#120;&#95;&#97;&#100;&#109;&#105;&#110;&#64;&#67;&#78;&#66;&#79;&#49;">goex_admin@CNBO1</a>&gt; conn <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#99;&#111;&#116;&#116;&#47;&#116;&#105;&#103;&#101;&#114;&#64;&#99;&#110;&#109;&#109;&#98;&#111;">scott/tiger@cnmmbo</a></p>
<p>Connected.</p>
<p><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#111;&#101;&#120;&#95;&#97;&#100;&#109;&#105;&#110;&#64;&#67;&#78;&#77;&#77;&#66;&#79;">goex_admin@CNMMBO</a>&gt; @idx_usage<br />Enter value for input_owner: GOEX_ADMIN<br />Enter value for input_owner: GOEX_ADMIN</p>
<p>OWNER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Table Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MON USE START_MONITORING&nbsp;&nbsp;&nbsp; END_MONITORING<br />--------------- ------------------------------ ------------------------- --- --- ------------------- ----------------<br />SCOTT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I_TB_EMP_EMPNO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TB_EMP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NO&nbsp; YES 03/19/2013 17:43:49 03/19/2013 17:46:04<br />GOEX_ADMIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ACC_GRP_EXT_INFO_TBL_LOG_PK&nbsp;&nbsp;&nbsp; ACC_GRP_EXT_INFO_TBL_LOG&nbsp; YES YES 02/22/2013 15:58:42<br />GOEX_ADMIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IDX_TDCL_CONTRACT_NUM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRADE_CLIENT_TBL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES YES 02/22/2013 15:58:42<br />GOEX_ADMIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IDX_TDCL_SETTLED_DATE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRADE_CLIENT_TBL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES YES 02/22/2013 15:58:42<br />GOEX_ADMIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IDX_TDCL_ACC_NUM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRADE_CLIENT_TBL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES YES 02/22/2013 15:58:41<br />GOEX_ADMIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IDX_TDCL_INSTRU_ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRADE_CLIENT_TBL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES YES 02/22/2013 15:58:42</p></td></tr></tbody></table></p>
<p><strong>　　5、索引监控的建议与弊端</strong></p>
<p>　　a、选择数据库高峰期实施索引监控，以及尽可能使用较长的监控周期来判断索引是否被使用</p>
<p>　　b、可以对特定时间段实施多次监控以判断索引的使用频率（初略值）</p>
<p>　　c、索引监控在一定程度上耗用系统资源，一旦监控完毕后应即时关闭以避免其带来的额外开销</p>
<p>　　d、索引监控仅仅从索引的使用与否来描述索引使用，并未提供详细的索引使用频率，b点提到的方法也只是初略值</p><img src ="http://www.blogjava.net/qileilove/aggbug/400387.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-06-08 12:34 <a href="http://www.blogjava.net/qileilove/archive/2013/06/08/400387.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle 监听器日志配置与管理</title><link>http://www.blogjava.net/qileilove/archive/2013/06/03/400098.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 03 Jun 2013 05:20:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/06/03/400098.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/400098.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/06/03/400098.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/400098.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/400098.html</trackback:ping><description><![CDATA[<div>　<a target="_self"><u><strong>Oracle</strong></u></a> 监听器是一个服务器端程序，用于监听所有来自客户端的请求，并为其提供<a target="_self"><u><strong>数据库</strong></u></a>服务。因此对监听器的管理与维护相当重要。<p>　　本文主要描述对Oracle监听器<a target="_self"><u><strong>日志</strong></u></a>文件的配置与管理。</p><p><strong>　　一、监听器日志特性</strong></p><p>　　1、监听器日志是一个纯文本文件，通常位于$ORACLE_HOME/network/log目录下，与sqlnet.log日志文件处于同一路径</p><p>　　2、其缺省的文件名为listener.log。对于非缺省的监听器，则产生的日志文件通常为listenername.log</p><p>　　3、该文件缺省由监听器自动创建，当日志文件丢失时或不存在时，会自动重新创建一个同名的文件，与alert_&lt;SID&gt;.log文件类似</p><p>　　4、该文件的尺寸会不断自动增长，当尺寸过大时或不便于阅读时，考虑将其备份</p><p>　　5、Oracle监听器在运行时不允许对日志文件做删除，重命名操作</p><p>　　6、可以设置日志状态为ON或OFF来实现启用或关闭日志</p><p><strong>　　二、设置日志文件目录及路径</strong></p><p>　　1、设置日志文件目录的两种方法</p><table style="border-bottom: #999 1px solid; border-left: #999 1px solid; background-color: #dddddd; width: 98%; font-size: 12px; border-top: #999 1px solid; border-right: #999 1px solid" align="center"><tbody><tr><td>lsnrctl SET LOG_DIRECTORY directory<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />LSNRCTL&gt; SET LOG_DIRECTORY /usr/oracle/admin/log</td></tr></tbody></table><p>　　2、设置日志文件的两种方法</p><table style="border-bottom: #999 1px solid; border-left: #999 1px solid; background-color: #dddddd; width: 98%; font-size: 12px; border-top: #999 1px solid; border-right: #999 1px solid" align="center"><tbody><tr><td>&nbsp;lsnrctl SET LOG_FILE file_name<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;LSNRCTL&gt; SET LOG_FILE file_name</td></tr></tbody></table><p>　　3、设置日志的状态</p><table style="border-bottom: #999 1px solid; border-left: #999 1px solid; background-color: #dddddd; width: 98%; font-size: 12px; border-top: #999 1px solid; border-right: #999 1px solid" align="center"><tbody><tr><td><p>&nbsp;lsnrctl SET LOG_STATUS {on | off}</p><p>&nbsp;LSNRCTL&gt; SET LOG_STATUS {on | off}</p></td></tr></tbody></table><p>　　4、演示设置</p><p>　　a）切换到日志目录查看日志文件</p><table style="border-bottom: #999 1px solid; border-left: #999 1px solid; background-color: #dddddd; width: 98%; font-size: 12px; border-top: #999 1px solid; border-right: #999 1px solid" align="center"><tbody><tr><td>&nbsp;[oracle@test ~]$ cd $ORACLE_HOME/network/log&nbsp;&nbsp;&nbsp;<br />&nbsp;[oracle@test log]$ ls -hltr<br />&nbsp;total 348K<br />&nbsp;-rw-r--r--&nbsp; 1 oracle oinstall 305K Apr&nbsp; 6 05:30 listener.log<br />&nbsp;-rw-r--r--&nbsp; 1 oracle oinstall&nbsp; 26K Jun 27 01:52 listener_demo92.log</td></tr></tbody></table><p>　　b）查看当前监听器的状态</p>&nbsp;[oracle@test log]$ lsnrctl status listener_demo92<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;LSNRCTL for <a target="_self"><u><strong>Linux</strong></u></a>: Version 9.2.0.8.0 - Production on 27-JUN-2011 01:54:31<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;Copyright (c) 1991, 2006, Oracle Corporation.&nbsp; All rights reserved.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))<br />&nbsp;STATUS of the LISTENER<br />&nbsp;------------------------<br />&nbsp;Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listener_demo92<br />&nbsp;Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TNSLSNR for Linux: Version 9.2.0.8.0 - Production<br />&nbsp;Start Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 27-JUN-2011 01:52:18<br />&nbsp;Uptime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 days 0 hr. 2 min. 13 sec<br />&nbsp;Trace Level&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; off<br />&nbsp;Security&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ON<br />&nbsp;SNMP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OFF<br />&nbsp;Listener Parameter File&nbsp;&nbsp; /oracle/92/network/admin/listener.ora<br />&nbsp;Listener Log File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /oracle/92/network/log/listener_demo92.log<br />&nbsp;Listening Endpoints Summary...<br />&nbsp;(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=1521)))<br />&nbsp;(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))<br />&nbsp;Services Summary...<br />&nbsp;Service "demo92" has 1 instance(s).<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Instance "demo92", status READY, has 1 handler(s) for this service...<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The command completed successfully&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div>　c）设置监听器目录及日志文件 <p> </p><table style="border-bottom: #999 1px solid; border-left: #999 1px solid; background-color: #dddddd; width: 98%; font-size: 12px; border-top: #999 1px solid; border-right: #999 1px solid" align="center"> <tbody> <tr> <td>LSNRCTL&gt; set current_listener listener_demo92&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;&nbsp; <br />Current Listener is listener_demo92&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LSNRCTL&gt; set password&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;&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 />Password:&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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />The command completed successfully&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LSNRCTL&gt; set log_directory /home/oracle/log&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;&nbsp;&nbsp;&nbsp; <br />Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))&nbsp;&nbsp;&nbsp;&nbsp; <br />listener_demo92 parameter "log_directory" set to /home/oracle/log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />The command completed successfully&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LSNRCTL&gt; set log_file listener_test.log&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))&nbsp;&nbsp;&nbsp;&nbsp; <br />listener_demo92 parameter "log_file" set to listener_test.log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />The command completed successfully&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LSNRCTL&gt; set log_status on&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))&nbsp;&nbsp;&nbsp;&nbsp; <br />listener_demo92 parameter "log_status" set to ON&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 />The command completed successfully&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LSNRCTL&gt; save_config&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;&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 />Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))&nbsp;&nbsp;&nbsp;&nbsp; <br />Saved listener_demo92 configuration parameters.&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 />Listener Parameter File&nbsp;&nbsp; /oracle/92/network/admin/listener.ora&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Old Parameter File&nbsp;&nbsp; /oracle/92/network/admin/listener.bak&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />The command completed successfully&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LSNRCTL&gt; exit&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;&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;&nbsp; </td></tr></tbody></table> <p>　　d）查看新路径下产生的日志文件</p> <p> </p><table style="border-bottom: #999 1px solid; border-left: #999 1px solid; background-color: #dddddd; width: 98%; font-size: 12px; border-top: #999 1px solid; border-right: #999 1px solid" align="center"> <tbody> <tr> <td>[oracle@test admin]$ cd /home/oracle/log&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;&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 />[oracle@test log]$ ls -hltr&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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />total 16K&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;&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;&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 />-rw-r--r--&nbsp; 1 oracle oinstall&nbsp; 41 Jun 27 02:11 listener_demo92.log&nbsp; --&gt;设置目录之后生成的&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />-rw-r--r--&nbsp; 1 oracle oinstall 113 Jun 27 02:12 listener_test.log&nbsp;&nbsp;&nbsp; --&gt;设置日志文件名之后的新日志文件 <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;&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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />[oracle@test log]$ ls -hltr&nbsp;&nbsp;&nbsp; --&gt;隔段时间查看，原来的日志文件不再增长，使用设定的日志文件名记录日志&nbsp; <br />total 16K&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;&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;&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 />-rw-r--r--&nbsp; 1 oracle oinstall&nbsp;&nbsp; 41 Jun 27 02:11 listener_demo92.log&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;&nbsp;&nbsp; <br />-rw-r--r--&nbsp; 1 oracle oinstall 1.3K Jun 27 02:17 listener_test.log&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;&nbsp;&nbsp;&nbsp;&nbsp; </td></tr></tbody></table> <p>　　e）查看listener.ora配置文件的变化</p> <p> </p>   [oracle@test admin]$ more listener.ora&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />#----ADDED BY TNSLSNR 27-JUN-2011 02:12:37---&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LOG_DIRECTORY_listener_demo92 = /home/oracle/log&nbsp;&nbsp; <br />LOG_FILE_listener_demo92 = listener_test.log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LOGGING_listener_demo92 = ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />#--------------------------------------------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div><div><strong>三、日志文件的备份与重命名</strong> <p>　　通常情况下，需要停止监听器来对日志文件进行备份，下面使用不停止监听的情况下对日志文件重命名以实现备份</p> <p>　　1、Windows平台的处理</p> <p> </p><table style="border-bottom: #999 1px solid; border-left: #999 1px solid; background-color: #dddddd; width: 98%; font-size: 12px; border-top: #999 1px solid; border-right: #999 1px solid" align="center"> <tbody> <tr> <td>C:\&gt;cd \oracle\ora92\network\log&nbsp;&nbsp;&nbsp;&nbsp; --&gt;切换到监听器日志文件所在目录&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />C:\oracle\ora92\network\log&gt; lsnrctl set log_status off --&gt;暂停或脱机记录日志文件&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 />C:\oracle\ora92\network\log&gt; rename listener.log listener.old --&gt;重命名日志文件，一般加上日期&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />C:\oracle\ora92\network\log&gt; lsnrctl set log_status on --&gt;联机监听器日志文件，会自动重新创建一个新的日志文件 </td></tr></tbody></table> <p>　　2、Unix/Linux平台的处理</p> <p> </p><table style="border-bottom: #999 1px solid; border-left: #999 1px solid; background-color: #dddddd; width: 98%; font-size: 12px; border-top: #999 1px solid; border-right: #999 1px solid" align="center"> <tbody> <tr> <td>$ lsnrctl set log_status off&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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />$ mv listener.log listener.old --&gt;另一种方法，cp listener.log /log/bak/. 然后 cp /dev/null &gt;listener.log <br />$ lsnrctl set log_status on &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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td></tr></tbody></table> <p>　　3、演示Linux平台下重命名日志文件</p> <p> </p><table style="border-bottom: #999 1px solid; border-left: #999 1px solid; background-color: #dddddd; width: 98%; font-size: 12px; border-top: #999 1px solid; border-right: #999 1px solid" align="center"> <tbody> <tr> <td>[oracle@test ~]$ cd /home/oracle/log&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />[oracle@test log]$ lsnrctl set log_status off&nbsp; --&gt;如果存在密码，应使用LSNRCTL界面来完成 <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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LSNRCTL for Linux: Version 9.2.0.8.0 - Production on 27-JUN-2011 02:41:09&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Copyright (c) 1991, 2006, Oracle Corporation.&nbsp; All rights reserved.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Connecting to (ADDRESS=(PROTOCOL=tcp)(PORT=1521))&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LISTENER parameter "log_status" set to OFF&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />The command completed successfully&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />[oracle@test log]$ mv listener_test.log listener_test.old&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 />[oracle@test log]$ lsnrctl set log_status on&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LSNRCTL for Linux: Version 9.2.0.8.0 - Production on 27-JUN-2011 02:41:31&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Copyright (c) 1991, 2006, Oracle Corporation.&nbsp; All rights reserved.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Connecting to (ADDRESS=(PROTOCOL=tcp)(PORT=1521))&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />LISTENER parameter "log_status" set to ON&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />The command completed successfully&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></tbody></table></div><img src ="http://www.blogjava.net/qileilove/aggbug/400098.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-06-03 13:20 <a href="http://www.blogjava.net/qileilove/archive/2013/06/03/400098.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>测试大数据实施——如何区别于测试数据仓库</title><link>http://www.blogjava.net/qileilove/archive/2013/05/28/399851.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 28 May 2013 02:28:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/05/28/399851.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/399851.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/05/28/399851.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/399851.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/399851.html</trackback:ping><description><![CDATA[<p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　无论它是一个数据仓库（DWH）还是一个大数据存储系统，我们<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>员关注的基本要素便是这&#8216;数据&#8217;。在基础水平上，数据验证是为了在这两种存储系统中针对源系统涉及的数据验证明确业务规则。这是个很容易思考的事，如果我们认识到如何测试一个DWH，我们就知道如何测试大数据存储系统。但遗憾的是，事实并非如此！在博客中，我将会阐述一些区别在这些存储系统和提出一个<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">学习</strong></u></a>大数据测试的途径。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　让我们从下面的3 个观点展示中查看这些区别：</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　&#9679; 数据</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　&#9679; 基础设施</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　&#9679; 验证工具</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">数据</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　在DWH 的数据与大数据存储系统的区别是数据的4个基本特性，是数据量、数据种类、数据速率和数据值。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　现在能够存储在DWH系统中典型的数据是依据G，而大数据存储系统能够存储&amp;处理数据大小超过PB。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　当达到一定数据种类时，在大数据存储系统中能够被存储和处理的数据类型并没有限制。Web日志，无线射频识别，传感器网络，社交网络，<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">互联网</strong></u></a>文本和文件，互联网搜索引擎，呼叫详细记录，天文学，大气科学，生物学，基因学，生化学，医学的记录，科学研究，军事监视，摄影档案，视频档案，和大规模的电子商务的任何数据，在大存储系统中，无论它是在可容许的运行时间内被存储和有效处理的结构化的或者未结构化的忽略的数据。另一方面，DWH能够存储和处理的仅仅是结构化的数据。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　虽然存储在DWH中的数据是通过&#8216;批处理&#8217;，大量的数据实现也支持流数据。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　因为它的捕获，管理和处理数据集大小的能力是超过DWH的能力，能够派生出大数据实现的数据值/商业价值的信息是成倍大于DWH系统。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">这对测试人员意味着什么呢？</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　一个DWH测试仪拥有与&#8216;结构化&#8217;数据兼容的这种优势。（倾向于静态模式数据）。但大数据的测试仪可能需要与&#8216;非结构化或者半导体结构化&#8217;数据（倾向于动态模式数据）绝大部分时间兼容。测试人员需要从商业/开发团队那里寻找一些附加输入关于&#8216;如何从已知的数据派生出结构化动态数据&#8217;。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　在DWH中，当它谈论到实际验证的数据时，测试方法是良好定义的和经过时间考验的。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　测试人员可选择使用手动抽样策略或从<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>工具里详细的验证策略，像Infosys Perfaware（专业的DWH测试解决方案）。但是考虑到为了验证庞大的数据集，甚至抽样测试在大数据验证的情况下是有挑战的。第三产业和自动化解决方案两者正处于孵化期，测试大数据最好的方法是能够下定决心来只有通过专注研发。这为测试人员提供非常多的机遇来创新、并且加倍努力来构建能够提供测试优势的工具，同样的来提高测试效率。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　基础设施</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　DWH系统是基于RDBMS而大数据存储系统是基于文件系统。当DWH系统在线性数据增长方面受到限制时，那些基于Apache安装的大数据实现是不会受到限制，它们能够在多个集群方面存储数据。这个存储是由HDFS（安装分布式文件系统）来提供的，一个可靠的共享存储系统能够运用分析应用MapReduce技术。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">这对测试人员意味着什么呢？</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　作为HDFS 给客户产生力量来存储大量的数据类型，运行整个数据集的询问和在合理的诗句内返回结果时，它们在自己派生出的大量数据信息方面不再受到限制。应用复杂的转换和业务规则将会是很容易的。这种力量将会通向一种数据探索的新方法。对于一个测试员，这意味着，指数增长大量的需求来进行测试。如果测试程序在可重用和测试集优化方面没有加强，测试包将会巨大的增大，并且导致维修的灾难。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　RDBMS 基于<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">数据库</strong></u></a>（<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Oracle</strong></u></a>,&nbsp;<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">SQL</strong></u></a>数据库等）安装在普通的文件系统中。所以，测试DWH系统没有专门的测试环境，因为它能从DWH 被安装在的文件系统中来操作。当它在HDFS中达到大量数据时，测试员需要一个测试环境基于自己的HDFS。测试员需要学习如何兼容HDFS而这不用于普通的文件系统。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　验证工具</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　对于DWH&nbsp;<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">系统测试</strong></u></a>的确认工具是基于SQL（结构化查询语言）。为了比较不同的目的，这DWH 测试仪运用不是参照宏命令基准线就是基于自动化工具的成熟UI。对于大数据，并没有定义工具。目前在安装电子系统的可用工具范围从纯程序设计工具像MapReduce（提供JAVA、Pesl、<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Ruby</strong></u></a>、<a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Python</strong></u></a>等代码）到构建包装在MapReduc上像HIVE QL或PIGlatin。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　这对测试人员意味着什么呢？</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　HIVE QL和SQL并不一样，如果他在SQL 方面有基本技能，尽管它是很容易学习的。HIVE QL为了确认目的也是在孕育期和尚未形成整个结构来从分布式文件系统存取数据。HIVE QL 仅仅适合做平面数据结构而并不能处理复杂的嵌入式的数据结构。为了处理这些，测试人员能够运用PIGLatin，它是一个语句基础而并不需要复杂的编码，但是，为了编写MapReduce 程序的需要，自从HIVE 和PIGLatin 两个同时演变，使的专业综合测试并没有取消。这种形势对于测试人员是巨大的惊人的挑战。要么他们努力达到给他们的配置文件增加脚本编写的技能，要么就等待他们内部的解决方案，要么外置的供应商来供应强大的自动化工具，用外缘资源在HDFS 提供简单的接口来查询和比照数据。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　总结</strong></p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　经验至少在WDH 中，只能够缩短大数量测试人员在概念层从源系统到HDFS 理解提取、加载转换数据方面学习曲线。它也并没有提供其它别的用处。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　大数据测试人员必须从抓痕学习大数据电子系统组件。直到这时，市场演变和完全的自动化测试工具为了大数据的验证是有效的，测试人员没有任何选择而是如大数据开发人员一样，在借助大数据技术像Hadoop 获得同种技能组合。这对于测试人员来说需要一个惊人的思维转变，和在组织内自测试部件一样好。</p><p style="word-break: break-all; margin: 10px 0px; padding: 0px; line-height: 21.59375px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　为了竞争，在短期来看，这个组织应该投资于测试团队的大数据具体的培训需求，而在长期来看，应该投资于发展自动化解决方案来验证大数据。</p><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff; height: 21px; position: relative; width: 627.1875px;"></div><img src ="http://www.blogjava.net/qileilove/aggbug/399851.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-05-28 10:28 <a href="http://www.blogjava.net/qileilove/archive/2013/05/28/399851.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟屌丝大哥学习DB2---DB2 runstats、reorgchk、reorg  命令</title><link>http://www.blogjava.net/qileilove/archive/2013/01/04/393752.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 04 Jan 2013 06:46:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2013/01/04/393752.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/393752.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2013/01/04/393752.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/393752.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/393752.html</trackback:ping><description><![CDATA[<div><p>1、runstats</p> <p>runsats可以搜集表的信息，也可以搜集索引信息。作为runstats本身没有优化的功能，但是它更新了统计信息以后，可以让DB2优化器使用最新的统计信息来进行优化，这样优化的效果更好。</p> <p>&nbsp;<wbr></p> <p><span>runstats&nbsp;<wbr>&nbsp;<wbr> on&nbsp;<wbr>&nbsp;<wbr> table&nbsp;<wbr>&nbsp;<wbr> &lt;tbschema&gt;.&lt;tbname&gt;&nbsp;<wbr>&nbsp;<wbr> 收集表&nbsp;<wbr>&nbsp;<wbr> &lt;tbname&gt;&nbsp;<wbr>&nbsp;<wbr> 的统计信息。表名必须是用&nbsp;<wbr>&nbsp;<wbr> &lt;dbschema&gt;&nbsp;<wbr>&nbsp;<wbr> 全限定的。</span></p> <p>&nbsp;<wbr></p> <p>&nbsp;<wbr></p> <p><span>&nbsp;<wbr> 2、reorg</span></p> <p>&nbsp;<wbr></p> <p><span>&nbsp;<wbr>A、 reorg&nbsp;<wbr>&nbsp;<wbr> table&nbsp;<wbr>&nbsp;<wbr> &lt;tbschema&gt;.&lt;tablename&gt;&nbsp;<wbr>&nbsp;<wbr> 通过重构行来消除&#8220;碎片&#8221;数据并压缩信息，对表进行重组。表名必须是用&nbsp;<wbr>&nbsp;<wbr> &lt;dbschema&gt;&nbsp;<wbr>&nbsp;<wbr> 全限定的。</span></p> <p><span>&nbsp;<wbr> B、</span></p> <p>reorg还有一个功能就是可以将表中的数据按照某个索引关键字的顺序排列，从而可以减少某些查询I/O的数量。</p> <p>&nbsp;<wbr></p> <p>&nbsp;<wbr></p> <p><span>&nbsp;<wbr> 执行REORG可以考虑分为表上有索引和没有索引两种情况：&nbsp;<wbr></span></p> <p><span>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> a.如表名为DB2INST1.STAFF,索引名为DB2INST1.ISTAFF</span></p> <p><span>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> reorg table db2inst1.staff index db2inst1.istaff use tempspace1</span></p> <p><span>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> b.建议REORG时使用USE参数指定数据重排时使用的临时表空间，否则，REORG工作将会</span></p> <p><span>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> 在表所在表空间中原地执行.如果表上有多个索引，INDEX参数值请使用最为重要的索</span></p> <p><span>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> 引名.</span></p> <p><span>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> c.表上没有索引：</span></p> <p><span>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> reorg table db2inst1.staff use tempspace1</span></p> <p><span>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> reorg table sysibm.systables use tempspace1</span></p> <p>&nbsp;<wbr></p> <p><a href="http://weiruan85.javaeye.com/blog/317520">http://weiruan85.javaeye.com/blog/317520</a></p> <p>&nbsp;<wbr></p> <p>3、</p> <p>&nbsp;<wbr></p> <p>让db2系统定时runstats、reorg</p> <p>Q:定期runstats、reorg</p> <p><span>A:在db2 v8.2以上可以使用 CALL SYSPROC.ADMIN_CMD来实现,</span></p> <p>这里主要讲在v8.2以前的版本中利用shell或者批处理来实现同样的功能</p> <p>因为在以前的版本中存储过程中是不能使用DDL操作语句的!(这点对于oracle刚转过来的人来说很是郁闷的)</p> <p>然后可以利用db2自带的配置自动维护来做,但是java做的东西比较让人感觉头痛!尤其是速度和莫名的错误!</p> <p>本代码使用操作系统的脚本来实现这部分功能!</p> <p>1.windows下</p> <p>如下：</p> <p><u><em><strong>下一个cmd文件s.cmd</strong></em></u></p> <p><u><em><strong>内容如下：</strong></em></u></p> <p><u><em><strong>db2 connect to ccp_dm</strong></em></u></p> <p><span><u><em><strong>db2 -x "select 'runstats on table '||rtrim(tabschema)||'.'||tabname||' on all columns' from sysstat.tables where card=-1"&gt;tab.sql</strong></em></u></span></p> <p><u><em><strong>db2 -f tab.sql</strong></em></u></p> <p>--其中where后的条件可以修改</p> <p>然后就是定制任务：用windos的定制任务！每周或者每月运行，这个就不讲了哈！</p> <p>这部分经测试,通过!</p> <p>不过能,这里只提到了runstats,对于reorg同理也可以实现!</p> <p>&nbsp;<wbr></p> <p><a href="http://myfriend2010.itpub.net/post/29012/386779">http://myfriend2010.itpub.net/post/29012/386779</a></p> <p>&nbsp;<wbr></p> <p>&nbsp;<wbr></p> <p>4、reorgchk</p> <p>&nbsp;<wbr></p> <p><span>C:\Documents and Settings\Administrator&gt;db2 reorgchk update statistics on table all</span></p> <p>&nbsp;<wbr></p> <p><span>正在执行 RUNSTATS ....</span></p> <p>&nbsp;<wbr></p> <p><span>&nbsp;<wbr> reorgchk&nbsp;<wbr>&nbsp;<wbr> on&nbsp;<wbr>&nbsp;<wbr> table&nbsp;<wbr>&nbsp;<wbr> all&nbsp;<wbr>&nbsp;<wbr> 确定是否需要对表进行重组。这对于对所有表自动执行 runstats很有用。&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr></span></p> <p>&nbsp;<wbr></p> <p>&nbsp;<wbr></p> <p><span>1) 针对系统表进行REORGCHK</span></p> <p><span>db2 reorgchk update statistics on table system</span></p> <p><span>使用UPDATE STATISTICS参数指定数据库首先执行RUNSTATS命令。</span></p> <p>&nbsp;<wbr></p> <p><span>2) 针对用户表进行REORGCHK</span></p> <p><span>db2 reorgchk update statistics on table user</span></p> <p>&nbsp;<wbr></p> <p>下面是执行的部分结果</p> <p><span>db2 reorgchk update statistics on table user</span></p> <p>执行 RUNSTATS ....</p> <p>&nbsp;<wbr></p> <p>&nbsp;<wbr></p> <p><span>db2 reorgchk 命令是最重要的、也是经常被忽略的 DB2 调整命令之一。 db2 reorgchk 命令被忽略是因为它不是一个一次性调整项。由于更新是在 DB2 数据库上执行的，因此关于表的统计信息将不会是最新的。db2 reorgchk 命令更新 DB2 优化器所使用的重要统计信息。建议在大约每 10,000 次更新后重复 db2 reorgchk 命令。</span></p> <p>&nbsp;<wbr></p> <p><span>在运行 db2 reorgchk 命令之前，您应该停止 IBM Directory Server 以防止在命令执行的同时发生任何 DB2 查询或更新。虽然这是可选的，但数据库查询和更新可能会非常缓慢并有可能超时。</span></p> <p>&nbsp;<wbr></p> <p>&nbsp;<wbr></p> <p>&nbsp;<wbr></p> <p><span>请注意，运行 db2 reorgchk 命令所带来的性能益处是即时的。不必在 db2 reorgchk 命令之后重新启动 DB2。</span></p> <p>&nbsp;<wbr></p> <p><span>除了提高性能之外，db2 reorgchk 命令还报告关于数据库中所有表和索引的统计信息。db2 reorgchk 命令还报告关于 DB2 表的组织的统计信息。</span></p> <p>&nbsp;<wbr></p> <p><span><a href="http://publib.boulder.ibm.com/tividd/td/ITAME/SC32-1351-00/zh_CN/HTML/am51_perftune66.htm"> http://publib.boulder.ibm.com/tividd/td/ITAME/SC32-1351-00/zh_CN/HTML/am51_perftune66.htm</a></span></p></div><img src ="http://www.blogjava.net/qileilove/aggbug/393752.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2013-01-04 14:46 <a href="http://www.blogjava.net/qileilove/archive/2013/01/04/393752.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟屌丝一起学习 DB2 第五课 存储过程(三) 存储过程实例 </title><link>http://www.blogjava.net/qileilove/archive/2012/12/12/392867.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 12 Dec 2012 07:17:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2012/12/12/392867.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/392867.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2012/12/12/392867.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/392867.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/392867.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp; 客户在进行短信服务这个业务申请时，需要填写一些基本信息，然后根据这些信息判断这个用户是否已经存在于业务系统中。因为网上服务和业务系统两个项目物理隔离，而且网上数据库保存的客户信息不全，所以判断需要把数据交换到业务系统，在业务系统中判断。</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 解决方式是通过存储过程，以前也了解过存储过程，但没使用到项目中。不过经过一番努力最后还是完成了，期间遇到了一些困难，特写此文让对DB2存储过程还不熟悉的童鞋避免一些无谓的错误。</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;</p><div style="font-size: 12px; margin: 5px 0px; line-height: 25px;"><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5;"><a href="" title="复制代码" style="color: #1d58d1; text-decoration: initial; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; margin-left: 22px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New';"><span style="line-height: 1.5; color: #0000ff;">DROP</span> <span style="line-height: 1.5; color: #0000ff;">PROCEDURE</span> "PLName"<br />@<br /><span style="line-height: 1.5; color: #0000ff;">CREATE</span> <span style="line-height: 1.5; color: #0000ff;">PROCEDURE</span> "PLName"(<span style="line-height: 1.5; color: #008080;">--</span><span style="line-height: 1.5; color: #008080;">存储过程名字</span><span style="line-height: 1.5; color: #008080;"><br /></span><span style="line-height: 1.5; color: #808080;">IN</span> IN_ID <span style="line-height: 1.5; color: #0000ff;">BIGINT</span> ,                    <span style="line-height: 1.5; color: #008080;">--</span><span style="line-height: 1.5; color: #008080;">以下全是输入参数</span><span style="line-height: 1.5; color: #008080;"><br /></span><span style="line-height: 1.5; color: #808080;">IN</span> IN_ENTNAME <span style="line-height: 1.5; color: #0000ff;">VARCHAR</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">200</span>) ,<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_REGNO <span style="line-height: 1.5; color: #0000ff;">VARCHAR</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">50</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_PASSWORD <span style="line-height: 1.5; color: #0000ff;">VARCHAR</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">20</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_LEREP <span style="line-height: 1.5; color: #0000ff;">VARCHAR</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">300</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_CERTYPE <span style="line-height: 1.5; color: #0000ff;">CHARACTER</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">1</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_CERNO <span style="line-height: 1.5; color: #0000ff;">VARCHAR</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">50</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_LINKMAN <span style="line-height: 1.5; color: #0000ff;">VARCHAR</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">50</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_SEX <span style="line-height: 1.5; color: #0000ff;">CHARACTER</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">1</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_MOBTEL <span style="line-height: 1.5; color: #0000ff;">VARCHAR</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">30</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_REQDATE <span style="line-height: 1.5; color: #0000ff;">TIMESTAMP</span>,<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_REMITEM <span style="line-height: 1.5; color: #0000ff;">VARCHAR</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">300</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_STATE <span style="line-height: 1.5; color: #0000ff;">CHARACTER</span>(<span style="line-height: 1.5; color: #800000; font-weight: bold;">1</span>),<br /><span style="line-height: 1.5; color: #808080;">IN</span> IN_TIMESTAMP <span style="line-height: 1.5; color: #0000ff;">TIMESTAMP</span><br />)<br /><span style="line-height: 1.5; color: #0000ff;">BEGIN</span><br />    <br />   <span style="line-height: 1.5; color: #0000ff;">declare</span> V_RESULT  <span style="line-height: 1.5; color: #0000ff;">BIGINT</span>;     <span style="line-height: 1.5; color: #008080;">--</span><span style="line-height: 1.5; color: #008080;">声明变量</span><span style="line-height: 1.5; color: #008080;"><br /></span>   <span style="line-height: 1.5; color: #0000ff;">DELETE</span> <span style="line-height: 1.5; color: #0000ff;">FROM</span>  TableNameA <span style="line-height: 1.5; color: #0000ff;">WHERE</span> ID <span style="line-height: 1.5; color: #808080;">=</span> IN_ID;<br /><br />   <span style="line-height: 1.5; color: #0000ff;">SET</span> V_RESULT <span style="line-height: 1.5; color: #808080;">=</span> <span style="line-height: 1.5; color: #0000ff;">NULL</span>;          --为变量赋值</pre><pre style="margin-top: 0px; margin-bottom: 0px; margin-left: 22px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New';">&nbsp; <span style="line-height: 1.5; color: #008080;">--</span><span style="line-height: 1.5; color: #008080;">检查用户输入的信息是否合法</span><span style="line-height: 1.5; color: #008080;"><br /></span><br />  <span style="line-height: 1.5; color: #0000ff;">select</span> b.id <span style="line-height: 1.5; color: #0000ff;">INTO</span> V_RESULT  <span style="line-height: 1.5; color: #0000ff;">from</span> TableNameB b,TableNameC c <span style="line-height: 1.5; color: #0000ff;">where<span style="line-height: 1.5; color: #000000;"> 正常的判断条件</span></span>  <br />  <span style="line-height: 1.5; color: #0000ff;">if</span>(V_RESULT <span style="line-height: 1.5; color: #0000ff;">IS</span> <span style="line-height: 1.5; color: #808080;">NOT</span> <span style="line-height: 1.5; color: #0000ff;">NULL</span>)  <span style="line-height: 1.5; color: #0000ff;">then</span> <span style="line-height: 1.5; color: #008080;">--</span><span style="line-height: 1.5; color: #008080;">-如果合法，执行下面的insert语句</span><span style="line-height: 1.5; color: #008080;"><br /></span>   <span style="line-height: 1.5; color: #0000ff;">INSERT</span> <span style="line-height: 1.5; color: #0000ff;">INTO</span> TableNameA(ID,ENTNAME,REGNO,PASSWORD,LEREP,CERTYPE,CERNO,LINKMAN,SEX,MOBTEL,REQDATE,REMITEM,STATE,<span style="line-height: 1.5; color: #0000ff;">TIMESTAMP</span>)<br />   <span style="line-height: 1.5; color: #0000ff;">VALUES</span>(IN_ID,IN_ENTNAME,IN_REGNO,IN_PASSWORD,IN_LEREP,IN_CERTYPE,IN_CERNO,IN_LINKMAN,IN_SEX,IN_MOBTEL,IN_REQDATE,IN_REMITEM,IN_STATE,IN_TIMESTAMP);<br />  <span style="line-height: 1.5; color: #0000ff;">end</span> <span style="line-height: 1.5; color: #0000ff;">if</span>;<br />    <span style="line-height: 1.5; color: #0000ff;">commit</span>;<br /><span style="line-height: 1.5; color: #0000ff;">END</span><br />@</pre><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5;"><a href="" title="复制代码" style="color: #1d58d1; text-decoration: initial; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div></div><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;"><strong>功能说明：</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;"><strong>调用存储过程时会传入一些值（IN输入参数），然后根据传入的值查询数据库（select语句），根据查询结果执行操作（添加、删除、更新）</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">有两种方式执行写好的存储过程：</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 1.拷贝到DB2客户端工具中直接执行</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">　　<strong>特别注意</strong>：执行时将</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;"><img src="http://pic002.cnblogs.com/images/2011/324103/2011120117531924.jpg" alt="" style="border: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">改成@，之前很多错误都和它有关，比如：&#8220;<span style="line-height: 23px; font-family: simsun; -webkit-text-decorations-in-effect: initial;">该命令被当作 SQL<br />语句来处理，因为它不是有效的命令行处理器命令&#8221;正</span>是这个问题花费了很长时间，严重影响心情</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 2.将上面的语句保存为test.db2文件放到任意目录下（比如D盘根目录），然后在cmd输入db2cmd 然后输入db2 -td@ -vf&nbsp; D：\test.db2即可</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp;执行后就可以测试存储过程写的是否正确</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp;直接写sql：</p><div style="font-size: 12px; margin: 5px 0px; line-height: 25px;"><pre style="margin-top: 0px; margin-bottom: 0px; margin-left: 22px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New';">call PLName(存储过程名字) （IN_ID,IN_ENTNAME,IN_REGNO,IN_PASSWORD,IN_LEREP,IN_CERTYPE,IN_CERNO,IN_LINKMAN,IN_SEX,IN_MOBTEL,IN_REQDATE,IN_REMITEM,IN_STATE,IN_TIMESTAMP对应的值）</pre></div><p style="margin-top: 10px; margin-bottom: 10px; background-color: #ffffff;"><font face="Verdana, Arial, Helvetica, sans-serif"><span style="line-height: 25px;">以上就是我今天所用到的存储过程，功能非常简单，比较复杂的操作也在摸索阶段，有什么疑问大家可以随时交流。</span></font><br /><br /></p><div style="font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px;"><div>CREATE PROCEDURE &nbsp;KJZB.ZQINVEST_JT(out returnCode Integer,out&nbsp;</div><div>errorMsg varchar(255))&nbsp;</div><div>LANGUAGE SQL&nbsp;</div><div>BEGIN&nbsp;</div></div><div><span style="line-height: 25px;">declare sql_code integer default 0;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare SQLSTATE char(5) default '00000';&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare SQLCODE integer default 0;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare sqlMsg varchar(200) default '';&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare stmt varchar(1024);&nbsp;</span></div><div><span style="line-height: 25px;"><br /></span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare vCurdate &nbsp; &nbsp;varchar(20); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 当天日期&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare vCurYMd &nbsp; &nbsp; varchar(6); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 当天所在的年月&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare vCurDay &nbsp;varchar(2) ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --所在天&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare maxday &nbsp; &nbsp; &nbsp;integer default 30; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 每个月按30天算&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare fday &nbsp; &nbsp; &nbsp; &nbsp; integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 实际天数&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare lastday &nbsp; &nbsp; &nbsp;integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 到期日的天数&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare firstday &nbsp; &nbsp; integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 购买月的天数&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare firstmonth &nbsp; integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 购买的月份&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare lastmonth &nbsp; &nbsp;integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 到期日的月份&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare firstyear &nbsp; &nbsp;integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 购买日的年份&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare lastyear &nbsp; &nbsp; integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 到期年份&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare disday &nbsp; &nbsp; &nbsp; integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 间隔天数&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare dismonth &nbsp; &nbsp; integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 间隔月份&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare disyear &nbsp; &nbsp; &nbsp;integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 间隔年份&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare vLsh &nbsp; &nbsp; &nbsp; &nbsp; varchar(32); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 流水号&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare vjgh &nbsp; &nbsp; &nbsp; &nbsp; varchar(8); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 机构码&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare ywzh &nbsp; &nbsp; &nbsp; varchar(32); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 业务帐号&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare vzh &nbsp; &nbsp; &nbsp; &nbsp; varchar(32); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 投资账号&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare vJgbm &nbsp; &nbsp; &nbsp; varchar(8) default '32022300'; &nbsp; -- 投资帐号对应的机构(默认为清算中心)<br /><br /></span><div>&nbsp; &nbsp;declare vDfJgbm &nbsp; &nbsp; varchar(8); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 对方机构号&nbsp;</div><div>&nbsp; &nbsp; declare gmrq &nbsp; &nbsp; &nbsp; &nbsp;varchar(8); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 购买日期&nbsp;</div><div>&nbsp; &nbsp; declare dqrq &nbsp; &nbsp; &nbsp; &nbsp;varchar(8); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 到期日期&nbsp;</div><div>&nbsp; &nbsp; declare zqpz &nbsp; &nbsp; &nbsp; &nbsp;varchar(1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 债券品种&nbsp;</div><div>&nbsp; &nbsp; declare hth &nbsp; &nbsp; &nbsp; &nbsp; varchar(16); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 合同号&nbsp;</div><div>&nbsp; &nbsp; declare fxfs &nbsp; &nbsp; &nbsp; &nbsp;varchar(1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 付息方式&nbsp;</div><div>&nbsp; &nbsp; declare ywlx &nbsp; &nbsp; &nbsp; &nbsp;varchar(3) default '888'; &nbsp; &nbsp; &nbsp; &nbsp;-- 业务类型(默认业务类型 888)&nbsp;</div><div>&nbsp; &nbsp; declare tzqx &nbsp; &nbsp; &nbsp; &nbsp;varchar(1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 投资期限&nbsp;</div><div>&nbsp; &nbsp; declare ysjlxkmkzz &nbsp;varchar(7); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 应收(计)利息科目控制字&nbsp;</div><div>&nbsp; &nbsp; declare tzsykmmkzz &nbsp;varchar(7); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 投资收益科目控制字&nbsp;</div><div>&nbsp; &nbsp; declare yjkmkzz &nbsp; &nbsp; varchar(7) default '142112'; &nbsp; &nbsp; -- 溢价科目控制字 长期投资(溢价142112)&nbsp;</div><div>&nbsp; &nbsp; declare zjkmkzz &nbsp; &nbsp; varchar(7) default '142113'; &nbsp; &nbsp; -- 折价科目控制字 长期投资(折价142113)&nbsp;</div><div>&nbsp; &nbsp; declare fykmkzz &nbsp; &nbsp; varchar(7) default '142111'; &nbsp; &nbsp; -- 相关费用科目控制字 长期投资(相关费用 142111)&nbsp;</div><div>&nbsp; &nbsp; declare zid &nbsp; &nbsp; &nbsp; &nbsp; varchar(32) default '0'; &nbsp; &nbsp; &nbsp; &nbsp; -- id 债券投资ID&nbsp;</div><div>&nbsp; &nbsp; declare vId &nbsp; &nbsp; &nbsp; &nbsp; varchar(32); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- id 债券流水ID&nbsp;</div><div>&nbsp; &nbsp; declare yslx &nbsp; &nbsp; &nbsp; &nbsp;double; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 应收利息 (面值 * 票面利率 (年) /360 * 当月实际天数)&nbsp;</div><div>&nbsp; &nbsp; declare yjlx &nbsp; &nbsp; &nbsp; &nbsp;double; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 应计利息 (面值 * 票面利率 (年) /360 * 当月实际天数)&nbsp;</div><div>&nbsp; &nbsp; declare ysjlx &nbsp; &nbsp; &nbsp; double; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 应收计利息&nbsp;</div><div>&nbsp; &nbsp; declare pmje &nbsp; &nbsp; &nbsp; &nbsp;double; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 票面金额&nbsp;</div><div>&nbsp; &nbsp; declare pmll &nbsp; &nbsp; &nbsp; &nbsp;double; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 票面利率&nbsp;</div><div>&nbsp; &nbsp; declare tzsy &nbsp; &nbsp; &nbsp; &nbsp;DECIMAL(12, 2); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 投资收益 &nbsp; &nbsp; &nbsp; ( 应收(计)利息 - 每月摊销的溢价 - 每月摊销相关费用 )&nbsp;</div><div>&nbsp; &nbsp; declare txyj &nbsp; &nbsp; &nbsp; &nbsp;double; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 月摊销溢价 &nbsp; &nbsp; ( 溢价/(到期日 - 购买日 + 1) * 当月实际天数 )&nbsp;</div><div>&nbsp; &nbsp; declare txzj &nbsp; &nbsp; &nbsp; &nbsp;double; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 月摊销折价 &nbsp; &nbsp; ( 折价/(到期日 - 购买日 + 1) * 当月实际天数 )&nbsp;</div><div>&nbsp; &nbsp; declare txfy &nbsp; &nbsp; &nbsp; &nbsp;double; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 月摊销费用 &nbsp; &nbsp; (相关费用)/(到期日 - 购买日 + 1) * 当月实际天数&nbsp;</div><div>&nbsp; &nbsp; declare yj &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double default 0.0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 溢价&nbsp;</div><div>&nbsp; &nbsp; declare zj &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double default 0.0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 折价&nbsp;</div><div>&nbsp; &nbsp; declare fy &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double default 0.0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 相关费用&nbsp;</div><br /><span style="line-height: 25px;">&nbsp;</span></div><div><span style="line-height: 25px;"><br /></span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; declare zqtz cursor for s1; &nbsp; 建立游标</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; -- 声明异常&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; DECLARE CONTINUE HANDLER FOR NOT FOUND,SQLEXCEPTION,SQLWARNING&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; begin&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp;set sql_code &nbsp; = SQLCODE;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp;set returnCode = sql_code;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; end;&nbsp;</span></div><div><span style="line-height: 25px;"><br /></span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; set vCurdate = (select char(current_date) from sysibm.sysdummy1);&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; set vCurdate = replace(vCurdate,'-','');&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; set vCurYMd &nbsp;= substr(vCurdate,1,6);&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; set vCurDay &nbsp;= substr(vCurdate,7,2);&nbsp;</span></div><div><span style="line-height: 25px;"><br /></span></div><div><span style="line-height: 25px;">&nbsp; &nbsp;-- 读取还没到期的长期债券投资信息&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp;set &nbsp;stmt = ' select JGBM,ZH,HTH,ZQPZ,PMJE,LL,GMRQ,DQR,YSLX,YJLX,YJ,ZJ,FY,FXFS,id,cast(substr(GMRQ,7,2) as integer),cast(substr(DQR,7,2) as integer),cast(substr(GMRQ,5,2) as integer),cast(substr(DQR,5,2) as integer),cast(substr(GMRQ,1,4) as integer),cast(substr(DQR,1,4) as integer) &nbsp;from kjzb.zqinvest where substr(dqr,1,6) &gt;=''' || &nbsp;vCurYMd &nbsp;|| ''' and tzqx = ''2'' and tzzt &lt;&gt; ''2''';&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp;prepare s1 from stmt;&nbsp;</span><br /><div><span style="line-height: 25px;"><br /></span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; open zqtz;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; fetch zqtz into vDfJgbm,vzh,hth,zqpz,pmje,pmll,gmrq,dqrq,yslx,yjlx,yj,zj,fy,fxfs,zid,firstday,lastday,firstmonth,lastmonth,firstyear,lastyear;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; while sql_code &lt;&gt; 100 do&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; -- 如果是31日购买的，第一个月不计提&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; if ( firstday = 31 and substr(gmrq,1,6) = vCurYMd ) then&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; goto EXIT;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</span></div><div><span style="line-height: 25px;"><br /></span></div><div><span style="line-height: 25px;">-- 如果是01日到期的，最后一个月不计提&nbsp;</span></div><div><span style="line-height: 25px;">if ( lastday = 1 and substr(dqrq,1,6) = vCurYMd ) then&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; goto EXIT;&nbsp;</span></div><div><span style="line-height: 25px;">end if;&nbsp;</span></div><div><span style="line-height: 25px;"><br /></span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; -- 间隔年份&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; if ( firstyear = lastyear ) then&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set disyear = 0;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set disyear = lastyear - firstyear - 1;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</span></div><div><span style="line-height: 25px;"><br /></span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; -- 同年&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; if ( disyear = 0 ) then&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 下个月或同月(业务逻辑上不会发生，但程序上要判断防止业务人员误操作)&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( lastmonth - firstmonth &lt;= 1 ) then&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set dismonth = 0;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set dismonth = lastmonth - firstmonth - 1;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 不在同一年，间隔月份 = 第一年的月份 + 中间年的月份 + 最后一年的月份&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set dismonth = ( 12 - firstmonth ) + ( disyear * 12 ) + ( lastmonth - 1 ) ;&nbsp;</span></div><div><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</span></div><div>&nbsp; &nbsp;-- 初始化摊销溢价、摊销折价、摊销费用&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set txyj = 0.0;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set txzj = 0.0;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set txfy = 0.0;&nbsp;</div><div>&nbsp; &nbsp; &nbsp;if &nbsp;fxfs &nbsp;= '5' &nbsp;then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 根据付息方式来计应计利息还是应收利息科目控制字&nbsp;</div><div>&nbsp; &nbsp; &nbsp; if zqpz = '1' then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set ysjlxkmkzz = '142107'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 应计利息 国债 &nbsp; &nbsp; 142107&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set tzsykmmkzz = '514111'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 投资收益（债券利息收入-国债利息收入） &nbsp; 514111&nbsp;</div><div>&nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; if zqpz = '2' then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set ysjlxkmkzz = '142108'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 应计利息 金融债 &nbsp; 142108&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set tzsykmmkzz = '514112'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 投资收益(债券利息收入-金融债券利息收入) 514112&nbsp;</div><div>&nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; if zqpz = '3' then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set ysjlxkmkzz = '142109'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 应计利息 公司债 &nbsp; 142109&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set tzsykmmkzz = '514113'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 债券利息收入-企业债券利息收入 514113&nbsp;</div><div>&nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; if zqpz = '4' then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set ysjlxkmkzz = '142110'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 应计利息 其他债券 142110&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set tzsykmmkzz = '514114'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 债券利息收入-其他债券利息收入 &nbsp; 514114&nbsp;</div><div>&nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp;else&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;if zqpz = '1' then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set ysjlxkmkzz = '132102'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 应收利息 国债 &nbsp; &nbsp; 132102&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set tzsykmmkzz = '514111'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 投资收益（债券利息收入-国债利息收入） &nbsp; 514111&nbsp;</div><div>&nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; if zqpz = '2' then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set ysjlxkmkzz = '132103'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 应收利息 金融债 &nbsp; 132103&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set tzsykmmkzz = '514112'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 投资收益(债券利息收入-金融债券利息收入) 514112 &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; if zqpz = '3' then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set ysjlxkmkzz = '132104'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 应收利息 公司债 &nbsp; 132104&nbsp;</div><div>&nbsp; &nbsp;set tzsykmmkzz = '514113'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 债券利息收入-企业债券利息收入 514113 &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; if zqpz = '4' then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set ysjlxkmkzz = '132105'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 应收利息 其他债券 132105&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set tzsykmmkzz = '514114'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 债券利息收入-其他债券利息收入 &nbsp; 514114&nbsp;</div><div>&nbsp; &nbsp; &nbsp; end if; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp;end if;&nbsp;</div><div>&nbsp;&nbsp;</div><div>&nbsp; &nbsp;if ( substr(dqrq,1,6) = vCurYMd ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 最后一个月计提&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;set fday = lastday - 1;&nbsp;</div><div>&nbsp; &nbsp;else&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;if ( substr(gmrq,1,6) = vCurYMd ) then &nbsp; &nbsp; &nbsp; -- 第一个月计提&nbsp;</div><div>&nbsp; &nbsp;set fday = 30 - firstday + 1;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;else&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;set fday = maxday; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 平常按30天算&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;end if;&nbsp;</div><div>&nbsp; &nbsp;end if;&nbsp;</div><div></div><div>-- 实际天数 = 第一个月的天数 + 间隔月份 * 30 + 最后一个月的天数(到期日不算)&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set disday = &nbsp;( 30 - firstday + 1) + ( dismonth * 30 ) + ( lastday - 1 ); &nbsp;</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- &nbsp;记提公式:面值*票面利率(年)/ 360*当月实际天数&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set ysjlx = pmje * (pmll / 100) /360 * fday;&nbsp;</div><div></div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- 投资收益公式 : 应收（计）利息 ( + 月摊销折价）&#8212; 月摊销溢价 - 月摊销费用&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set tzsy = ysjlx;&nbsp;</div><div></div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- 设计思想为如果有溢价，则应该没有折价&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;if yj &lt;&gt; 0.0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set txyj = yj /disday * fday;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set tzsy = tzsy - txyj;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;else&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if zj &lt;&gt; 0.0 then&nbsp;</div><div>set txzj = zj/disday* fday;&nbsp;</div><div>set tzsy = tzsy + txzj; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end if;&nbsp;<br /><div>&nbsp;if fy &lt;&gt; 0.0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set txfy = fy /disday * fday;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set tzsy = tzsy - txfy;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;end if;&nbsp;</div><div></div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; --借: 1321 应收利息[按月计提金额]&nbsp;</div><div>&nbsp; &nbsp;set vId = &nbsp;kjzb.getvId();&nbsp;</div><div>&nbsp; &nbsp;set vLsh = kjzb.getLsh(32); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 获取流水号&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set vjgh = kjzb.getJgh(vzh); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 获取机构号&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set ywzh = kjzb.getZh(vjgh,ysjlxkmkzz); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 应收(计)利息账号&nbsp;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; if ywzh is null then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set sqlMsg = '债券记提走帐时找不到指定机构['||vjgh||']和科目控制字为['|| ysjlxkmkzz ||']的帐号';&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto ERROR_RETURN;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; insert into kjzb.FLLSB values(vId,vJgbm,ysjlxkmkzz,vLsh,hth,ywzh,'借',ysjlx,'','0000',vCurdate,ywlx);&nbsp;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; if sql_code &lt;&gt; 0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set sqlMsg = '债券走帐插入会计分录出错';&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto ERROR_RETURN;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp;-- 借: 1421 长期投资(折价)[按月计提金额]&nbsp;</div><div>&nbsp; &nbsp;if zj &lt;&gt; 0.0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set vId = &nbsp;kjzb.getvId();&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set ywzh = kjzb.getZh(vjgh,zjkmkzz); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 长期投资(折价)账号&nbsp;</div><div></div><div>&nbsp; &nbsp;if ywzh is null then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;set sqlMsg = '债券记提走帐时找不到指定机构['||vjgh||']和科目控制字为['|| zjkmkzz ||']的帐号';&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;set errorMsg = &nbsp;sqlMsg;&nbsp;<br /><div>&nbsp; &nbsp; goto ERROR_RETURN;&nbsp;</div><div>&nbsp; &nbsp;end if;&nbsp;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;insert into kjzb.FLLSB values(vId,vJgbm,zjkmkzz,vLsh,hth,ywzh,'借',txzj,'','0000',vCurdate,ywlx);&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if sql_code &lt;&gt; 0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set sqlMsg = '债券走帐插入会计分录出错';&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto ERROR_RETURN;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end if;&nbsp;</div><div>&nbsp; &nbsp;end if;&nbsp;</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- 贷: 5141 投资收益 &nbsp;应收（计）利息-每月摊消的溢价-每月摊消相关费用&nbsp;</div><div>&nbsp; &nbsp;set vId = &nbsp;kjzb.getvId();&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set ywzh = kjzb.getZh(vjgh,tzsykmmkzz); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 投资收益账号&nbsp;</div><div></div><div>if ywzh is null then&nbsp;</div><div>&nbsp;&nbsp;&nbsp; &nbsp;set sqlMsg = '债券记提走帐时找不到指定机构['||vjgh||']和科目控制字为['|| tzsykmmkzz ||']的帐号';&nbsp;<div>&nbsp; &nbsp; set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; goto ERROR_RETURN;&nbsp;</div><div>end if;&nbsp;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; insert into kjzb.FLLSB values(vId,vJgbm,tzsykmmkzz,vLsh,hth,ywzh,'贷',tzsy,'','0000',vCurdate,ywlx);&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if sql_code &lt;&gt; 0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set sqlMsg = '债券走帐插入会计分录出错';&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto ERROR_RETURN;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- 贷: 1421 长期投资(溢价)[按月摊消]每月摊消的溢价(溢价/(到期日-购买日+1) *当月实际天数)&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if yj &lt;&gt; 0.0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; set vId = &nbsp;kjzb.getvId();&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set ywzh = kjzb.getZh(vjgh,yjkmkzz); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 长期投资(溢价)账号&nbsp;</div><div></div><div>if ywzh is null then&nbsp;</div><div>&nbsp; &nbsp; set sqlMsg = '债券记提走帐时找不到指定机构['||vjgh||']和科目控制字为['|| yjkmkzz ||']的帐号';&nbsp;</div><div>&nbsp; &nbsp; set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; goto ERROR_RETURN;&nbsp;</div><div>end if;&nbsp;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; insert into kjzb.FLLSB values(vId,vJgbm,yjkmkzz,vLsh,hth,ywzh,'贷',txyj,'','0000',vCurdate,ywlx);&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if sql_code &lt;&gt; 0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set sqlMsg = '债券走帐插入会计分录出错';&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto ERROR_RETURN;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- 贷: 1421 长期投资(相关费用)[按月摊消金额] 每月摊消相关费用(相关费用/(到期日-购买日+1) *当月实际天数)&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if (fy &lt;&gt; 0.0) &nbsp; then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set vId = &nbsp;kjzb.getvId();&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set ywzh = kjzb.getZh(vjgh,fykmkzz); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 长期投资(相关费用)账号&nbsp;</div><div></div><div>if ywzh is null then&nbsp;</div><div>&nbsp; &nbsp; set sqlMsg = '债券记提走帐时找不到指定机构['||vjgh||']和科目控制字为['|| fykmkzz ||']的帐号';&nbsp;</div><div>&nbsp; &nbsp; set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; goto ERROR_RETURN;&nbsp;</div><div>end if;&nbsp;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; insert into kjzb.FLLSB values(vId,vJgbm,yjkmkzz,vLsh,hth,ywzh,'贷',txfy,'','0000',vCurdate,ywlx);&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if sql_code &lt;&gt; 0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set sqlMsg = '债券走帐插入会计分录出错';&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto ERROR_RETURN;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; end if;&nbsp;</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp;-- 对 kjzb.zqinvest 表的以下字段进行更新&nbsp;</div><div>&nbsp; &nbsp;-- yjtyjlx 【已计提应计利息】&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- yjtyslx 【已计提应收利息】&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- ytxyj &nbsp; 【已摊销溢价】&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- ytxzj &nbsp; 【已摊销折价】&nbsp;</div></div><div>&nbsp; if fxfs = '5' then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update kjzb.zqinvest set yjtyjlx = yjtyjlx + ysjlx,ytxyj = ytxyj + txyj,ytxzj = ytxzj + txzj,ytxfy = ytxfy + txfy where id = zid;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if sql_code &lt;&gt; 0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set sqlMsg = '债券走帐时更新表出错';&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; goto ERROR_RETURN;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update kjzb.zqinvest set yjtyslx = yjtyslx + ysjlx,ytxyj = ytxyj + txyj,ytxzj = ytxzj + txzj,ytxfy = ytxfy + txfy where id = zid;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if sql_code &lt;&gt; 0 then&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set sqlMsg = '债券走帐时更新表出错';&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; goto ERROR_RETURN;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end if;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;end if;&nbsp;</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; EXIT:&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fetch zqtz into vDfJgbm,vzh,hth,zqpz,pmje,pmll,gmrq,dqrq,yslx,yjlx,yj,zj,fy,fxfs,zid,firstday,lastday,firstmonth,lastmonth,firstyear,lastyear;&nbsp;</div><div></div><div>&nbsp; &nbsp; end while;&nbsp;</div><div></div><div>&nbsp; &nbsp; close zqtz; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- 关闭游标&nbsp;</div><div></div><div>&nbsp; &nbsp; COMMIT;&nbsp;</div><div>&nbsp; &nbsp; set sqlMsg &nbsp; = '债券投资自动计提成功!';&nbsp;</div><div>&nbsp; &nbsp; set errorMsg = &nbsp;sqlMsg;&nbsp;</div><div>&nbsp; &nbsp; set sql_code = 0;&nbsp;</div><div>&nbsp; &nbsp; set returnCode = sql_code;&nbsp;</div><div>&nbsp; &nbsp; return 1;&nbsp;</div><div></div><div>&nbsp; &nbsp; ERROR_RETURN:&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ROLLBACK;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return -1;&nbsp;</div></div></div></div><p>&nbsp;</p><img src ="http://www.blogjava.net/qileilove/aggbug/392867.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2012-12-12 15:17 <a href="http://www.blogjava.net/qileilove/archive/2012/12/12/392867.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟屌丝一起学习 DB2 第五课 存储过程(二)</title><link>http://www.blogjava.net/qileilove/archive/2012/12/11/392819.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 11 Dec 2012 08:34:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2012/12/11/392819.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/392819.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2012/12/11/392819.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/392819.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/392819.html</trackback:ping><description><![CDATA[<div>REPEAT语句<br /><div>ftch_loop2:</div><div>REPEAT</div><div>&nbsp; &nbsp; FETCH &nbsp;c1 &nbsp;INTO &nbsp;v_firstname, &nbsp;v_midinit, &nbsp;v_lastname;</div><div>UNTIL &nbsp;SQLCODE &nbsp;&lt;&gt; &nbsp;0 &nbsp;AND &nbsp;REPEAT &nbsp;ftch_loop2;</div><div></div><div>WHILE语句</div><div>WHILE &nbsp;at_end &nbsp;= &nbsp;0 &nbsp;DO</div><div>&nbsp; &nbsp; FETCH &nbsp;c1 &nbsp;INTO &nbsp;v_firstname, &nbsp;v_midinit, &nbsp;v_lastname;</div><div>&nbsp; &nbsp; IF &nbsp;SQLCODE &nbsp;= &nbsp;100 &nbsp;THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; SET &nbsp;at_end &nbsp;= &nbsp;1;</div><div>&nbsp; &nbsp; END &nbsp;IF;</div><div>END &nbsp;WHILE;</div><div>LEAVE和ITERATE语句<br /><div>LEAVE和ITERATE语句来控制循环</div><div>LEAVE语句用来跳出循环</div><div>ITERATE语句用来回到for或者while循环的开始重新执行</div><div>示例</div><div>FETCH_LOOP1: &nbsp;LOOP</div><div>&nbsp; &nbsp; FETCH &nbsp;c1 &nbsp;INTO &nbsp;v_dept, &nbsp;v_deptname, &nbsp;v_admdept;</div><div>&nbsp; &nbsp; IF &nbsp;at_end &nbsp;= &nbsp;1 &nbsp;THEN &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; LEAVE FETCH_LOOP1;</div><div>&nbsp; &nbsp; ELSEIF &nbsp;v_dept &nbsp;= &nbsp;&#8216;D01&#8217; &nbsp;THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ITERATE FETCH_LOOP1;</div><div>&nbsp; &nbsp; END &nbsp;IF;</div><div>&nbsp; &nbsp; INSERT &nbsp;INTO &nbsp;department(deptno, deptname, admdept)</div><div>&nbsp; &nbsp;VALUES(&#8216;NEW&#8217;, v_deptname, v_admdept);</div><div>END &nbsp;LOOP FETCH_LOOP1;</div><div>GOTO语句<br /><div>GOTO语句用于直接跳转到指定标签处。例如：</div><div>IF &nbsp;v_DEPT &nbsp;= &nbsp;&#8216;D11&#8217;</div><div>&nbsp; &nbsp; GOTO &nbsp;bye;</div><div>&#8230;&#8230;</div><div>bye:</div><div>RETURN语句<br /><div>RETURN语句用于向调用返回。</div><div>IF &nbsp;v_DEPT &nbsp;= &nbsp;&#8216;D11&#8217;<br /></div><div>&nbsp; &nbsp; RETURN &nbsp;1;</div><strong><span style="font-size: 18pt;">八&nbsp;</span><span style="font-size: 18pt;">游标和结果集<br /><br /></span></strong><div>游标的声明</div></div><div><div>下面是游标声明的几个例子：</div><div>DECLARE &nbsp;c1 &nbsp;CURSOR &nbsp;FOR select * from staff;</div><div>（DECLARE关键字，cl游标名称， CURSOR是必须有的，；指通过c1的游标来操作staff里所有的数据）最常用的最普通的。</div><div>2.DECLARE &nbsp;c1 &nbsp;CURSOR &nbsp;WITH &nbsp;HOLD FOR &nbsp;select &nbsp;* &nbsp; form &nbsp;staff;</div><div>3.DECLARE &nbsp;c1 &nbsp;CURSOR WITH &nbsp;RETURN &nbsp;TO &nbsp;CALLER &nbsp;FOR &nbsp;select &nbsp;* &nbsp; form &nbsp;staff;</div><div>4.DECLARE &nbsp;c1 &nbsp;CURSOR WITH &nbsp;RETURN &nbsp;TO &nbsp;CLIENT &nbsp;FOR &nbsp;select &nbsp;* &nbsp; form &nbsp;staff;<br /><br /><div>游标的相关操作</div></div><div><div>打开游标</div><div>OPEN &nbsp;&lt;游标名&gt;</div><div>提取游标</div><div>FETCH &nbsp;&lt;游标名&gt; &nbsp;INTO &nbsp;&lt;变量列表&gt;</div><div>关闭游标</div><div>CLOSE &nbsp;&lt;游标名&gt;</div><div>游标的遍历<br /><br /><div>DECLARE &nbsp;at_end &nbsp;INT &nbsp;DEFAULT &nbsp;0; （声明了at_end的变量，默认值是0）</div><div>DECLARE &nbsp;PIID &nbsp;INTEGER &nbsp;DEFAULT &nbsp;0;</div><div>DECLARE &nbsp;PINT &nbsp;INTEGER &nbsp;DEFAULT &nbsp;0;</div><div>DECLARE &nbsp;not_found &nbsp;CONDITION　FOR　SQLSTATE　'02000'; &nbsp;&nbsp;</div><div>DECLARE &nbsp;c1 &nbsp;CURSOR &nbsp;FOR &nbsp;SELECT &nbsp;IID &nbsp;FROM &nbsp;YH; （声明了一个游标，把IID的指标拿出来）</div><div>DECLARE &nbsp;CONTINUE &nbsp;HANDLER &nbsp;FOR &nbsp;not_found &nbsp;SET &nbsp;at_end &nbsp;= &nbsp;1; &nbsp;&nbsp;</div><div>OPEN　c1; （进行循环）</div><div>SET &nbsp;PCOUNT &nbsp;= &nbsp;0; &nbsp;&nbsp;</div><div>ins_loop: &nbsp; LOOP</div><div>&nbsp; &nbsp; FETCH &nbsp;c1 &nbsp;INTO &nbsp;PIID; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; IF &nbsp;at_end &nbsp;&lt;&gt; &nbsp;0 &nbsp;THEN &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; LEAVE &nbsp;ins_loop; &nbsp; &nbsp;（ LEAVE跳出循环）</div><div>&nbsp; &nbsp; END &nbsp;IF;</div><div>&nbsp; &nbsp; SET &nbsp;PCOUNT &nbsp;= &nbsp;PCOUNT &nbsp;+ &nbsp;1; （表示提取了多少条记录）</div><div>END LOOP;</div><div>删除游标对应的数据行<br /><div>DECLARE &nbsp;cursor1 &nbsp;CURSOR &nbsp;FOR &nbsp;<span style="white-space:pre">	</span>SELECT &nbsp;DEPTNO, &nbsp;DEPTNAME, &nbsp;LOCATION</div><div><span style="white-space:pre">					</span> FROM &nbsp;DB2ADMIN.ORG &nbsp;FOR &nbsp;UPDATE;（声明一个cursor1的游标，从一个表时提出部门名称，...，位置）</div><div></div><div>OPEN &nbsp;cursor1;（打开游标）</div><div></div><div>FETCH &nbsp;FROM &nbsp;cursor1 &nbsp;INTO &nbsp;v_DEPTNO, &nbsp;V_DEPTNAME, &nbsp;v_LOCATION;</div><div></div><div>DELETE &nbsp;FROM &nbsp;DB2ADMIN.ORG &nbsp;WHERE CURRENT &nbsp;OF &nbsp;cursor1;（删除DB2ADMIN.ORG的记录； CURRENT &nbsp;OF &nbsp;cursor1这是的游标是指向某一个位置；删除游标指向的当前行。）</div><div></div><div>CLOSE &nbsp;cursor1;（关闭游标，也可做一个循环，删除所有的内容）</div><div>更新游标对应的数据行<br /><div>DECLARE &nbsp;cursor1 &nbsp;CURSOR &nbsp;FOR &nbsp;<span style="white-space:pre">	</span>SELECT &nbsp;DEPTNO, &nbsp;DEPTNAME, &nbsp;LOCATION</div><div><span style="white-space:pre">					</span> FROM &nbsp;DB2ADMIN.ORG <span style="white-space:pre">	</span>FOR &nbsp;UPDATE;</div><div></div><div>OPEN &nbsp;cursor1;</div><div></div><div>FETCH &nbsp;FROM &nbsp;cursor1 &nbsp;INTO &nbsp;v_DEPTNO, &nbsp;v_DEPTNAME, &nbsp;v_LOCATION;</div><div></div><div>UPDATE &nbsp;DB2ADMIN.ORG &nbsp;SET &nbsp; DEPTNAME &nbsp;= &nbsp;&#8216;NEW NAME&#8217;WHERE CURRENT &nbsp;OF &nbsp;cursor1;</div><div></div><div>CLOSE &nbsp;cursor1;</div><div><div>使用游标返回多个结果集<br /></div></div><img src="http://www.blogjava.net/images/blogjava_net/qileilove/游标1.png" width="796" height="468" alt="" /><br /><br /><br /><strong><span style="font-size: 18pt;">九&nbsp;</span><span style="font-size: 18pt;">异常处理器<br /><br /></span></strong><div>异常处理器的声明<br /><br /><div>DECLARE handler-type HANDLER FOR condition handler-action;&nbsp;</div><div>（语法结构）（异常处理器是需要预先声明的）<br /><div>异常处理器的类型（handler-type）</div><div>异常处理器的类型有如下几种：</div><div>CONTINUE（继续）</div><div>在异常处理器操作完成之后，会继续执行产生这个异常语句之后的下一条语句。&nbsp;</div><div>EXIT（记录完后就退出，不再继续执行）</div><div>在异常处理器操作完成之后，存储过程会终止，并将控制返回给调用者。&nbsp;</div><div>UNDO（撤销所做的记录，退出整个程序）</div><div>在异常处理器操作执行之前，DB2会回滚存储过程中执行的SQL操作。在异常处理器操作完成之后，存储过程会终止，并将控制返回给调用者。&nbsp;</div></div></div></div><div>异常处理器和SQLSTATE<br /><div>异常处理器可以处理基于特定SQLSTATE值的定制异常，或者处理预定义异常的类。预定义的3种异常如下所示：&nbsp;</div><div>NOT FOUND</div><div>标识导致SQLCODE值为＋100或者SQLSATE值为02000的异常。这个异常通常在SELECT没有返回行的时候出现。&nbsp;</div><div>SQLEXCEPTION</div><div>标识导致SQLCODE值为负的异常。&nbsp;</div><div>SQLWARNING</div><div>标识导致警告异常或者导致＋100以外的SQLCODE正值的异常。&nbsp;</div><div></div><div>注:如果产生了NOT FOUND 或者SQLWARNING异常，并且没有为这个异常定义异常处理器，那么就会忽略这个异常，并且将控制流转向下一个语句。如果产生了SQLEXCEPTION异常，并且没有为这个异常定义异常处理器，那么存储过程就会失败，并且会将控制流返回调用者</div><div>异常处理器示例</div><div>如下示例声明了两个异常处理器。 EXIT处理器会在出现SQLEXCEPTION 或者SQLWARNING异常的时候被调用。EXIT处理器会在终止SQL程序之前，将名为stmt的变量设为&#8220;ABORTED&#8221;,并且将控制流返回给调用者。UNDO处理器会将控制流返回给调用者之前，回滚存储过程体中已经完成的SQL操作。&nbsp;</div><div></div><div>&nbsp; &nbsp;DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SET stmt = 'ABORTED';&nbsp;</div><div></div><div></div><div>&nbsp; &nbsp; DECLARE UNDO HANDLER FOR NOT FOUND;&nbsp;</div><div>异常处理器定制<br /><div>&nbsp;如果预定义异常集不能满足需求，就可以为特定的SQLSTATE值声明定制异常，然后再为这个定制异常声明处理器。语法如下：&nbsp;</div><div>&nbsp; &nbsp;DECLARE unique-name CONDITION FOR SQLSATE 'sqlstate'&nbsp;</div><div>更为复杂的异常处理器示例（1 of 2）<br /><div>&nbsp; &nbsp; -- Generic Handler&nbsp;</div><div>&nbsp; &nbsp; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND</div><div>&nbsp; &nbsp; BEGIN NOT ATOMIC</div><div>&nbsp; &nbsp; &nbsp; &nbsp; -- Capture SQLCODE &amp; SQLSTATE&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; SELECT SQLCODE, SQLSTATE&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INTO hSqlcode, hSqlstate&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM SYSIBM.SYSDUMMY1;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Use the poGenStatus variable to tell the procedure -- what type of error occurred</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CASE hSqlstate&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN '02000' THEN&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET poGenStatus=5000;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN '42724' THEN&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SET poGenStatus=3;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE IF (hSqlCode &lt; 0) THEN&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET poGenStatus=hSqlCode;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END IF;&nbsp;</div><div>&nbsp; &nbsp; &nbsp;END&nbsp;</div><div><div>&nbsp; 上面的异常处理器会在出现SQLEXCEPTION, SQLWARNING, NOT FOUND异常的时候触发。异常处理器会取出当前的SQLCODE, SQLSTATE，然后根据它们的值来设置输出参数（poGenStatus）的值。&nbsp;<br /><br /></div></div></div><div><span style="font-size: 18pt;">十 编写和调试存储过程<br /></span><div></div><div>创建存储过程</div><div>将存储过程部署到本地或远程DB2数据库</div><div>修改并重新部署存储过程</div><div>对存储过程进行测试和Debug</div><div><div>使用Command Editor创建存储过程（1 of 3）<br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/commenderedit.jpg" width="562" height="351" alt="" /><br /><br /></div></div><img src="http://www.blogjava.net/images/blogjava_net/qileilove/comm2.jpg" width="520" height="395" alt="" /><br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/comm3.jpg" width="520" height="395" alt="" /><br /><br /></div></div></div></div></div></div></div></div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/392819.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2012-12-11 16:34 <a href="http://www.blogjava.net/qileilove/archive/2012/12/11/392819.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟屌丝一起学习 DB2 第五课 存储过程(一)</title><link>http://www.blogjava.net/qileilove/archive/2012/12/11/392814.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 11 Dec 2012 07:56:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2012/12/11/392814.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/392814.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2012/12/11/392814.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/392814.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/392814.html</trackback:ping><description><![CDATA[<div><h1><span style="font-size: 22pt; font-family: 宋体;">DB2&nbsp;存储过程</span></h1><h2><span style="font-size: 16pt; font-family: 黑体;">一、什么是存储过程</span></h2><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">受&nbsp;DB2&nbsp;服务器控制的一段可执行程序</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">可以通过SQL的CALL语句来完成对存储过程的调用</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">在存储过程中可以包含业务逻辑</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">存储过程可以在本地或远程进行调用</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">存储过程可以接收或传递参数，生成结果集</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><h2><span style="font-size: 16pt; font-family: 黑体;">二、存储过程特征</span></h2><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">包含使用sql语句的过程构造</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">存储在数据库中且在db2&nbsp;服务器上运行；</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">可以由正在使用的sql的应用程序根据名称来调用；</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">允许应用程序分2部分允许，在客户机上运行应用程序，在服务器上运行存储过程</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">存储过程在应用程序中的优势</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">减少了客户机与服务器直接的网络使用率</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">增强了硬件和软件功能</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">提高了安全性</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">减少了开发成本并且提高了可靠性</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">集中处理了公共例程的安全性、管理和维护</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">通过sql&nbsp;pl&nbsp;当前的语句集合和语言特性，可以用sql开发综合的、高级的程序</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; background:#ffffff; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">例如函数、存储过程和触发器。</span><span style="color: #454545; font-size: 10.5pt; font-family: Tahoma; background-position: initial initial; background-repeat: initial initial;">这样便可以将业务逻辑封装到易于维护的数据库对象中，从而提高数据库应用程序的性能。</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; background:#ffffff; "><span style="color: #454545; font-size: 10.5pt; font-family: Tahoma; background-position: initial initial; background-repeat: initial initial;">SQL&nbsp;PL&nbsp;支持本地和全局变量，包括声明和赋值，还支持条件语句和迭代语句、控制语句的转移、错误管理语句以及返回结果集的方法。</span></p><h2><span style="font-size: 16pt; font-family: 黑体;">三、什么时候使用存储过程</span></h2><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; background:#ffffff; "><span style="color: #454545; font-size: 10.5pt; font-family: Tahoma; background-position: initial initial; background-repeat: initial initial;">使用存储过程的合适时机:</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; background:#ffffff; "><span style="color: #454545; font-size: 10.5pt; font-family: Tahoma; background-position: initial initial; background-repeat: initial initial;">应用程序的性能无法满足预期时</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; background:#ffffff; "><span style="color: #454545; font-size: 10.5pt; font-family: Tahoma; background-position: initial initial; background-repeat: initial initial;">客户端数量较多且应用程序中SQL代码分散时</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; background:#ffffff; "><span style="color: #454545; font-size: 10.5pt; font-family: Tahoma; background-position: initial initial; background-repeat: initial initial;">应用程序需要进行繁重的数据库操作，同时这些操作并不需要进行太多的客户交互</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; background:#ffffff; "><span style="color: #454545; font-size: 10.5pt; font-family: Tahoma; background-position: initial initial; background-repeat: initial initial;">应用程序代码更改频繁</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; background:#ffffff; "><span style="color: #454545; font-size: 10.5pt; font-family: Tahoma; background-position: initial initial; background-repeat: initial initial;">需要对客户应用代码进行访问控制时</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; background:#ffffff; "><span style="color: #454545; font-size: 10.5pt; font-family: Tahoma; background-position: initial initial; background-repeat: initial initial;">客户应用需要在一次操作中执行多条&nbsp;SQL&nbsp;语句</span></p><h2><img src="http://www.blogjava.net/images/blogjava_net/qileilove/db2hgjh.png" width="814" height="547" alt="" /><br /><br /></h2><h2><span style="font-size: 16pt; font-family: 黑体;">五、数据类型</span></h2><img src="http://www.blogjava.net/images/blogjava_net/qileilove/数据类型.png" width="486" height="600" alt="" /><br /><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">字符型：</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">char&nbsp;varchar</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">日期型&nbsp;date</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">数字型&nbsp;number&nbsp;decilmal&nbsp;integer</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">详细请看屌丝大哥&nbsp;db2数据类型介绍的那一课</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><h2><span style="font-size: 16pt; font-family: 黑体;">六、</span><span style="font-size: 16pt; font-family: 黑体;">Db2&nbsp;存储过程基本语法</span></h2><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><h3><span style="font-size: 16pt; font-family: 宋体;">6.1&nbsp;存储过程结构</span></h3><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">CREATE&nbsp;OR&nbsp;REPLACE&nbsp;PROCEDURE&nbsp;&lt;过程名&gt;</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">(&nbsp;[&nbsp;IN&nbsp;|&nbsp;OUT&nbsp;|&nbsp;INOUT&nbsp;]&nbsp;&nbsp;参数名&nbsp;&nbsp;数据类型&nbsp;&nbsp;默认值&nbsp;)</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">LANGUAGE&nbsp;&nbsp;SQL</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">BEGIN</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;业务逻辑代码</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">END;</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">IN（输入参数）</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">只是将实参传递给存储过程，但在存储过程中不能对其进行修改。换句话说，对于存储过程而言它是只读的。</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">OUT（输出参数）</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">在存储过程结束时向调用者返回。一般在过程中都会被赋值。</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">INOUT（输入输出参数）</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">上述两种参数类型的结合体。它可以帮助调用者将实参传递给进程，另外它也能够作为输出参数被修改和赋值。</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">复合语句实例</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">复合语句是指包含在BEGIN和END间的语句。它一般包括如下语句类型：</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">声明语句</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">赋值语句</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">控制语句</span></p><p style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 10.5pt; font-family: 宋体;">条件处理语句<br /><br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/复合语句.png" width="721" height="458" alt="" /><br /><br /><br /></span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="position:absolute; z-index:1; left:0px; margin-left:89.8667px; margin-top:778.2667px; width:522.0000px; height:351.0000px; "><img width="522" height="351" src="file:///C:\DOCUME~1\pccw\LOCALS~1\Temp\ksohtml\wps_clip_image-20435.png" alt="" /></span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">说明：</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">1.&nbsp;复合语句可以嵌套使用。</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">2.&nbsp;BEGIN语句可以和标签组合使用，这样可以更清晰的标识语句块的范围。</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "></p><p style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><h3><span style="font-size: 16pt; font-family: 宋体;">6.2&nbsp;变量声明与变量赋值</span></h3><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">变量声明语法：</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DECLARE&nbsp;变量名&nbsp;&nbsp;数据类型&nbsp;初始值；</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">Delcare&nbsp;DiaoSiName&nbsp;varchar（20）；</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">变量赋值语法&nbsp;：set&nbsp;变量名=值；</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">例如：给屌丝姓名变量赋值。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">Set&nbsp;DiaoSiName&nbsp;=&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&#8216;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">奶娃</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&#8217;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">变量声明</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DECLARE&nbsp;&nbsp;my_var&nbsp;&nbsp;INTEGER&nbsp;&nbsp;DEFAULT&nbsp;&nbsp;6;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">条件声明</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DECLARE&nbsp;&nbsp;not_found&nbsp;&nbsp;CONDITION&nbsp;&nbsp;FOR&nbsp;&nbsp;SQLSTATE&nbsp;&nbsp;&#8216;02000&#8217;;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">游标声明</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DECLARE&nbsp;&nbsp;c1&nbsp;&nbsp;CURSOR&nbsp;&nbsp;FOR&nbsp;&nbsp;select&nbsp;&nbsp;*&nbsp;&nbsp;from&nbsp;&nbsp;staff;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">异常处理器声明</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DECLARE&nbsp;&nbsp;EXIT&nbsp;&nbsp;HANDLER&nbsp;&nbsp;FOR&nbsp;&nbsp;SQLEXCEPTION&nbsp;&nbsp;&#8230;;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">语法</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">SET&nbsp;&nbsp;lv_name&nbsp;&nbsp;=&nbsp;&nbsp;expression;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">SET&nbsp;&nbsp;lv_name&nbsp;&nbsp;=&nbsp;&nbsp;NULL;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">示例</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">(1)&nbsp;SET&nbsp;&nbsp;salary&nbsp;&nbsp;=&nbsp;&nbsp;salary&nbsp;&nbsp;+&nbsp;&nbsp;salary&nbsp;&nbsp;*&nbsp;&nbsp;0.1;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">(2)&nbsp;SET&nbsp;&nbsp;init_salary&nbsp;&nbsp;=&nbsp;&nbsp;NULL;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">(3)&nbsp;SET&nbsp;&nbsp;salary&nbsp;&nbsp;=&nbsp;&nbsp;(select&nbsp;&nbsp;salary&nbsp;&nbsp;from&nbsp;&nbsp;employee&nbsp;&nbsp;where&nbsp;empno&nbsp;&nbsp;=&nbsp;&nbsp;lv_emp_num);</span></p><p style="margin-bottom: 0pt; margin-top: 0pt;"><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">注:&nbsp;如果&nbsp;SELECT&nbsp;语句返回记录超过一行，示例&nbsp;3&nbsp;将会返回SQLERROR。<br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/例子1.png" width="632" height="431" alt="" /><br /><br /><br /><br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/列子2.png" width="633" height="431" alt="" /><br /><br /></span><div>模块 - 规格说明(Module Specification)<br /><br /><div>模块可以发布type, SP, UDF以供外部使用。</div><div>CREATE &nbsp;OR &nbsp;REPLACE &nbsp;MODULE &nbsp;myMod;</div><div></div><div>ALTER &nbsp;MODULE &nbsp;myMod &nbsp;PUBLISH</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TYPE &nbsp;myRowTyp &nbsp;AS &nbsp;ANCHOR &nbsp;ROW &nbsp;myTab;</div><div></div><div>ALTER &nbsp;MODULE &nbsp;myMod &nbsp;PUBLISH</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FUNCTION &nbsp;myFunc(val1 &nbsp;ANCHOR &nbsp;myTab.col1)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RETURNS myRowTyp;</div><div></div><div>ALTER &nbsp;MODULE &nbsp;myMod &nbsp;PUBLISH</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PROCEDURE &nbsp;myProc(OUT &nbsp;param1 &nbsp;ANCHOR &nbsp;myTab.col2);</div><div></div></div><div>模块 - 实现(Module Implementation)</div><div>下面的代码是模块的实现部分：</div><div>ALTER &nbsp;MODULE &nbsp;myMod &nbsp;ADD &nbsp;VARIABLE &nbsp;pkgVar &nbsp;ANCHOR &nbsp;myTab.col1;</div><div></div><div>ALTER &nbsp;MODULE &nbsp;myMod &nbsp;ADD &nbsp;FUNCTION &nbsp;<span style="white-space:pre">	</span>myFunc(val1 &nbsp;ANCHOR &nbsp;myTab.col1) &nbsp;RETURNS &nbsp;myRowTyp</div><div>BEGIN</div><div>&nbsp; &nbsp; DECLARE &nbsp;var1 &nbsp;myRowTyp;</div><div>&nbsp; &nbsp; SELECT &nbsp;* &nbsp;INTO &nbsp;var1 &nbsp;FROM &nbsp;myTab &nbsp;WHERE &nbsp;col1 &nbsp;&lt; &nbsp;val1 &nbsp;AND &nbsp;col1 &nbsp;&gt; &nbsp;pkgVar;</div><div><span style="white-space:pre">	</span>RETURN &nbsp;var1;</div><div>END</div><div></div><div>ALTER &nbsp;MODULE &nbsp;myMod &nbsp;ADD &nbsp;PROCEDURE &nbsp;myProc(OUT &nbsp;param1 &nbsp;ANCHOR &nbsp;myTab.col2)</div><div>BEGIN</div><div>&nbsp; &nbsp; DECLARE &nbsp;varRow &nbsp;myRowTyp;</div><div><span style="white-space:pre">	</span>SET &nbsp;param1 &nbsp;= &nbsp;varRow.col2 &nbsp;&#8211; &nbsp;pkgVar;</div><div>END<br /><br /><div>模块 - 其他语句<br /><br /><div>删除整个模块</div><div>DROP &nbsp;MODULE &nbsp;myMod;</div><div>保留规格说明内容，删除实现</div><div>ALTER &nbsp;MODULE &nbsp;myMod &nbsp;DROP &nbsp;BODY;</div><div>删除模块中的存储过程(SP)</div><div>ALTER MODULE myMod DROP PROCEDURE myProc;</div><div>将模块的执行权限赋给joe</div><div>GRANT EXECUTE ON MODULE myMod TO joe;<br /><div><strong><br /></strong></div><div><span style="font-size: 18pt;"><strong>七、控制语句<br /></strong></span><div>IF语句</div></div><div><div>格式：</div><div>IF &nbsp;条件1 &nbsp; THEN &nbsp;statement1;</div><div>ELSEIF &nbsp;条件2 &nbsp;THEN &nbsp;statement2;</div><div>ELSE &nbsp;statement3;</div><div><span style="white-space:pre">	</span> &nbsp; END &nbsp;IF;</div><div></div><div>注:条件成立时为TRUE (真),不成立时为FALSE(假) 和 NULL</div><div><div>IF语句例子</div></div></div><div>IF &nbsp;rating &nbsp;= &nbsp;1 &nbsp;THEN</div><div><span style="white-space:pre">	</span>UPDATE &nbsp;EMPLOYEE &nbsp;SET &nbsp;salary &nbsp;= &nbsp;salary*1.10</div><div>&nbsp; &nbsp; &nbsp;WHERE &nbsp;empno &nbsp;= &nbsp;i_num;（如果满足于...时，薪水调整1.1倍）</div><div>ELSEIF &nbsp;rating &nbsp;= &nbsp;2 &nbsp;THEN</div><div><span style="white-space:pre">	</span>UPDATE &nbsp;EMPLOYEE &nbsp;SET &nbsp;salary &nbsp;= &nbsp;salary*1.05</div><div>&nbsp; &nbsp; &nbsp;WHERE &nbsp;empno &nbsp;= &nbsp;i_num;</div><div>ELSE</div><div><span style="white-space:pre">	</span>UPDATE &nbsp;EMPLOYEE &nbsp;SET &nbsp;salary &nbsp;= &nbsp;salary*1.03</div><div>&nbsp; &nbsp; &nbsp;WHERE &nbsp;empno &nbsp;= &nbsp;i_num;</div><div>END &nbsp;IF;</div><div>CASE语句（1 of 2）<br /><br /><div>简单CASE语句<br /><br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/case1.png" width="823" height="469" alt="" /><br /><br /><div>稍加变形的CASE语句<br /><br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/case2.png" width="783" height="485" alt="" /><br /><br /><br /><div>LOOP语句<br /><div>语法</div><div>[LABEL] &nbsp;LOOP</div><div>&nbsp; &nbsp; SQL-procedure-statements;</div><div><span style="white-space:pre">	</span> &nbsp; &nbsp;END &nbsp;LOOP &nbsp;[LABEL];</div><div>示例</div><div>fetch_loop: &nbsp;LOOP</div><div><span style="white-space:pre">	</span>FETCH &nbsp;c1 &nbsp;INTO &nbsp;v_firstname, &nbsp;v_lastname;</div><div>&nbsp; &nbsp; &nbsp;SET &nbsp;counter &nbsp;= &nbsp;counter &nbsp;+ &nbsp;1;</div><div>&nbsp; &nbsp; &nbsp;IF &nbsp;counter &nbsp;= &nbsp;51 &nbsp;THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LEAVE &nbsp;fetch_loop;</div><div>&nbsp; &nbsp; &nbsp;END &nbsp;IF;</div><div>END &nbsp;LOOP &nbsp;fetch_loop;</div><div><div>FOR语句</div></div></div><div>语法</div><div>[LABEL] &nbsp;FOR &nbsp;for-loop-name &nbsp;AS &nbsp;[cursor-name &nbsp;CURSOR &nbsp;FOR]</div><div>&nbsp; &nbsp; &nbsp; select-statement &nbsp;</div><div>DO</div><div>&nbsp; &nbsp; &nbsp; SQL-procedure-statements;</div><div><span style="white-space:pre">	</span> &nbsp; &nbsp;END &nbsp;FOR &nbsp;[LABEL];</div><div>示例</div><div>DECLARE &nbsp;fullname &nbsp;CHAR(40);</div><div>FOR &nbsp;v1 &nbsp;AS &nbsp;c1 &nbsp;CURSOR &nbsp;FOR &nbsp;SELECT &nbsp;firstnme, &nbsp;midinit, &nbsp;lastname &nbsp;FROM &nbsp;employee</div><div>DO</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SET &nbsp;fullname=lastname||&#8216;,&#8217;||firstnme||&#8217;,&#8217;||midinit;</div><div>&nbsp; &nbsp; INSERT &nbsp;INTO &nbsp;tname &nbsp;VALUE &nbsp;(fullname);</div><div>END &nbsp;FOR;</div><div></div></div></div></div></div></div></div></p></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p></div><img src ="http://www.blogjava.net/qileilove/aggbug/392814.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2012-12-11 15:56 <a href="http://www.blogjava.net/qileilove/archive/2012/12/11/392814.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟屌丝大哥学DB2-第四课 数据类型 ，表 ，视图，索引，模式，约束（一）</title><link>http://www.blogjava.net/qileilove/archive/2012/12/06/392570.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 06 Dec 2012 15:12:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2012/12/06/392570.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/392570.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2012/12/06/392570.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/392570.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/392570.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: (DiaoSiID)在我们建立表前 ，我们先要了解DB2中都有哪些数据类型，以便我们这些屌丝以后快速创建表。DB2 提供了一套丰富且灵活的数据类型。DB2 附带 INTEGER、CHAR 和 DATE 等基本数据类型。它还提供了创建用户定义的数据类型（UDT）的工具，使用户能够创建复杂的非传统的数据类型，从而适应当今复杂的编程环境。在给定的情况下，选用哪种数据类型取决于列中存储的信息的类型和范围。...&nbsp;&nbsp;<a href='http://www.blogjava.net/qileilove/archive/2012/12/06/392570.html'>阅读全文</a><img src ="http://www.blogjava.net/qileilove/aggbug/392570.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2012-12-06 23:12 <a href="http://www.blogjava.net/qileilove/archive/2012/12/06/392570.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟屌丝一起学习 DB2 第三课 创建表空间</title><link>http://www.blogjava.net/qileilove/archive/2012/12/06/392554.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 06 Dec 2012 07:40:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2012/12/06/392554.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/392554.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2012/12/06/392554.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/392554.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/392554.html</trackback:ping><description><![CDATA[<p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px;">缓冲池(bufferpool) 是一个内存块的集合，这些内存块采用页面的形式。在首次创建数据库时，同时创建了一个默认的缓冲池 IBMDEFAULTBP。可以在创建表空间时，或者在 Buffer Pools 视图中使用 Create New Bufferpool 向导，创建新的缓冲池。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px;">　　缓冲池最重要的作用是，在数据库读写硬盘上的数据时帮助减少 I/O 开销。这是通过 I/O 预获取和页面清理器实现的。预获取能够减少读取页面的 I/O 开销，其原理是：预先判断特定查询可能需要的页面，然后将这些页面读入缓冲池，因此当查询需要它们时，它们已经准备好了。页面清理器确保将事务不再需要的已经更新的页面首先写到硬盘上，然后从缓冲池中清除它们。这确保缓冲池中有足够的干净空间可以读取页面。</p><p style="margin-left:21.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px;">　　DB2 支持不同的页面大小：2K、4K、8K、16K 和 32K。IBMDEFAULTBP 使用 4K 的页面大小。如果希望创建采用其他页面大小的表空间，那么首先要确保数据库中有采用这种页面大小的缓冲池。多个表空间可以使用同一个缓冲池。在创建或更改表空间时，可以指定要使用哪个缓冲池。选择和创建适当的缓冲池对于数据库性能很重要。可以根据需要创建新的缓冲池或更改现有的缓冲池。</span><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px; text-indent: 0px; background-color: #ffffff;">　</span><a title="db2" href="http://search.yesky.com/search.do?stype=0&amp;wd=DB2" target="_blank" style="text-decoration: initial; color: #333333; font-family: Arial, 宋体; line-height: 24px; text-indent: 0px; background-color: #ffffff;"><strong><u>DB2</u></strong></a><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px; text-indent: 0px; background-color: #ffffff;">数据库中的表空间(tablespace) 是一个逻辑层，一些数据库对象(比如表、视图和索引)驻留在这里。一个数据库可以有多个表空间。在首次创建数据库时，DB2 会自动地创建一组表空间。<br /></span><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px; text-indent: 0px; background-color: #ffffff;">　在 Control Center 中，展开 HELLOWLD 并点击 Table Spaces。应该会在 Control Center 右边的窗口中看到三个表空间，如图 7 所示：</span><br /><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">图 7. Control Center Table Spaces 视图</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　<img height="422" alt="Control Center Tablespaces 视图" src="http://dev.yesky.com/imagelist/2007/301/v47fk2tmnk05.jpg" width="497" style="padding: 0px; margin: 0px 0px 10px; border: 0px;" /></p><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px; text-indent: 0px; background-color: #ffffff;">　这些表空间是 DB2 在创建数据库 HWLD 时创建的。SYSCATSPACE 和 TEMPSPACE1 都是系统表空间，不能删除或重新创建它们。SYSCATSPACE 是系统编目表空间，用来存储关于数据库的元信息。TEMPSPACE1 在某些数据库操作期间用来存储临时结果。USERSPACE1 是默认的用户表空间，用来存储表、视图和索引等用户数据。任何具有足够权力的 DB2 用户都可以删除和重新创建 USERSPACE1 或者创建其他用户表空间。</span><br /><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　SMS 或 DMS 表空间</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　在创建表空间时，可以选择表空间是 SMS 表空间还是 DMS 表空间。SMS 代表 System Managed Space，DMS 代表 Database Managed Space。在 SMS 表空间中，空间由操作系统的文件系统管理，会根据需要分配空间。SMS 表空间需要的初始设置比较少，管理方面需要考虑的因素少，而且一般更容易创建和使用，因为空间会在需要时自动地分配。在 DMS 表空间中，空间由 DB2 管理。DMS 表空间需要在创建时预先分配空间，所以需要进行比较多的初始设置工作，管理方面也有更多需要考虑的因素。但是，它为用户提供了更大的灵活性，可以更好地控制数据的布局并改进数据访问的性能。在一般情况下，经过良好设计和调优的 DMS 表空间可以提供比相似的 SMS 表空间更好的性能。</p><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px; text-indent: 0px; background-color: #ffffff;">　在 Table Spaces 视图中，点击每个表空间。查看在右下方的窗口中显示的详细信息。SYSCATSPACE 和 USERSPACE1 都是 DMS 表空间，TEMPSPACE1 是 SMS 表空间。您还可以创建自己的表空间。<br /><br />屌丝 已经创建了 自己的表空间 你看&nbsp;<br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/未命名13.jpg" width="831" height="419" alt="" /><br /></span><br />当然你也可以用命令插入了 插入 插入。。。。。屌丝非常忌讳的词<br /><br /><br /><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">只有sysadm和sysctl的权限才可以创建表空间</span></p><p style="margin-left:21.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">只有在缓冲池创建或者激活的状态才能使用create&nbsp;tablespace命令</span></p><p style="margin-left:21.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">缓冲池可以动态的增加、删除和变更</span></p><p style="margin-left:21.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DFT_PREFETCH_SZ能够优化计算的环境<br /></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">create&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[LARGE/REGULAR/TEMPORARY]</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TABLESPACE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tablespace</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PAGESIZE</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">integer</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MANAGED&nbsp;BY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[AUTOMATIC&nbsp;STORAGE][SYSTEM/DATABASE]</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[system-container/database-container]</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EXTENTSIZE</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">[number-of-pages/integer]</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PREFETCHSIZE</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">[number-of-pages/integer]</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BUFFERPOOL</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">bufferpool-name</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OVERHEAD</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">number-of-milliseconds&nbsp;(<font face="宋体">系统默认</font><font face="Calibri">)</font></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRANSFEBRATE</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">number-of-milliseconds</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AUTORESIZE</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">	</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">YES</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;USING&nbsp;(DEVICE&nbsp;'Container-String'&nbsp;integer&nbsp;K|M|G)</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">这里是个例子 大家可以联系下 create&nbsp;tabblespace&nbsp;屌丝 managed&nbsp;by&nbsp;database&nbsp;using&nbsp;(device&nbsp;'/dev/rhdisk0'&nbsp;10000(<font face="宋体">页数</font><font face="Calibri">),device'/dev/rn1hd01'&nbsp;40G)<br /></font></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">注意这里的<font face="Calibri">pagesize&nbsp;</font><font face="宋体">同</font><font face="Calibri">bufferpool</font><font face="宋体">中的</font><font face="Calibri">pagesize</font><font face="宋体">是相同的<br /><br /></font></span></p><h3 style="margin-left:21.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="font-size: 10.5pt; font-family: 宋体;">&nbsp;</span><span style="font-size: 10.5pt; font-family: 宋体;">表空间的类型</span><span style="font-size: 10.5pt; font-family: Calibri;"><o:p></o:p></span></h3><p class="p0" style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">C</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">reate&nbsp;&nbsp;{large<font face="宋体">、</font><font face="Calibri">regular</font><font face="宋体">、</font><font face="Calibri">[system/user]&nbsp;temporary}&nbsp;TABLESAPCE&nbsp;name</font></span></p><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "><font face="宋体"><br /></font></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span><p>&nbsp;</p><h4 style="margin-left:21.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="font-size: 10.5pt; font-family: 宋体;">(1)&nbsp;</span><span style="font-size: 10.5pt; font-family: 宋体;">常规表空间<font face="Cambria">(REGULAR)</font></span><span style="font-size: 10.5pt; font-family: Cambria;"><o:p></o:p></span></h4><p class="p15" style="margin-left:42.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">SMS<font face="宋体">时默认为</font><font face="Calibri">regular</font></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p15" style="margin-left:42.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">存储用户数据，如<font face="Calibri">USERSPACE1</font></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><h4 style="margin-left:21.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="font-size: 10.5pt; font-family: 宋体;">(2)&nbsp;</span><span style="font-size: 10.5pt; font-family: 宋体;">临时表空间</span><span style="font-size: 10.5pt; font-family: Cambria;"><o:p></o:p></span></h4><p class="p15" style="margin-left:42.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">系统临时表空间：<font face="Calibri">DB2</font><font face="宋体">用来排序</font></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p15" style="margin-left:42.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">用户临时表空间：被用来定义全局临时表空间在内存里<br /></span><h4 style="margin-left:21.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="font-size: 10.5pt; font-family: 宋体;">创建用户临时表空间：</span><span style="font-size: 10.5pt; font-family: Cambria;"><o:p></o:p></span></h4><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;&nbsp;用户临时表空间用来存储已说明的临时表。</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">CREATE&nbsp;USER&nbsp;TEMPORARY&nbsp;TABLESPACE&nbsp;usr_tbsp</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;MANAGED&nbsp;BY&nbsp;DATABASE</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;USING&nbsp;(FILE&nbsp;'d:\db2data\user_tbsp'&nbsp;5000,</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FILE&nbsp;'e:\db2data\user_tbsp'&nbsp;5000)</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><h4 style="margin-left:21.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="font-size: 10.5pt; font-family: 宋体;">(3)&nbsp;</span><span style="font-size: 10.5pt; font-family: 宋体;">大型表空间</span><span style="font-size: 10.5pt; font-family: Cambria;"><o:p></o:p></span></h4><p class="p15" style="margin-left:42.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DMS<font face="宋体">时&nbsp;默认是</font><font face="Calibri">LARGE</font></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><p class="p15" style="margin-left:42.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; line-height:150%; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">l&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">存储多媒体对象或其他大型对象数据</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Calibri'; "><o:p></o:p></span></p><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">接下来 屌丝大哥 为你介绍表空间</span><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">缓冲池<br /><br /></span><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">缓冲池(bufferpool) 是一个内存块的集合，这些内存块采用页面的形式。在首次创建数据库时，同时创建了一个默认的缓冲池 IBMDEFAULTBP。可以在创建表空间时，或者在 Buffer Pools 视图中使用 Create New Bufferpool 向导，创建新的缓冲池。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　缓冲池最重要的作用是，在数据库读写硬盘上的数据时帮助减少 I/O 开销。这是通过 I/O 预获取和页面清理器实现的。预获取能够减少读取页面的 I/O 开销，其原理是：预先判断特定查询可能需要的页面，然后将这些页面读入缓冲池，因此当查询需要它们时，它们已经准备好了。页面清理器确保将事务不再需要的已经更新的页面首先写到硬盘上，然后从缓冲池中清除它们。这确保缓冲池中有足够的干净空间可以读取页面。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　DB2 支持不同的页面大小：2K、4K、8K、16K 和 32K。IBMDEFAULTBP 使用 4K 的页面大小。如果希望创建采用其他页面大小的表空间，那么首先要确保数据库中有采用这种页面大小的缓冲池。多个表空间可以使用同一个缓冲池。在创建或更改表空间时，可以指定要使用哪个缓冲池。选择和创建适当的缓冲池对于数据库性能很重要。可以根据需要创建新的缓冲池或更改现有的缓冲池。<br />　在 Control Center 中，点击 Buffer Pools。可以看到数据库中的所有缓冲池。选择创建新的缓冲池或更改现有的缓冲池。<br /></p><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;"><img src="http://www.blogjava.net/images/blogjava_net/qileilove/未命名15.jpg" width="1138" height="704" alt="" /><br />看到了么 &nbsp;屌丝大哥 也创建了个缓冲池 是不是很给力？？<br /></span><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">DB2 系统目录表和视图</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　在创建新数据库时，DB2 会在编目表空间中创建多个系统编目表和视图。这些系统编目表和视图用来跟踪数据库管理程序需要知道的关于数据库对象、访问控制信息和工具的重要信息。系统编目视图基于基本系统编目表。用户在一般情况下通过查询系统编目视图来查看感兴趣的系统编目表数据。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　在 Control Center 中，在 All Database 视图下面，展开 HELLOWLD，然后选择 Table Spaces。选择右上窗口中显示的 SYSCATSPACE。可以在右下窗口中看到这个表空间的概况：</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">Control Center &#8212;&#8212; Tablespaces 视图</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　<img height="309" alt="CC &#8212;&#8212; Tablespaces 视图" src="http://dev.yesky.com/imagelist/2007/301/7546h357579g.jpg" width="490" style="padding: 0px; margin: 0px 0px 10px; border: 0px;" /></p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　点击 Show Related Objects。会出现一个新页面，其中显示表空间 SYSCATSPACE 中的所有表和索引，以及它们的模式 SYSIBM。点击 Indexes，列出 SYSCATSPACE 中的所有索引。Show SQL 显示用来获得这个表空间中的表或索引列表的 select 命令。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　表、索引、模式和视图都是重要的 DB2 对象，本教程后面都会详细讨论。但是，首先试试手工创建表空间：</p><ol style="padding: 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;"><li style="padding: 0px; margin: 0px; border: 0px; list-style: none;">在 Control Center 中点击 Create New Tablespace，启动 Create Table Space 向导。输入 TBSP_DATA1 作为表空间名，在 comment 中输入 DMS tablespace to hold data。</li><li style="padding: 0px; margin: 0px; border: 0px; list-style: none;">选择 Regular 来选择要使用的表空间类型并点击 Next。出现 Specify a buffer pool 面板，在这里选择这个表空间要使用的缓冲池。</li><li style="padding: 0px; margin: 0px; border: 0px; list-style: none;">使用默认的 IBM 缓冲池，但是也可以使用 Create 按钮创建新的缓冲池。点击 Next。</li></ol><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;"><br /></span><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">创建新的表空间 &#8212;&#8212; 指定缓冲池</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　<img height="332" alt="创建新的表空间 &#8212;&#8212; 步骤 2" src="http://dev.yesky.com/imagelist/2007/301/6c50d648aob9.jpg" width="500" style="padding: 0px; margin: 0px 0px 10px; border: 0px;" /></p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　4.　这个面板允许指定表空间是由数据库管理(DMS)，还是由系统管理(SMS)。选择 Database-managed space (high performance)。点击 Next。Containers 页面出现。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　5.　在 Containers 页面上，可以指定容器的数量。容器(Container) 可以是存储表空间数据的目录、文件或设备。可以为每个表空间创建多个容器，而且在创建表空间之后，可以删除现有的容器或添加更多的容器。点击 Add，Define Container 页面出现，可以在这里为新的表空间定义容器。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　6.　可以为新的表空间定义多个容器。不同的容器可以位于不同的物理节点或路径。按照图 11 所示添加容器，然后点击 OK。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　图 11. 创建新的表空间 &#8212;&#8212; 添加容器</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　<img height="365" alt="创建新的表空间 &#8212;&#8212; 添加容器" src="http://dev.yesky.com/imagelist/2007/301/9889t41c66lx.jpg" width="437" style="padding: 0px; margin: 0px 0px 10px; border: 0px;" /></p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　7.　用相同的操作添加相同路径上的另一个容器 tbsp_data1_c02。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　8.　应该会看到添加的两个容器，见图 12。每个容器的大小是 5MB，总共 10MB。如果对已经定义的容器不满意，那么点击 Change 或 Remove。点击 Next 继续。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　图 12. 创建新的表空间 &#8212;&#8212; 容器页面</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　<img height="188" alt="创建新的表空间 &#8212;&#8212; 容器页面" src="http://dev.yesky.com/imagelist/2007/301/knm7515nmvgb.jpg" width="500" style="padding: 0px; margin: 0px 0px 10px; border: 0px;" /></p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　9.　下一个页面帮助您定义这个表空间使用的区间和预获取大小。一个区间(extent)包含一系列连续的页面。页面的数量称为区间的大小。一般来说，希望一次分配多个页面，从而减少空间分配的开销。预获取大小是指在启用预获取时预获取器读取的页面数量。预获取的概念在前面讨论过。选择 Less than 25MB 来改变表的平均大小，建议的区间大小会自动地改为适当的设置。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　10.　点击 Summary 显示 Summary 页面。点击 Show SQL 并将 SQL 保存在 C:\DB2\hellowld\<a href="http://www.mydown.com/soft/2/2382.html" target="_blank" style="text-decoration: initial; color: #333333;">crt</a>_tbsp.clp 中。点击 Finish 让 Create Tablespace 向导完成操作。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　11.　在 Control Center Table Spaces 视图中，应该能够找到新的表空间 TBSP_DATA1。如果对新创建的表空间 TBSP_DATA1 不完全满意，那么点击 Alter Tablespace 来修改这个表空间。如果希望创建 SMS 表空间，那么点击 Create New Tablespace。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　图 13. Control Center &#8212;&#8212; Tablespace 视图</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　<img height="431" alt="Control Center &#8212;&#8212; Tablespace 视图" src="http://dev.yesky.com/imagelist/2007/301/sz6114d3loa7.jpg" width="500" style="padding: 0px; margin: 0px 0px 10px; border: 0px;" /></p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　12.　将索引、大对象(Large Object，LOB)和大字段(Long Field，LF)或 XML 数据与表数据分开存储是有好处的。但是，在本教程中没有 LOB/LF 数据，所以不需要为它们创建表空间。XML 数据存储在与其他数据相同的表空间 TBSP_DATA1 中，所以也不需要为它创建表空间。后面几节将讨论索引。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　13.　在 DB2 命令行上，输入 cd C:\DB2\HELLOWLD\ 来创建表空间。如果目录 HELLOWLD 还不存在，需要首先创建它。然后，运行以下命令 notepad crt_tbsp.clp。在 notepad 中，编辑 Create Tablespace 语句，将它改为以下代码： CREATE LARGE TABLESPACE TBSP_INDEX1 PAGESIZE 4 K MANAGED BY DATABASE USING</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　(FILE 'C:\DB2\NODE0000\hellowld\dbdir\tbsp_index1_c01' 5120,</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　FILE 'C:\DB2\NODE0000\hellowld\dbdir\tbsp_index1_c02' 5120)</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　EXTENTSIZE 8 OVERHEAD 10.5 PREFETCHSIZE 8 TRANSFERRATE 0.14 BUFFERPOOL IBMDEFAULTBP;</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　14.　将 COMMENT 语句改为： COMMENT ON TABLESPACE TBSP_INDEX1&nbsp;<a href="http://www.mydown.com/soft/network/chat/475/444475.shtml" target="_blank" style="text-decoration: initial; color: #333333;">IS</a>'tablespace to hold index data';</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　现在 crt_tbsp.clp 中的命令应该是下面这样：<br /><br />CONNECT TO HELLOWLD;&nbsp;<br /><br />CREATE LARGE TABLESPACE TBSP_INDEX1 PAGESIZE 4 K MANAGED BY DATABASE USING&nbsp;<br />(FILE 'C:\DB2\NODE0000\hellowld\dbdir\tbsp_index1_c01' 5120,&nbsp;<br />FILE 'C:\DB2\NODE0000\hellowld\dbdir\tbsp_index1_c02' 5120 )&nbsp;<br />EXTENTSIZE 8 OVERHEAD 10.5 PREFETCHSIZE 16 TRANSFERRATE 0.14 BUFFERPOOL IBMDEFAULTBP ;&nbsp;<br /><br />COMMENT ON TABLESPACE TBSP_INDEX1 IS 'tablespace to hold index data';&nbsp;<br /><br />CONNECT RESET;&nbsp;<br /><br />　　15.　保存并退出 notepad。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　16.　在 DB2 命令行窗口中运行 db2 -tvf crt_tbsp.clp 命令，应该会看到成功地创建了这个表空间。DB2 命令行选项 -tvf 允许运行来自文件的 DB2 命令。</p><p style="padding: 14px 0px; margin: 0px; border: 0px; color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;">　　17.　进入 Control Center，点击 Control Center 主菜单中的 Selected，然后点击下拉菜单中的 Refresh，查看到目前为止创建的所有表空间。</p><span style="color: #333333; font-family: Arial, 宋体; line-height: 24px; background-color: #ffffff;"><br /></span><p>&nbsp;</p><img src ="http://www.blogjava.net/qileilove/aggbug/392554.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2012-12-06 15:40 <a href="http://www.blogjava.net/qileilove/archive/2012/12/06/392554.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟屌丝学DB2 第二课 建立数据库以及添加用户</title><link>http://www.blogjava.net/qileilove/archive/2012/12/05/392514.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 05 Dec 2012 10:30:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2012/12/05/392514.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/392514.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2012/12/05/392514.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/392514.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/392514.html</trackback:ping><description><![CDATA[<span style="font-family: Arial; line-height: 24px; background-color: #ffffff; font-size: 12pt;">在安装DB2 之后，就可以在 DB2 环境中创建自己的</span><a href="http://www.knowsky.com/sql.asp" style="text-decoration: initial; color: black; line-height: 12pt; font-family: 宋体; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">数据库</span></a><span style="font-family: Arial; line-height: 24px; background-color: #ffffff; font-size: 12pt;">。首先考虑数据库应该使用哪个实例。实例(instance) 提供一个由数据库管理配置(DBM CFG)文件控制的逻辑层，可以在这里将多个数据库分组在一起。DBM CFG 文件包含一组 DBM CFG 参数，可以使用它们对实例进行调优。在每个工作站上可以创建多个实例，在每个实例中可以创建多个数据库。<br /></span><span style="font-family: Arial; font-size: 12pt;">屌丝学习当然要创建屌丝实例</span><br /><span style="color: #333333; font-family: Arial; line-height: 25.200000762939453px; background-color: #eef3f8; font-size: 12pt;">Windows先创建DB2实例的方法&nbsp;<br /></span><span style="color: #333333; font-family: Arial; line-height: 25.200000762939453px; background-color: #eef3f8; font-size: 12pt;">在Windows下,通过如下命令即可创建DB2实例:db2icrt instance_name<br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/未命名.jpg" width="689" height="319" alt="" /><br /></span><span style="color: #333333; font-family: Arial; line-height: 25.200000762939453px; background-color: #eef3f8; font-size: 12pt;">屌丝这个实例就创建<br /></span><span style="color: #333333; font-family: Arial; line-height: 25.200000762939453px; background-color: #eef3f8; font-size: 12pt;">将屌丝这个实例添加进数据库中，如图<br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/未命名11.jpg" alt="" /><br /><img src="http://www.blogjava.net/images/blogjava_net/qileilove/未命名11.jpg" width="1136" height="704" alt="" /><br /><br /></span><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">需要注意的是,instance_name必须按照如下的规则命令:</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　1)不能大于 8 个字符</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　2)不能 以"sql"、"ibm"或"sys"开头</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　3)不能以数字开头或者包含 a-z、$、#、@、_ 或 0-9 之外的字符</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　如：</span></p><span style="color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><br /></span><table border="0" cellspacing="0" cellpadding="6" width="95%" align="center" style="padding: 0px; margin: 0px; border-color: #cccccc; color: #333333; font-family: Arial, 宋体; font-size: 14px; line-height: 25.200000762939453px; text-align: start; background-color: #eef3f8; table-layout: fixed;"><tbody style="padding: 0px; margin: 0px; border: 0px;"><tr style="padding: 0px; margin: 0px; border: 0px;"><td bgcolor="#fdfddf" style="padding: 0px; margin: 0px; border: 0px; word-wrap: break-word;"><font style="padding: 0px; margin: 0px; border: 0px; color: #990000; font-weight: bold;"><span style="font-family: Arial; font-size: 12pt;">以下是代码片段：</span></font><br style="padding: 0px; margin: 0px; border: 0px;" /><span style="font-family: Arial; font-size: 12pt;">DB2BIN&gt;db2icrt insttest</span></td></tr></tbody></table><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　DB20000I DB2ICRT命令成功完成。</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　DB2BIN&gt;db2ilist --列举服务器上存在的 DB2 实例</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><table border="0" cellspacing="0" cellpadding="6" width="95%" align="center" style="padding: 0px; margin: 0px; border-color: #cccccc; color: #333333; font-family: Arial, 宋体; font-size: 14px; line-height: 25.200000762939453px; text-align: start; background-color: #eef3f8; table-layout: fixed;"><tbody style="padding: 0px; margin: 0px; border: 0px;"><tr style="padding: 0px; margin: 0px; border: 0px;"><td bgcolor="#fdfddf" style="padding: 0px; margin: 0px; border: 0px; word-wrap: break-word;"><font style="padding: 0px; margin: 0px; border: 0px; color: #990000; font-weight: bold;"><span style="font-family: Arial; font-size: 12pt;">以下是代码片段：</span></font><br style="padding: 0px; margin: 0px; border: 0px;" /><span style="font-family: Arial; font-size: 12pt;">&nbsp;&nbsp;&nbsp; INSTTEST&nbsp;</span><br style="padding: 0px; margin: 0px; border: 0px;" /><span style="font-family: Arial; font-size: 12pt;">　　D:DB2BIN&gt;</span></td></tr></tbody></table><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　要删除一个实例，首先断开所有数据库连接，然后执行以下命令停止实例：</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><table border="0" cellspacing="0" cellpadding="6" width="95%" align="center" style="padding: 0px; margin: 0px; border-color: #cccccc; color: #333333; font-family: Arial, 宋体; font-size: 14px; line-height: 25.200000762939453px; text-align: start; background-color: #eef3f8; table-layout: fixed;"><tbody style="padding: 0px; margin: 0px; border: 0px;"><tr style="padding: 0px; margin: 0px; border: 0px;"><td bgcolor="#fdfddf" style="padding: 0px; margin: 0px; border: 0px; word-wrap: break-word;"><font style="padding: 0px; margin: 0px; border: 0px; color: #990000; font-weight: bold;"><span style="font-family: Arial; font-size: 12pt;">以下是代码片段：</span></font><br style="padding: 0px; margin: 0px; border: 0px;" /><span style="font-family: Arial; font-size: 12pt;">db2idrop -f instance_name</span></td></tr></tbody></table><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　比如：</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><table border="0" cellspacing="0" cellpadding="6" width="95%" align="center" style="padding: 0px; margin: 0px; border-color: #cccccc; color: #333333; font-family: Arial, 宋体; font-size: 14px; line-height: 25.200000762939453px; text-align: start; background-color: #eef3f8; table-layout: fixed;"><tbody style="padding: 0px; margin: 0px; border: 0px;"><tr style="padding: 0px; margin: 0px; border: 0px;"><td bgcolor="#fdfddf" style="padding: 0px; margin: 0px; border: 0px; word-wrap: break-word;"><font style="padding: 0px; margin: 0px; border: 0px; color: #990000; font-weight: bold;"><span style="font-family: Arial; font-size: 12pt;">以下是代码片段：</span></font><br style="padding: 0px; margin: 0px; border: 0px;" /><span style="font-family: Arial; font-size: 12pt;">DB2BIN&gt;db2idrop -f insttest</span></td></tr></tbody></table><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　DB20000I DB2IDROP命令成功完成。</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　DB2BIN&gt;</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　察看实例配置文件</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　--默认</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><table border="0" cellspacing="0" cellpadding="6" width="95%" align="center" style="padding: 0px; margin: 0px; border-color: #cccccc; color: #333333; font-family: Arial, 宋体; font-size: 14px; line-height: 25.200000762939453px; text-align: start; background-color: #eef3f8; table-layout: fixed;"><tbody style="padding: 0px; margin: 0px; border: 0px;"><tr style="padding: 0px; margin: 0px; border: 0px;"><td bgcolor="#fdfddf" style="padding: 0px; margin: 0px; border: 0px; word-wrap: break-word;"><font style="padding: 0px; margin: 0px; border: 0px; color: #990000; font-weight: bold;"><span style="font-family: Arial; font-size: 12pt;">以下是代码片段：</span></font><br style="padding: 0px; margin: 0px; border: 0px;" /><span style="font-family: Arial; font-size: 12pt;">DB2 GET DBM CFG</span></td></tr></tbody></table><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　--分屏显示</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><table border="0" cellspacing="0" cellpadding="6" width="95%" align="center" style="padding: 0px; margin: 0px; border-color: #cccccc; color: #333333; font-family: Arial, 宋体; font-size: 14px; line-height: 25.200000762939453px; text-align: start; background-color: #eef3f8; table-layout: fixed;"><tbody style="padding: 0px; margin: 0px; border: 0px;"><tr style="padding: 0px; margin: 0px; border: 0px;"><td bgcolor="#fdfddf" style="padding: 0px; margin: 0px; border: 0px; word-wrap: break-word;"><font style="padding: 0px; margin: 0px; border: 0px; color: #990000; font-weight: bold;"><span style="font-family: Arial; font-size: 12pt;">以下是代码片段：</span></font><br style="padding: 0px; margin: 0px; border: 0px;" /><span style="font-family: Arial; font-size: 12pt;">DB2 GET DBM CFG | More</span></td></tr></tbody></table><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><span style="font-family: Arial; font-size: 12pt;">　　--将显示结果存入 cfg.out 文件中</span></p><p style="padding: 20px 0px 0px; margin: 0px; border: 0px; clear: both; color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"></p><table border="0" cellspacing="0" cellpadding="6" width="95%" align="center" style="padding: 0px; margin: 0px; border-color: #cccccc; color: #333333; font-family: Arial, 宋体; font-size: 14px; line-height: 25.200000762939453px; text-align: start; background-color: #eef3f8; table-layout: fixed;"><tbody style="padding: 0px; margin: 0px; border: 0px;"><tr style="padding: 0px; margin: 0px; border: 0px;"><td bgcolor="#fdfddf" style="padding: 0px; margin: 0px; border: 0px; word-wrap: break-word;"><font style="padding: 0px; margin: 0px; border: 0px; color: #990000; font-weight: bold;"><span style="font-family: Arial; font-size: 12pt;">以下是代码片段：</span></font><br style="padding: 0px; margin: 0px; border: 0px;" /><span style="font-family: Arial; font-size: 12pt;">DB2 GET DBM CFG &gt; cfg.out</span></td></tr></tbody></table><span style="font-family: 宋体; line-height: 24px; background-color: #ffffff;">　<br /></span><span style="font-family: Arial; line-height: 24px; background-color: #ffffff; font-size: 12pt;">接下来 给位屌丝DB就要创建数据库了 &nbsp;记住有2种方式创建 第一种 就是用control center<br /><br /></span><span style="font-family: Arial; line-height: 24px; background-color: #ffffff; font-size: 12pt;">如下所示，在创建数据库时要考虑几个因素。有几种创建数据库的方法。可以使用从 Control Center 调用的 Create Database 向导，它会引导用户分步创建数据库。如果您了解实际的 Create Database 命令的话，还可以从 DB2 Command Window、Command Editor 或命令行直接发出命令。<br /></span><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　在这个示例中，从 DB2 First Steps Launch 面板的 Create Database 向导：</span><br /><br /><span style="font-family: Arial; font-size: 12pt;">　　1、启动 DB2 Control Center。点击 Start &gt; All</span>&nbsp;<a href="http://pr.knowsky.com/" style="text-decoration: initial; color: black; line-height: 12pt;"><span style="font-family: Arial; font-size: 12pt;">PR</span></a><span style="font-family: Arial; font-size: 12pt;">ograms &gt; IBM DB2 &gt; General Administration Tools 并选择 Control Center。当提示选择 Control Center 视图时，点击 OK 选择默认视图(Advanced)。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　2、点击 All Databases(如图 5 所示)，然后点击 Create New Database。Create Your Own Database 向导打开。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　 从 Control Center 创建新数据库</span></p><span style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><br /></span><img src="http://www.knowsky.com/img2005/3ba2833nji15.jpg" alt="从 Control Center 创建新数据库" /><br /><br /><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">在 Create Your Own Database 向导中，指定数据库名和数据库目录的位置。输入 HelloWld 作为数据库名。指定 C:\ 作为默认路径。输入 hwld 作为数据库别名。在 Comment 字段中输入任何描述性的注释。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　4、选中 Enable Database for&nbsp;</span><a href="http://www.knowsky.com/xml.asp" style="text-decoration: initial; color: black; line-height: 12pt;"><span style="font-family: Arial; font-size: 12pt;">xml</span></a><span style="font-family: Arial; font-size: 12pt;">。XML 列只能在 UTF-8 代码集(Unicode)数据库中使用。所以要在数据库中使用 XML，就必须创建 Unicode 数据库。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　5、不需要指定任何其他数据库选项，所以选择 Summary 面板，然后点击 Show Command 来查看创建这个数据库所用的 DB2 命令。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　6、因为在这个数据库中启用了 XML，所以使用 CODESET UTF-8。点击 Close。如果想将命令保存到文件中，供以后参考或重用，那么点击 Save 而不是 Close。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　7、在 Create New Database 窗口中，点击 Finish 并等待向导完成操作。</span></p><br /><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">在 DB2 创建数据库时，它还创建以下东西：</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　1、在指定的驱动器或路径上创建必要的数据库目录</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　2、创建一组默认的表空间，包括 SYSCAT、TEMPORARY 和 USER 表空间</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　3、在编目表空间中创建一组系统编目表和视图</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　4、创建数据库配置(DB CFG)文件并设置默认值</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　5、为数据库恢复日志文件创建空间并分配它</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　6、为数据库(如 CLI)和命令行处理器创建的几个应用程序</span></p><br /><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;">　<strong style="font-family: Arial; font-size: 12pt;">使用 DB2 Control Center 检查创建的数据库</strong></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　在 Control Center 左边的面板中，找到并展开 All Systems 和 All Databases。看看是否能够找到刚才创建的 HELLOWLD 数据库。All Systems 提供了数据库对象视图，这些对象依次根据机器、实例和数据库进行分组。在这个机器上只有一个实例，DB2。All Databases 提供了这个机器上的所有数据库的快速查看。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　图 6. 查看新数据库</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;">　　<img height="432" alt="查看新数据库" src="http://www.knowsky.com/img2005/5c0745z87wc9.jpg" width="445" /></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　如果您了解创建数据库所用的 DB2 命令，那么可以使用在前面的 Create New Database 向导窗口中保存的 CREATE DATABASE 命令并根据需要进行修改，然后从 DB2 命令行处理器发出 CREATE DATABASE 命令来创建数据库。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　选择 Start &gt; Run，输入 db2cmd 并按 Enter。打开 DB2 命令行处理器窗口。要想获得 create database 命令的帮助，可以在命令行窗口中输入 db2 ? create database。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　输入 db2 CREATE DATABASE MYTESTDB ON C:。在命令成功完成之后，点击 Control Center 主菜单中的 Selected 并点击 Refresh。然后看看是否能够在 Control Center 中找到新的数据库 MYTESTDB。</span></p><p style="font-family: 宋体; line-height: 24px; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">　　在 DB2 命令窗口中输入命令 db2 LIST DATABASE DIRECTORY。应该会看到 HELLOWLD 和 MYTESTDB 数据库的数据库项。</span><br /><span style="font-family: Arial; font-size: 12pt;">第二种 用命令创建；</span><br /></p><pre style="white-space: pre-wrap; line-height: normal; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">db2 CREATE DATABASE diaosi ON C: USING CODESET UTF8 TERRITORY CN COLLATE USING SYSTEM
</span></pre><div><span style="color: #454545; font-family: Arial; background-color: #ffffff; font-size: 12pt;">territory cn 是数据库的语言环境 &nbsp;&nbsp;</span><pre style="white-space: pre-wrap; line-height: normal; background-color: #ffffff;"><span style="font-family: Arial; font-size: 12pt;">USING CODESET UTF8 指的是数据库用utf8字符 </span></pre><h3><span style="font-size: 12pt; font-family: Arial;">为DB2数据库创建新用户帐户并为其分配特定特权</span>&nbsp;&nbsp;<br /><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; font-weight: normal; letter-spacing: 2px; background-color: #f7fcff;"><span style="font-family: Arial; font-size: 12pt;">目标</span></p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; font-weight: normal; letter-spacing: 2px; background-color: #f7fcff;"><span style="font-family: Arial; font-size: 12pt;">到目前为止，一直使用实例管理员帐户（SYSADM）来执行所有数据库命令。这个帐户对所有实用程序、数据和数据库对象具有完全访问权。因此，为了避免无意或有意的数据损失，必须要保护这个帐户。在大多数情况下，需要创建不同的用户和/或组，并授予有限的权限集。在本次实验中，将创建一个新的用户帐户，然后为它分配特定的特权。</span></p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; font-weight: normal; letter-spacing: 2px; background-color: #f7fcff;"><span style="font-family: Arial; font-size: 12pt;">步骤</span></p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; font-weight: normal; letter-spacing: 2px; background-color: #f7fcff;"><span style="font-family: Arial; font-size: 12pt;">1.通过控制面板打开&#8220;管理&#8221;菜单项，打开&#8220;计算机管理&#8221;控制台。</span></p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; font-weight: normal; letter-spacing: 2px; background-color: #f7fcff;"><span style="font-family: Arial; font-size: 12pt;">2.在窗口左边的面板中，展开&#8220;系统工具&#8221;，然后展开&#8220;本地用户和组&#8221;文件夹。右击 &#8220;用户&#8221;文件夹并选择&#8220;新建用户&#8221;菜单项。</span></p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; font-weight: normal; letter-spacing: 2px; background-color: #f7fcff;"><br /><span style="font-family: Arial; font-size: 12pt;">图 1. 打开计算机管理中用户管理</span></p><br /></h3><img src="http://www.ibm.com/developerworks/cn/db2/library/techarticles/dm-0806expressc8/001.jpg" alt="打开计算机管理中用户管理" /><br /><div><br /><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">3.在&#8220;用户&#8221;对话框中，输入以下信息（另外参见下图）。在&#8220;用户名&#8221;框中，输入 customer。在&#8220;全名&#8221;框中，输入 Customer1。在&#8220;描述&#8221;框中，输入 A typical bookstore customer。在 &#8220;密码&#8221; 和 &#8220;确认密码&#8221; 框中，输入 ibmdb2admin。取消 &#8220;用户下次登录时须修改密码&#8221;选项。最后，单击&#8220;创建&#8221;按钮创建新用户。</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><br />图 2. 创建一个新用户</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><img height="364" alt="创建一个新用户" src="http://www.ibm.com/developerworks/cn/db2/library/techarticles/dm-0806expressc8/002.jpg" width="512" style="border: 0px; max-width: 100%;" /></p></div></div><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">4.确保使用 Control Center （控制中心） 的高级视图。切换到高级视图的方法是，从 Control Center （控制中心） Tools 菜单中选择 Customize Control Center （控制中心） 菜单项，选择 Advanced （高级） 选项并单击&#8220;确定&#8221;按钮。</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><br />图 3. 打开控制中心高级视图</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><img height="389" alt="打开控制中心高级视图" src="http://www.ibm.com/developerworks/cn/db2/library/techarticles/dm-0806expressc8/003.jpg" width="439" style="border: 0px; max-width: 100%;" />&nbsp;<br /></p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">5.在 Control Center （控制中心） 左边面板中的对象树中，依次展开所有数据库&gt; EXPRESS &gt; Tables。</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">6.将所需的特权授予刚才创建的用户。在 EXPRESS 数据库的表列表中，右键单击 CUSTOMERS 表并选择 &#8220;特权&#8221; 菜单项，这时会显示 &#8220;表特权&#8221; 对话框。</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><br />图 4. 打开特权菜单项</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><img height="490" alt="打开特权菜单项" src="http://www.ibm.com/developerworks/cn/db2/library/techarticles/dm-0806expressc8/004.jpg" width="534" style="border: 0px; max-width: 100%;" />&nbsp;<br /></p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">7.单击&#8220;添加用户&#8221;按钮并选择刚才创建的 customer 用户。单击 &#8220;确定&#8221;按钮关闭 &#8220;添加用户&#8221; 对话框。</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><br />图 5. 给表添加用户</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><img height="490" alt="给表添加用户" src="http://www.ibm.com/developerworks/cn/db2/library/techarticles/dm-0806expressc8/005.jpg" width="533" style="border: 0px; max-width: 100%;" />&nbsp;<br /></p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">8.您会注意到，customer 用户已经添加到用户列表中了，但是还没有分配特权。为了授予这个用户 SELECT、INSERT、UPDATE 和 DELETE 特权，将所有下拉框改为 Yes。因特网客户应该能够查看/添加/更新/删除他们的帐户数据。我们不授予这个用户其他权限，因为他们不需要那些权限。单击 &#8220;确定&#8221; 按钮关闭 &#8220;表特权&#8221; 对话框并接受所做的修改。</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><br />图 6. 授予用户权限</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;"><img height="489" alt="授予用户权限" src="http://www.ibm.com/developerworks/cn/db2/library/techarticles/dm-0806expressc8/006.jpg" width="535" style="border: 0px; max-width: 100%;" />&nbsp;<br /></p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">9.对于 BOOKS 和 SALES 表重复第 6-8 步。对于 BOOKS 表，只授予 SELECT 特权，因为不应该允许客户修改商店的库存数据。对于 SALES 表，只授予 SELECT 和 INSERT 特权。客户不应该有 DELETE 或 UPDATE 特权，因为只有商店职员应该有权修改销售数据。</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">10.使用上面创建的用户 ID 连接数据库。尝试从 CUSTOMERS 表中选择数据，会发生什么情况？尝试删除或更新 SALES 表中的数据，会发生什么情况？</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">在本次实验中，我们只创建了一个用户；但是，实际的应用程序可能包含许多不同类型的用户。请您自己试着创建其他用户并授予他们特权。还可以创建用户组并向组授予特权，这样就不必向每个用户分别授予特权。</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">转帖者注：</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">&nbsp;&nbsp;&nbsp; 创建完新用户后，在使用该新用户身份进行JDBC连接时需要注意SQL语句的写法。比如：当初创建数据库时使用的是Administer用户身份。现在在该数据中增加了用户&#8212;&#8212;customer，那么在使用customer身份连接数据库后的所有SQL语句均要求在表名前增加原数据库表的创建者。</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">例如，SELECT * FROM&nbsp;<font color="#ff0000">Administer.</font>TableName ; （注意红色部分）不能写成SELECT * FROM TableName ，否则会发生</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">42704错误：</p><p style="line-height: normal; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Georgia; font-size: 12px; letter-spacing: 2px; background-color: #f7fcff;">SQLException information<br />Error msg: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=ADMIN.CONTACT, DRIVER=3.50.152<br />SQLSTATE: 42704<br />Error code: -204<br />com.ibm.db2.jcc.b.nm: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=ADMIN.CONTACT, DRIVER=3.50.152<br />at com.ibm.db2.jcc.b.wc.a(wc.java:579)<br />at com.ibm.db2.jcc.b.wc.a(wc.java:57)<br />at com.ibm.db2.jcc.b.wc.a(wc.java:126)<br />at com.ibm.db2.jcc.b.tk.c(tk.java:1901)<br />at com.ibm.db2.jcc.b.tk.d(tk.java:1889)<br />at com.ibm.db2.jcc.b.tk.a(tk.java:1416)<br />at com.ibm.db2.jcc.t4.db.g(db.java:138)<br />at com.ibm.db2.jcc.t4.db.a(db.java:38)<br />at com.ibm.db2.jcc.t4.t.a(t.java:32)<br />at com.ibm.db2.jcc.t4.sb.h(sb.java:141)<br />at com.ibm.db2.jcc.b.tk.N(tk.java:1387)<br />at com.ibm.db2.jcc.b.tk.a(tk.java:2215)<br />at com.ibm.db2.jcc.b.tk.a(tk.java:557)<br />at com.ibm.db2.jcc.b.tk.executeQuery(tk.java:541)<br />at com.EzJava.main(EzJava.java:45)<br />Error msg: DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-204;42704;ADMIN.CONTACT, DRIVER=3.50.152<br />SQLSTATE: 56098<br />Error code: -727<br />com.ibm.db2.jcc.b.SqlException: DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-204;42704;ADMIN.CONTACT, DRIVER=3.50.152<br />at com.ibm.db2.jcc.b.wc.a(wc.java:55)<br />at com.ibm.db2.jcc.b.wc.a(wc.java:126)<br />at com.ibm.db2.jcc.b.tk.c(tk.java:1901)<br />at com.ibm.db2.jcc.b.tk.a(tk.java:1443)<br />at com.ibm.db2.jcc.t4.db.n(db.java:739)<br />at com.ibm.db2.jcc.t4.db.i(db.java:257)<br />at com.ibm.db2.jcc.t4.db.c(db.java:52)<br />at com.ibm.db2.jcc.t4.t.c(t.java:44)<br />at com.ibm.db2.jcc.t4.sb.i(sb.java:153)<br />at com.ibm.db2.jcc.b.tk.P(tk.java:1438)<br />at com.ibm.db2.jcc.b.tk.a(tk.java:2217)<br />at com.ibm.db2.jcc.b.tk.a(tk.java:557)<br />at com.ibm.db2.jcc.b.tk.executeQuery(tk.java:541)<br />at com.EzJava.main(EzJava.java:45)</p><span style="color: #333333; font-family: Arial, 宋体; line-height: 25.200000762939453px; background-color: #eef3f8;"><br /><br /></span><img src ="http://www.blogjava.net/qileilove/aggbug/392514.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2012-12-05 18:30 <a href="http://www.blogjava.net/qileilove/archive/2012/12/05/392514.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟屌丝一起学习 DB2 第一课 安装DB2</title><link>http://www.blogjava.net/qileilove/archive/2012/12/05/392509.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 05 Dec 2012 09:16:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2012/12/05/392509.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/392509.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2012/12/05/392509.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/392509.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/392509.html</trackback:ping><description><![CDATA[<span style="color: #454545; font-family: Tahoma, Helvetica, Arial, STHeiti; background-color: #ffffff;">如果您没有DB2的安装软件，那么您可以到IBM的官方网站上下载免费试用版，唉 苦逼的屌丝 只能用 免费版 &nbsp;你也可以选择Express-C 版本 网址如下：</span><a target="_blank" href="http://www-900.ibm.com/cn/software/db2/" style="color: #3fa7cb; font-family: Tahoma, Helvetica, Arial, STHeiti; background-color: #ffffff;">www-900.ibm.com/cn/software/db2/</a>&nbsp;或者度娘 自己找<br /><p style="margin: 0px; padding: 0px; color: #454545; font-family: Tahoma, Helvetica, Arial, STHeiti; background-color: #ffffff;">获得的安装文件是一个压缩包：</p><div><img src="http://hiphotos.baidu.com/yidragon88xx/pic/item/726bb3d1a29291a8a1ec9c62.jpg" alt="" /><br /><br /><span style="color: #454545; font-family: Tahoma, Helvetica, Arial, STHeiti; background-color: #ffffff;">DB2的安装1、解压DB2安装压缩包</span><p style="margin: 0px; padding: 0px; color: #454545; font-family: Tahoma, Helvetica, Arial, STHeiti; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 解压获得的DB2安装压缩包：<br /><img src="http://hiphotos.baidu.com/yidragon88xx/pic/item/bc220cc5514081ec38db496a.jpg" alt="" /><br /><br /><br /></p><p style="margin: 0px; padding: 0px;">图3</p>2、安装DB2 V8.2<p style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 双击解压后安装文件目录中的&#8220;setup.exe&#8221;文件，开始安装<br /><br /><img src="http://hiphotos.baidu.com/yidragon88xx/pic/item/18bb4153febc72290df3e377.jpg" alt="" /><br /><br /><br /></p><p style="margin: 0px; padding: 0px;">图4</p><p style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 第一步：首先进入安装界面：<br /><br />唉 终于苦逼的进来了 &nbsp;<br /><img src="http://hiphotos.baidu.com/yidragon88xx/pic/item/9c5cd0e89d9e2118b90e2d70.jpg" alt="" /><br /><br /></p><p style="margin: 0px; padding: 0px;">后续安装步骤请参见------&gt;图解：IBM DB2 安装完整过程 ( 二 )</p><p style="margin: 0px; padding: 0px;">将鼠标移动到安装界面不同项，会提示您不同的信息：</p><p style="margin: 0px; padding: 0px;">&nbsp;安装先决条件：显示安装DB2的软硬件需求，先决条件和安装说明。<br />各种数据库 很卡 &nbsp;还是mysql好些。。小点也实用<br /></p><img src="http://hiphotos.baidu.com/yidragon88xx/pic/item/27360bb57d162e548ad4b214.jpg" alt="" /><br /><br />发行说明：显示本产品的最新信息，包括与本产品相关的书籍的自述文件。<br /><img src="http://hiphotos.baidu.com/yidragon88xx/pic/item/3cb931ff58dbbc165d600817.jpg" alt="" /><br />安装产品：展示可安装的产品列表，可以从列表中进行选择<br /><br /><img src="http://hiphotos.baidu.com/yidragon88xx/pic/item/a2576150ca19873f367abe11.jpg" alt="" /><br /><br /><br /><p style="margin: 0px; padding: 0px;">退出安装：关闭此窗口。</p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/409650ca38ddb7da52664f1e.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /></p><p style="margin: 0px; padding: 0px;"><br /></p><p style="margin: 0px; padding: 0px;">第二步：点击&#8220;安装产品&#8221;，进入选择安装产品界面。<br />反正各种用着不习惯 ，最坑爹的是 找不到顺手的编辑器<br /></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/69bc2637b0d778160a55a9ed.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /></p><p style="margin: 0px; padding: 0px;">图10</p><p style="margin: 0px; padding: 0px;">我们的演示版本只有一个可选项，即：DB2 UDB企业服务器版。选中此项。</p><p style="margin: 0px; padding: 0px;">点击&#8220;下一步&#8221;进入下一步安装。<br /></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/b99f2c1e9a22962d304e15ef.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" />图11</p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;">第三步：安装程序进入&#8220;欢迎使用DB2安装向导&#8221;界面。 点击&#8220;下一步&#8221;。</p><p>&nbsp;</p><p>&nbsp;</p><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/806f46dc3258ac135982ddf5.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /><p style="margin: 0px; padding: 0px;">第四步：安装进入&#8220;许可证协议&#8221;界面，选择&#8220;我接受许可证协议中的全部条款&#8221;，否则，安装程序将被终止。点击&#8220;下一步&#8221;。</p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/2bbfeb866ca0340dc75cc301.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /><br /></p><p style="margin: 0px; padding: 0px;"><br /></p><p style="margin: 0px; padding: 0px;">第五步：安装进入&#8220;选择安装类型&#8221;界面<br />&nbsp;典型安装：安装程序按照缺省的配置进行安装，您可以在附加功能一栏中添加如&#8220;数据仓库&#8221;或&#8220;卫星管理功能&#8221;的功能。对于大多数的开发环境，选择&#8220;典型安装&#8221;就可以了。</p><p style="margin: 0px; padding: 0px;">压缩安装：这个类型只是安装DB2最基本的功能部件和功能，执行最小的配置。</p><p style="margin: 0px; padding: 0px;">定制安装：您可以自己决定安装什么功能和功能部件，但是，这个类型要求您对DB2的功能部件和设置都比较了解。<br /><br /></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/5d44bf075a6e0b5c03088114.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /></p><p style="margin: 0px; padding: 0px;">第六步：安装程序进入&#8220;选择安装操作&#8221;界面</p><p style="margin: 0px; padding: 0px;">&#168;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 第一项：是否在计算机上安装DB2 企业服务器版本，这个必须被选中。</p><p style="margin: 0px; padding: 0px;">&#168; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 第二项：是否将您对在安装过程中对DB2的设置保存到响应文件中，保存后的响应可以在下一次安装DB2时使用，这个选项对于局域网环境下大批量安装DB2会省去很多重复劳动。我们这里不选中它。点击&#8220;下一步&#8221;。</p><p>&nbsp;</p><p style="margin: 0px; padding: 0px;">我们这里选择&#8220;典型安装&#8221;，点击&#8220;下一步&#8221;。<br /></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/6342ddf2b0ce79ec0a46e01d.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /></p><p style="margin: 0px; padding: 0px;">第七步：安装进入&#8220;选择安装文件夹&#8221;界面</p><p style="margin: 0px; padding: 0px;">驱动器：是您想要将DB2安装的目的磁盘，旁边有安装的必需空间，点击&#8220;磁盘空间&#8221;可以查看所选的驱动器的剩余空间是否足够。建议您不要安装到C盘，因为重新安装操作系统时C盘的数据将丢失。这里我们选择D盘。</p><p style="margin: 0px; padding: 0px;">目录：是在您选择的驱动器上安装DB2的路径，点击&#8220;更改&#8221;可以更改路径。点击&#8220;下一步&#8221;。<br /><br /></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/576fd8f6f3259a05720eec88.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /><br /></p><p style="margin: 0px; padding: 0px;">第九步：安装进入&#8220;设置管理联系人列表&#8221;界面</p><p style="margin: 0px; padding: 0px;">&#168;管理联系人列表位置：将管理联系人列表创建的位置，有本地和远程两种。本地就是在本系统中创建；远程就是将列表保存在另一个DB2服务器上。</p><p style="margin: 0px; padding: 0px;">&#168;通知SMTP服务器：此处服务器是接收向管理联系人发送通知的服务器，对于开发环境来说SMTP服务器一般无需设置。点击&#8220;下一步&#8221;。</p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/1b37d309328a08f662d98697.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /></p><p style="margin: 0px; padding: 0px;"><br /></p><p style="margin: 0px; padding: 0px;">第十步：安装进入一个警告界面</p><p style="margin: 0px; padding: 0px;">这里是因为没有指定SMTP服务器，由于我们安装的是开发环境，这个警告可以忽略，点击&#8220;确定&#8221;继续。</p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/5ba1ff72bc55b13b8701b092.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /></p><p style="margin: 0px; padding: 0px;"><br /></p><p style="margin: 0px; padding: 0px;">第十一步：安装进入&#8220;配置DB2实例&#8221;界面</p><p style="margin: 0px; padding: 0px;">DB2实例为执行DB2命令和SQL语句提供了一个逻辑的上下文环境，一个DB2实例下可以创建多个数据库，缺省情况下，系统会创建一个名叫&#8221;DB2&#8221;的实例，点击&#8220;下一步&#8221;。</p><p style="margin: 0px; padding: 0px;"></p><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/404308f8a2a8627e252df293.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"><br /></p><p style="margin: 0px; padding: 0px;">第十二步：安装进入&#8220;准备DB2 工具目录&#8221;界面</p><p style="margin: 0px; padding: 0px;">DB2 工具目录可以用来做什么呢？举个例子，在生产环境下，我们常常需要在系统运行过程中对数据库的性能进行监控，DB2性能诊断工具常常将监控结果存放在工具目录数据库中的，供管理员后续统计分析使用。由于我们部署的是开发环境，因此这个选项不需要选择，直接点击&#8220;下一步&#8221;。</p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/2a8b4e3c104dd327bba16762.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /><br /></p><p style="margin: 0px; padding: 0px;"><br /></p><p style="margin: 0px; padding: 0px;">第十三步：安装进入&#8220;为健康监视器通知指定联系人&#8221;界面</p><p style="margin: 0px; padding: 0px;">对于生产环境来说，&#8220;健康监视器&#8221;提供了在数据库系统出现异常情况时通知管理员的功能，由于我们安装的是开发环境，这个选项无需设置，我们选择将任务延迟到完成安装后进行。点击&#8220;下一步&#8221;</p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/b84d9d092b9a1fb20b7b8275.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /></p><p style="margin: 0px; padding: 0px;"><br /></p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;">第十四步：安装进入&#8220;对DB2对象启用操作系统安全性&#8221;界面</p><p style="margin: 0px; padding: 0px;">您可以选择是否选择启用操作系统安全性，选择&#8220;是&#8221;，点击&#8220;下一步&#8221;</p><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/a84d9b91dd9e71aaa877a476.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /><br /><br /><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;">第十五步：进入&#8220;开始复制文件&#8221;界面</p><p style="margin: 0px; padding: 0px;">到此，安装向导所需要的配置信息基本设置完成。如果您要查看或更改参数设置，请单击上一步，如果对设置感到满意，点击&#8220;安装&#8221;开始安装。</p><p style="margin: 0px; padding: 0px;"></p><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/b84d9d092b981fb20b7b8277.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"><br /></p><p style="margin: 0px; padding: 0px;">第十六步：系统进入安装过程，DB2开始复制文件并进行系统参数设置，这个过程可能会持续几分钟。</p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/e768ba6163ac8563eaf8f870.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /><br /></p><p style="margin: 0px; padding: 0px;"><br /></p><p style="margin: 0px; padding: 0px;">第十七步：安装文件复制完成后，系统安装进入&#8220;安装完成&#8221;界面，点击&#8220;完成&#8221;</p><p style="margin: 0px; padding: 0px;"></p><p style="margin: 0px; padding: 0px;"><img small="0" src="http://hiphotos.baidu.com/yidragon88xx/pic/item/c00f7c4ac2b271d783025c71.jpg" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;" alt="" /></p><p style="margin: 0px; padding: 0px;">在control center中建库</p><br /><p>&nbsp;</p><br /><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p></div><img src ="http://www.blogjava.net/qileilove/aggbug/392509.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2012-12-05 17:16 <a href="http://www.blogjava.net/qileilove/archive/2012/12/05/392509.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>