﻿<?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-&lt;p align="left" style="font-family:华文行楷; font-size:20px; color:#FF0000"&gt;心砚手记&lt;/p&gt;-文章分类-DB</title><link>http://www.blogjava.net/zqbchina/category/23801.html</link><description>&lt;p align="right" style="font-family:华文新魏; font-size:14px; color:#660000"&gt;技术知识是基础，技术精通是目标，体系思想是境界&lt;/p&gt;</description><language>zh-cn</language><lastBuildDate>Wed, 31 Jul 2013 06:16:06 GMT</lastBuildDate><pubDate>Wed, 31 Jul 2013 06:16:06 GMT</pubDate><ttl>60</ttl><item><title>OVER(PARTITION BY)函数用法</title><link>http://www.blogjava.net/zqbchina/articles/402194.html</link><dc:creator>心砚</dc:creator><author>心砚</author><pubDate>Wed, 31 Jul 2013 04:23:00 GMT</pubDate><guid>http://www.blogjava.net/zqbchina/articles/402194.html</guid><description><![CDATA[<div class="postTitle" style="box-sizing: border-box; margin-bottom: 10px; font-size: 14px; font-family: Verdana, Arial, Helvetica, sans-serif; font-variant: normal; white-space: normal; text-transform: none; word-spacing: 0px; font-weight: bold; color: rgb(75,75,75); font-style: normal; orphans: 2; widows: 2; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
<h1 style="box-sizing: border-box; font-size: 14px; font-weight: bold; color: rgb(102,102,102); text-align: left; margin: 10px 0px"><span style="box-sizing: border-box; font-size: 24pt">转自： <a href="http://www.cnblogs.com/lanzi/archive/2010/10/26/1861338.html"><br /><br />http://www.cnblogs.com/lanzi/archive/2010/10/26/1861338.html</a><br /><br /><br />OVER(PARTITION BY)函数介绍</span></h1></div>
<div id="cnblogs_post_body" style="box-sizing: border-box; white-space: normal; text-transform: none; word-break: normal !important; word-spacing: 0px; color: rgb(75,75,75); font: 13px/20px Verdana, Arial, Helvetica, sans-serif; orphans: 2; widows: 2; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
<div style="box-sizing: border-box">开窗函数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp; Oracle从8.1.6开始提供分析函数，分析函数用于计算基于组的某种聚合值，它和聚合函数的不同之处是：对于每个组返回多行，而聚合函数对于每个组只返回一行。</div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 开窗函数指定了分析函数工作的数据窗口大小，这个数据窗口大小可能会随着行的变化而变化，举例如下：<br style="box-sizing: border-box" /><span style="box-sizing: border-box; font-size: 18pt">1：over后的写法：<span class="Apple-converted-space">&nbsp;</span></span>&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />&nbsp;&nbsp; over（order by salary） 按照salary排序进行累计，order by是个默认的开窗函数<br style="box-sizing: border-box" />&nbsp;&nbsp; over（partition by deptno）按照部门分区<br style="box-sizing: border-box" /></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<div style="box-sizing: border-box">&nbsp;&nbsp; over（partition by deptno order by salary）</div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><span style="box-sizing: border-box; font-size: 18pt">2：</span><span style="box-sizing: border-box; font-size: 18pt">开窗的窗口范围</span><span style="box-sizing: border-box; font-size: 18pt">：</span><br style="box-sizing: border-box" /><span style="box-sizing: border-box; font-size: 14pt">over（order by salary<span class="Apple-converted-space">&nbsp;</span></span><span style="box-sizing: border-box; font-size: 14pt; background-color: rgb(255,255,0)">range</span><span style="box-sizing: border-box; font-size: 14pt"><span class="Apple-converted-space">&nbsp;</span>between 5 preceding and 5 following）：窗口范围为当前行数据幅度减5加5后的范围内的。</span></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">举例：</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<div style="box-sizing: border-box">
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><u style="box-sizing: border-box"><span style="box-sizing: border-box; color: red">--</span><span style="box-sizing: border-box; color: red">sum(s)over(order by s range between 2 preceding and 2 following)<span class="Apple-converted-space">&nbsp;</span></span><span style="box-sizing: border-box; color: red">表示加2或2的范围内的求和</span></u><br style="box-sizing: border-box" /></p>&nbsp;select name,class,s, sum(s)over(order by s range between 2 preceding and 2 following) mm from t2<br style="box-sizing: border-box" />adf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 45&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 45&nbsp; --45加2减2即43到47，但是s在这个范围内只有45<br style="box-sizing: border-box" />asdf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 55&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 55<br style="box-sizing: border-box" />cfe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 74&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 74<br style="box-sizing: border-box" />3dd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 78&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 158 --78在76到80范围内有78，80，求和得158<br style="box-sizing: border-box" />fda&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 80&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 158<br style="box-sizing: border-box" />gds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92<br style="box-sizing: border-box" />ffd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 190<br style="box-sizing: border-box" />dss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 190<br style="box-sizing: border-box" />ddd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 198<br style="box-sizing: border-box" />
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">gf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 198</p></div>&nbsp; 
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<div style="box-sizing: border-box"><span style="box-sizing: border-box; font-size: 14pt">over（order by salary</span><span style="box-sizing: border-box"><span class="Apple-converted-space">&nbsp;</span></span><span style="box-sizing: border-box; font-size: 14pt; background-color: rgb(255,255,0)">rows<span class="Apple-converted-space">&nbsp;</span></span><span style="box-sizing: border-box; font-size: 14pt">between 5 preceding and 5 following）：窗口范围为当前行前后各移动5行。</span></div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">举例：</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<div style="box-sizing: border-box"><u style="box-sizing: border-box"><span style="box-sizing: border-box; color: red">--sum(s)over(order by s rows between 2 preceding and 2 following)</span></u>表示在上下两行之间的范围内<br style="box-sizing: border-box" />select name,class,s, sum(s)over(order by s rows between 2 preceding and 2 following) mm from t2<br style="box-sizing: border-box" />adf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 45&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 174&nbsp; （45+55+74=174）<br style="box-sizing: border-box" />asdf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 55&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 252&nbsp;&nbsp; （45+55+74+78=252）<br style="box-sizing: border-box" />cfe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 74&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 332&nbsp;&nbsp;&nbsp; （74+55+45+78+80=332）<br style="box-sizing: border-box" />3dd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 78&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 379&nbsp;&nbsp;&nbsp; （78+74+55+80+92=379）<br style="box-sizing: border-box" />fda&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 80&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 419<br style="box-sizing: border-box" />gds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 440<br style="box-sizing: border-box" />ffd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 461<br style="box-sizing: border-box" />dss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 480<br style="box-sizing: border-box" />ddd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 388<br style="box-sizing: border-box" />gf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 293</div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<div style="box-sizing: border-box">over（order by salary<span class="Apple-converted-space">&nbsp;</span><span style="box-sizing: border-box; background-color: yellow">range</span><span class="Apple-converted-space">&nbsp;</span>between unbounded preceding and unbounded following）或者 
<div style="box-sizing: border-box">over（order by salary<span class="Apple-converted-space">&nbsp;</span><span style="box-sizing: border-box; background-color: yellow">rows</span><span class="Apple-converted-space">&nbsp;</span>between unbounded preceding and unbounded following）：窗口不做限制</div></div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><span style="box-sizing: border-box; font-size: 18pt">3、与over函数结合的几个函数介绍</span><br style="box-sizing: border-box" /></p>
<div style="box-sizing: border-box"><strong style="box-sizing: border-box; font-size: 14pt">row_number()over()、rank()over()和dense_rank()over()函数的使用</strong></div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">下面以班级成绩表t2来说明其应用</p>t2表信息如下：<br style="box-sizing: border-box" />cfe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 74<br style="box-sizing: border-box" />dss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95<br style="box-sizing: border-box" />ffd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95<br style="box-sizing: border-box" />fda&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 80<br style="box-sizing: border-box" />gds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92<br style="box-sizing: border-box" />gf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99<br style="box-sizing: border-box" />ddd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99<br style="box-sizing: border-box" />adf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 45<br style="box-sizing: border-box" />asdf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 55<br style="box-sizing: border-box" />3dd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 78<br style="box-sizing: border-box" /><br style="box-sizing: border-box" />select * from&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; select name,class,s,rank()over(partition by class order by s desc) mm from t2<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; where mm=1；<br style="box-sizing: border-box" />得到的结果是:<br style="box-sizing: border-box" />dss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />ffd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />gds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />gf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />ddd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" /><br style="box-sizing: border-box" />注意：<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; 1.在求第一名成绩的时候，不能用row_number()，因为如果同班有两个并列第一，row_number()只返回一个结果;<br style="box-sizing: border-box" />select * from&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; select name,class,s,row_number()over(partition by class order by s desc) mm from t2<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; where mm=1；<br style="box-sizing: border-box" />1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp; --95有两名但是只显示一个<br style="box-sizing: border-box" />2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 --99有两名但也只显示一个<br style="box-sizing: border-box" /><br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp; 2.rank()和dense_rank()可以将所有的都查找出来：<br style="box-sizing: border-box" />如上可以看到采用rank可以将并列第一名的都查找出来；<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp; rank()和dense_rank()区别：<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp; --rank()是跳跃排序，有两个第二名时接下来就是第四名；<br style="box-sizing: border-box" />select name,class,s,rank()over(partition by class order by s desc) mm from t2<br style="box-sizing: border-box" />dss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />ffd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />fda&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 80&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 --直接就跳到了第三<br style="box-sizing: border-box" />gds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />cfe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 74&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<br style="box-sizing: border-box" />gf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />ddd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />3dd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 78&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<br style="box-sizing: border-box" />asdf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 55&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4<br style="box-sizing: border-box" />adf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 45&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp; --dense_rank()l是连续排序，有两个第二名时仍然跟着第三名<br style="box-sizing: border-box" />select name,class,s,dense_rank()over(partition by class order by s desc) mm from t2<br style="box-sizing: border-box" />dss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />ffd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />fda&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 80&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 --连续排序（仍为2）<br style="box-sizing: border-box" />gds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />cfe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 74&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<br style="box-sizing: border-box" />gf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />ddd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br style="box-sizing: border-box" />3dd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 78&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<br style="box-sizing: border-box" />asdf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 55&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<br style="box-sizing: border-box" />adf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 45&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4<br style="box-sizing: border-box" /><br style="box-sizing: border-box" /><strong style="box-sizing: border-box; font-size: 14pt">--sum()over（）的使用</strong><br style="box-sizing: border-box; font-size: 14pt" />select name,class,s, sum(s)over(partition by class order by s desc) mm from t2 --根据班级进行分数求和<br style="box-sizing: border-box" />dss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 190&nbsp; --由于两个95都是第一名，所以累加时是两个第一名的相加<br style="box-sizing: border-box" />ffd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 190<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />fda&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 80&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 270&nbsp; --第一名加上第二名的<br style="box-sizing: border-box" />gds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 92<br style="box-sizing: border-box" />cfe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 74&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 166<br style="box-sizing: border-box" />gf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 198<br style="box-sizing: border-box" />ddd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 198<br style="box-sizing: border-box" />3dd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 78&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 276<br style="box-sizing: border-box" />asdf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 55&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 331<br style="box-sizing: border-box" />adf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 45&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 376<br style="box-sizing: border-box" /><br style="box-sizing: border-box" />
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><strong style="box-sizing: border-box"><span style="box-sizing: border-box; font-size: 14pt">first_value() over()和last_value() over()的使用 &nbsp;</span></strong></p><img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/first_last1.png" width="982" height="265" /><br style="box-sizing: border-box" />
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><br style="box-sizing: border-box" />--找出这三条电路每条电路的第一条记录类型和最后一条记录类型</p>
<div style="box-sizing: border-box"><em style="box-sizing: border-box">
<div style="box-sizing: border-box">
<div style="box-sizing: border-box">SELECT opr_id,res_type,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first_value(res_type) over(PARTITION BY opr_id<span class="Apple-converted-space">&nbsp;</span><span style="box-sizing: border-box; background-color: yellow">ORDER BY res_type</span>) low,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last_value(res_type) over(PARTITION BY opr_id<span class="Apple-converted-space">&nbsp;</span><span style="box-sizing: border-box; background-color: yellow">ORDER BY res_type<span class="Apple-converted-space">&nbsp;</span></span><strong style="box-sizing: border-box; color: red">rows BETWEEN unbounded preceding AND unbounded following</strong>) high<br style="box-sizing: border-box" />&nbsp; FROM rm_circuit_route<br style="box-sizing: border-box" />WHERE opr_id IN ('000100190000000000021311','000100190000000000021355','000100190000000000021339')<br style="box-sizing: border-box" />&nbsp;ORDER BY opr_id;</div></div></em></div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;<img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/first_last22.png" width="433" height="170" /></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><span style="box-sizing: border-box; color: red">注：</span><em style="box-sizing: border-box; color: red"><em style="box-sizing: border-box">rows BETWEEN unbounded preceding AND unbounded following</em></em><span style="box-sizing: border-box; color: red"><span class="Apple-converted-space">&nbsp;</span>的使用</span><br style="box-sizing: border-box; color: red" /></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">--取last_value时不使用<em style="box-sizing: border-box; color: red"><em style="box-sizing: border-box">rows BETWEEN unbounded preceding AND unbounded following</em></em><em style="box-sizing: border-box"><em style="box-sizing: border-box">的结果</em></em></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<div style="box-sizing: border-box"><em style="box-sizing: border-box"><em style="box-sizing: border-box">
<div style="box-sizing: border-box">SELECT opr_id,res_type,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first_value(res_type) over(PARTITION BY opr_id ORDER BY res_type) low,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last_value(res_type) over(PARTITION BY opr_id ORDER BY res_type) high<br style="box-sizing: border-box" />&nbsp; FROM rm_circuit_route<br style="box-sizing: border-box" />&nbsp;WHERE opr_id IN ('000100190000000000021311','000100190000000000021355','000100190000000000021339')<br style="box-sizing: border-box" />&nbsp;ORDER BY opr_id;</div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">如下图可以看到，如果不使用<em style="box-sizing: border-box"><em style="box-sizing: border-box"></em></em></p>
<div style="box-sizing: border-box"><em style="box-sizing: border-box"><em style="box-sizing: border-box"><em style="box-sizing: border-box; color: red"><em style="box-sizing: border-box">rows BETWEEN unbounded preceding AND unbounded following，</em></em><span style="box-sizing: border-box; color: red"></span><span style="box-sizing: border-box; color: red"><span style="box-sizing: border-box; color: rgb(0,0,0)">取出的last_value由于与res_type进行进行排列，因此取出的电路的最后一行记录的类型就不是按照电路的范围提取了，而是以res_type为范围进行提取了。</span></span><em style="box-sizing: border-box; color: red"><em style="box-sizing: border-box"><span style="box-sizing: border-box"></span></em></em></em></em></div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/first_last3.png" width="439" height="177" /><em style="box-sizing: border-box"><em style="box-sizing: border-box">&nbsp;</em></em></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><em style="box-sizing: border-box"><em style="box-sizing: border-box">&nbsp;</em></em></p></em></em></div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<div style="box-sizing: border-box"><strong style="box-sizing: border-box"><em style="box-sizing: border-box">在first_value和last_value中ignore nulls的使用</em></strong></div>数据如下：<br style="box-sizing: border-box" />
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/fs1.png" width="834" height="136" />&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">取出该电路的第一条记录，加上<strong style="box-sizing: border-box"><em style="box-sizing: border-box">ignore nulls</em></strong><em style="box-sizing: border-box">后，如果第一条是判断的那个字段是空的，则默认取下一条，结果如下所示：</em></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/fl2.png" width="667" height="175" />&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;<img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/fl3.png" width="773" height="213" /></p>
<div style="box-sizing: border-box"><strong style="box-sizing: border-box"><span style="box-sizing: border-box; font-size: 14pt">--lag() over()函数用法</span></strong>（取出前n行数据）<br style="box-sizing: border-box" /><strong style="box-sizing: border-box">lag(expresstion,&lt;offset&gt;,&lt;default&gt;)</strong><br style="box-sizing: border-box" />with a as<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />(select 1 id,'a' name from dual<br style="box-sizing: border-box" />&nbsp;union<br style="box-sizing: border-box" />&nbsp;select 2 id,'b' name from dual<br style="box-sizing: border-box" />&nbsp;union<br style="box-sizing: border-box" />&nbsp;select 3 id,'c' name from dual<br style="box-sizing: border-box" />&nbsp;union<br style="box-sizing: border-box" />&nbsp;select 4 id,'d' name from dual<br style="box-sizing: border-box" />&nbsp;union<br style="box-sizing: border-box" />&nbsp;select 5 id,'e' name from dual<br style="box-sizing: border-box" />)<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />select id,name,<span style="box-sizing: border-box; color: red">lag(id,1,'')over(order by name)<span class="Apple-converted-space">&nbsp;</span></span>from a;<br style="box-sizing: border-box" /><br style="box-sizing: border-box" /><strong style="box-sizing: border-box; font-size: 14pt">--lead() over()函数用法</strong>（取出后N行数据）</div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><strong style="box-sizing: border-box">lead(expresstion,&lt;offset&gt;,&lt;default&gt;)</strong><br style="box-sizing: border-box" />with a as<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />(select 1 id,'a' name from dual<br style="box-sizing: border-box" />&nbsp;union<br style="box-sizing: border-box" />&nbsp;select 2 id,'b' name from dual<br style="box-sizing: border-box" />&nbsp;union<br style="box-sizing: border-box" />&nbsp;select 3 id,'c' name from dual<br style="box-sizing: border-box" />&nbsp;union<br style="box-sizing: border-box" />&nbsp;select 4 id,'d' name from dual<br style="box-sizing: border-box" />&nbsp;union<br style="box-sizing: border-box" />&nbsp;select 5 id,'e' name from dual<br style="box-sizing: border-box" />)<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />select id,name,<span style="box-sizing: border-box; color: red">lead(id,1,'')over(order by name)<span class="Apple-converted-space">&nbsp;</span></span>from a;<br style="box-sizing: border-box" /><br style="box-sizing: border-box" /><strong style="box-sizing: border-box; font-size: 14pt">--ratio_to_report(a)函数用法 Ratio_to_report() 括号中就是分子，over() 括号中就是分母</strong><br style="box-sizing: border-box; font-size: 14pt" />with a as (select 1 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 1 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union&nbsp; all<br style="box-sizing: border-box" />select 1 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 2 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />select 3 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 4 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 4 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 5 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br style="box-sizing: border-box" />select a,<span style="box-sizing: border-box; color: red"><span class="Apple-converted-space">&nbsp;</span>ratio_to_report(a)over(partition by a)<span class="Apple-converted-space">&nbsp;</span></span>b from a<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />order by a;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" /><br style="box-sizing: border-box" />with a as (select 1 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 1 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union&nbsp; all<br style="box-sizing: border-box" />select 1 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 2 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />select 3 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 4 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 4 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 5 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br style="box-sizing: border-box" />select a,<span class="Apple-converted-space">&nbsp;</span><span style="box-sizing: border-box; color: red">ratio_to_report(a)over()</span><span class="Apple-converted-space">&nbsp;</span>b from a<span class="Apple-converted-space">&nbsp;</span><u style="box-sizing: border-box">--分母缺省就是整个占比</u><br style="box-sizing: border-box" />order by a;<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" /><br style="box-sizing: border-box" />with a as (select 1 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 1 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union&nbsp; all<br style="box-sizing: border-box" />select 1 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 2 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" />select 3 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 4 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 4 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union all<br style="box-sizing: border-box" />select 5 a from dual<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br style="box-sizing: border-box" />select a,<span class="Apple-converted-space">&nbsp;</span><span style="box-sizing: border-box; color: red">ratio_to_report(a)over() b from a</span><br style="box-sizing: border-box" /><span style="box-sizing: border-box; color: red">group by a<span class="Apple-converted-space">&nbsp;</span></span>order by a;--分组后的占比</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<div style="box-sizing: border-box"><strong style="box-sizing: border-box; font-size: 14pt">percent_rank用法</strong></div>
<div style="box-sizing: border-box">计算方法：所在组排名序号-1除以该组所有的行数-1，如下所示自己计算的pr1与通过percent_rank函数得到的值是一样的：<br style="box-sizing: border-box" />SELECT a.deptno,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.ename,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.sal,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.r,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b.n,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (a.r-1)/(n-1) pr1,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; percent_rank() over(PARTITION BY a.deptno ORDER BY a.sal) pr2<br style="box-sizing: border-box" />&nbsp; FROM (SELECT deptno,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ename,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sal,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rank() over(PARTITION BY deptno ORDER BY sal) r --计算出在组中的排名序号<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM emp<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ORDER BY deptno, sal) a,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SELECT deptno, COUNT(1) n FROM emp GROUP BY deptno) b --按部门计算每个部门的所有成员数<br style="box-sizing: border-box" />&nbsp;WHERE a.deptno = b.deptno;</div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"><img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/percent_rank.png" width="373" height="260" /><br style="box-sizing: border-box" />&nbsp;</p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<div style="box-sizing: border-box"><strong style="box-sizing: border-box; font-size: 14pt">cume_dist函数</strong></div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<div style="box-sizing: border-box">计算方法：所在组排名序号除以该组所有的行数，但是如果存在并列情况，则需加上并列的个数-1，<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如下所示自己计算的pr1与通过percent_rank函数得到的值是一样的：<br style="box-sizing: border-box" />SELECT a.deptno,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.ename,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.sal,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.r,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b.n,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c.rn,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (a.r + c.rn - 1) / n pr1,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cume_dist() over(PARTITION BY a.deptno ORDER BY a.sal) pr2<br style="box-sizing: border-box" />&nbsp; FROM (SELECT deptno,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ename,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sal,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rank() over(PARTITION BY deptno ORDER BY sal) r<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM emp<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ORDER BY deptno, sal) a,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SELECT deptno, COUNT(1) n FROM emp GROUP BY deptno) b,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SELECT deptno, r, COUNT(1) rn,sal<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM (SELECT deptno,sal,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rank() over(PARTITION BY deptno ORDER BY sal) r<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM emp)<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY deptno, r,sal<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ORDER BY deptno) c --c表就是为了得到每个部门员工工资的一样的个数<br style="box-sizing: border-box" />&nbsp;WHERE a.deptno = b.deptno<br style="box-sizing: border-box" />&nbsp;&nbsp; AND a.deptno = c.deptno(+)<br style="box-sizing: border-box" />&nbsp;&nbsp; AND a.sal = c.sal;</div><img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/cume_dist.png" width="547" height="259" />&nbsp; 
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>&nbsp; 
<div style="box-sizing: border-box"><strong style="box-sizing: border-box; font-size: 14pt">percentile_cont函数</strong></div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<div style="box-sizing: border-box">含义：输入一个百分比（该百分比就是按照percent_rank函数计算的值），返回该百分比位置的平均值<br style="box-sizing: border-box" />如下，输入百分比为0.7，因为0.7介于0.6和0.8之间，因此返回的结果就是0.6对应的sal的1500加上0.8对应的sal的1600平均<br style="box-sizing: border-box" />SELECT ename,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sal,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deptno,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; percentile_cont(0.7) within GROUP(ORDER BY sal) over(PARTITION BY deptno) "Percentile_Cont",<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; percent_rank() over(PARTITION BY deptno ORDER BY sal) "Percent_Rank"<br style="box-sizing: border-box" />&nbsp; FROM emp<br style="box-sizing: border-box" />&nbsp;WHERE deptno IN (30, 60);</div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px">&nbsp;<img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/percentile_cont.png" width="423" height="122" /></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<div style="box-sizing: border-box">若输入的百分比为0.6，则直接0.6对应的sal值，即1500<br style="box-sizing: border-box" />SELECT ename,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sal,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deptno,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; percentile_cont(0.6) within GROUP(ORDER BY sal) over(PARTITION BY deptno) "Percentile_Cont",<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; percent_rank() over(PARTITION BY deptno ORDER BY sal) "Percent_Rank"<br style="box-sizing: border-box" />&nbsp; FROM emp<br style="box-sizing: border-box" />&nbsp;WHERE deptno IN (30, 60);</div><img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/percentile_cont2.png" width="421" height="119" />&nbsp; 
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<div style="box-sizing: border-box"><strong style="box-sizing: border-box; font-size: 14pt">PERCENTILE_DISC函数</strong></div>
<p style="box-sizing: border-box; margin: 10px auto; text-indent: 0px"></p>
<div style="box-sizing: border-box">功能描述：返回一个与输入的分布百分比值相对应的数据值，分布百分比的计算方法见函数CUME_DIST，如果没有正好对应的数据值，就取大于该分布值的下一个值。<br style="box-sizing: border-box" />注意：本函数与PERCENTILE_CONT的区别在找不到对应的分布值时返回的替代值的计算方法不同<br style="box-sizing: border-box" /><br style="box-sizing: border-box" />SAMPLE：下例中0.7的分布值在部门30中没有对应的Cume_Dist值，所以就取下一个分布值0.83333333所对应的SALARY来替代<br style="box-sizing: border-box" /><br style="box-sizing: border-box" />SELECT ename,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sal,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deptno,<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; percentile_disc(0.7) within GROUP(ORDER BY sal) over(PARTITION BY deptno) "Percentile_Disc",<br style="box-sizing: border-box" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cume_dist() over(PARTITION BY deptno ORDER BY sal) "Cume_Dist"<br style="box-sizing: border-box" />&nbsp; FROM emp<br style="box-sizing: border-box" />&nbsp;WHERE deptno IN (30, 60);</div><img style="box-sizing: border-box; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px" alt="" src="http://images.cnblogs.com/cnblogs_com/lanzi/percentile_disc.png" width="443" height="123" />&nbsp;</div>
<p align="left">&nbsp;</p><img src ="http://www.blogjava.net/zqbchina/aggbug/402194.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zqbchina/" target="_blank">心砚</a> 2013-07-31 12:23 <a href="http://www.blogjava.net/zqbchina/articles/402194.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DB2中SQLSTATE=57016 SQLCODE=-668，原因码 "7"的解决</title><link>http://www.blogjava.net/zqbchina/articles/134702.html</link><dc:creator>心砚</dc:creator><author>心砚</author><pubDate>Mon, 06 Aug 2007 06:51:00 GMT</pubDate><guid>http://www.blogjava.net/zqbchina/articles/134702.html</guid><wfw:comment>http://www.blogjava.net/zqbchina/comments/134702.html</wfw:comment><comments>http://www.blogjava.net/zqbchina/articles/134702.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/zqbchina/comments/commentRss/134702.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zqbchina/services/trackbacks/134702.html</trackback:ping><description><![CDATA[<font size="1">对表进行任何操作都不被允许，提示SQLSTATE=57016 SQLCODE=-668 ，原因码 "7"的错误：SQL0668N  Operation not allowed for reason code "7" on table XXX. 解决方法为：执行命令：reorg table XXX；即可。<br />参考原文为：<br />Operation not allowed for reason code reason-code on table table-name.<br />Explanation: Access to table table-name is restricted. The cause is based on the following reason codes reason-code: 7<br />    The table is in the reorg pending state. This can occur after an ALTER TABLE statement containing a REORG-recommended operation.7<br />    Reorganize the table using the REORG TABLE command (note that INPLACE REORG TABLE is not allowed for a table that is in the reorg pending state).<br />其中：<br />   reorg   table   &lt;tablename&gt;   通过重构行来消除“碎片”数据并压缩信息，对表进行重组。<br />   runstats   on   table   &lt;tbschema&gt;.&lt;tbname&gt;   收集表   &lt;tbname&gt;   的统计信息。<br />   reorgchk   on   table   all   确定是否需要对表进行重组，对于对所有表自动执行   runstats   很有用。<br />  &gt;&gt;&gt; reorg   和runstats   都是单个表优化，初始化的命令： <br />           runstats on table administrator.test;<br />           reorg table administrator.test; </font><img src ="http://www.blogjava.net/zqbchina/aggbug/134702.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zqbchina/" target="_blank">心砚</a> 2007-08-06 14:51 <a href="http://www.blogjava.net/zqbchina/articles/134702.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DB2中UDF的SQLSTATE=42884 问题</title><link>http://www.blogjava.net/zqbchina/articles/134678.html</link><dc:creator>心砚</dc:creator><author>心砚</author><pubDate>Mon, 06 Aug 2007 05:07:00 GMT</pubDate><guid>http://www.blogjava.net/zqbchina/articles/134678.html</guid><wfw:comment>http://www.blogjava.net/zqbchina/comments/134678.html</wfw:comment><comments>http://www.blogjava.net/zqbchina/articles/134678.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zqbchina/comments/commentRss/134678.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zqbchina/services/trackbacks/134678.html</trackback:ping><description><![CDATA[<font size="1">写了一个很简单的函数，传入参数character，结果执行报错：SQLSTATE ==&gt;<font color="#cc0033">42884</font> ，将传入参数改为：varchar型就ok了。<br />在一篇chm文章中发现了有这个提示，但也没有给出原因，原文：Use <tt>VARCHAR</tt> types for character string input in UDF definitions.</font><img src ="http://www.blogjava.net/zqbchina/aggbug/134678.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zqbchina/" target="_blank">心砚</a> 2007-08-06 13:07 <a href="http://www.blogjava.net/zqbchina/articles/134678.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DB2中的存储过程和函数</title><link>http://www.blogjava.net/zqbchina/articles/132112.html</link><dc:creator>心砚</dc:creator><author>心砚</author><pubDate>Tue, 24 Jul 2007 09:39:00 GMT</pubDate><guid>http://www.blogjava.net/zqbchina/articles/132112.html</guid><wfw:comment>http://www.blogjava.net/zqbchina/comments/132112.html</wfw:comment><comments>http://www.blogjava.net/zqbchina/articles/132112.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zqbchina/comments/commentRss/132112.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zqbchina/services/trackbacks/132112.html</trackback:ping><description><![CDATA[<font size="1">这个DB2快把人折腾死了，楞是不知道函数和存储过程是怎么写的。今天弄了一个多小时写了一个函数，赶快记下来：<br />DROP FUNCTION myfunction;<br />CREATE FUNCTION myfunction(idvalue int) returns varchar(10)<br />language sql<br />specific myfunction<br />  f:begin <font style="BACKGROUND-COLOR: #0000ff">atomic --注意这个关键字：</font></font>
		<font size="1">
				<font style="BACKGROUND-COLOR: #7fffd4">
						<font style="BACKGROUND-COLOR: #7fffd4">the body of the function is wrapped with <tt><font face="Arial">BEGIN ATOMIC</font></tt></font>
						<br />
				</font>    declare v_id int;<br />    declare v_name char(7);<br />    set (v_id,v_name) = (<br />      select id,name<br />        from test<br />        where id = idvalue);<br />    return v_name||char(v_id);<br />  end f;<br /><br /><br />NND，不知道是我机器环境的问题，还是DB2太变态：在执行table function时，一定要赋予一个别名么？<br />select * from table(mytabfunc2(1))<font style="BACKGROUND-COLOR: #ffff00"><strong> as b --竟然不要都不行！！！</strong></font><br /><br />DB2 江湖黑话：UDF－User-Defined Functions<br />                              LUW－Linux 、Unix、Windows<br /><br /></font><img src ="http://www.blogjava.net/zqbchina/aggbug/132112.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zqbchina/" target="_blank">心砚</a> 2007-07-24 17:39 <a href="http://www.blogjava.net/zqbchina/articles/132112.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DB2常用命令集</title><link>http://www.blogjava.net/zqbchina/articles/131516.html</link><dc:creator>心砚</dc:creator><author>心砚</author><pubDate>Fri, 20 Jul 2007 08:33:00 GMT</pubDate><guid>http://www.blogjava.net/zqbchina/articles/131516.html</guid><wfw:comment>http://www.blogjava.net/zqbchina/comments/131516.html</wfw:comment><comments>http://www.blogjava.net/zqbchina/articles/131516.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zqbchina/comments/commentRss/131516.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zqbchina/services/trackbacks/131516.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: DB2														常用命令集																																																																																						1，																				关闭						db2							...&nbsp;&nbsp;<a href='http://www.blogjava.net/zqbchina/articles/131516.html'>阅读全文</a><img src ="http://www.blogjava.net/zqbchina/aggbug/131516.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zqbchina/" target="_blank">心砚</a> 2007-07-20 16:33 <a href="http://www.blogjava.net/zqbchina/articles/131516.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DB2常用操作</title><link>http://www.blogjava.net/zqbchina/articles/131504.html</link><dc:creator>心砚</dc:creator><author>心砚</author><pubDate>Fri, 20 Jul 2007 07:51:00 GMT</pubDate><guid>http://www.blogjava.net/zqbchina/articles/131504.html</guid><wfw:comment>http://www.blogjava.net/zqbchina/comments/131504.html</wfw:comment><comments>http://www.blogjava.net/zqbchina/articles/131504.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zqbchina/comments/commentRss/131504.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zqbchina/services/trackbacks/131504.html</trackback:ping><description><![CDATA[<p>d:\winnt\system32\drivers\etc\services文件是对机器名到IP地址的解析。<br />d:\winnt\system32\drivers\etc\hosts文件是对端口名到端口号的解析。<br />以上两条上非DB2的，但在DB2中使用到。</p>
		<p>db2admin start 起动DB2管理</p>
		<p>DB2里对一个命令的HELP是:<br />&gt;db2 ? 该命令</p>
		<p>db2 连接到远程数据库<br />第一步建一个结点：<br />&gt;db2 catalog tcpip node 结点名 remote 数据库服务器IP地址 server 端口(50000)<br />第二步建一个到库的联结别名：<br />&gt;db2 catalog db 库名 as 别名 at node 结点名<br />第三步建立联结：<br />&gt;db2 connect to 别名 user 用户名 using 用户密码<br />断开联结：<br />db2 connect reset</p>
		<p>
				<br />db2里需要用到一个系统环境变量：db2codepage， 缺省值是1386，此值非常重要，客户端于数据库端的db2codepage不一样时客户端就无法连上数据库端。</p>
		<p>DB2里一个表的全名是：schema.表名，缺什情况下不同的用户看到的表是不一样的，<br />在程序的sql语句里必需用表的全名(切记)。</p>
		<p>查看有哪些程序在使用该数据库：<br />&gt;db2 list application <br />其结果中有一个字段application-handle在杀死该引用中用到</p>
		<p>杀死一个程序对该数据库的使用:<br />&gt;db2 force application {all | (application-handle)}</p>
		<p>在库被使用时db2stop不能执行</p>
		<p>DB2命令后所带参数：<br />-t 以；作为一句结束<br />-f 指向一个文件(即执行一个文件中的语句，在command窗口里有些命令无法执行，可先用notepad建一个文件然后执行它)<br />-v (我不知道是什么)<br />注释：-v用于显示当前所执行的sql命令。<br /></p>
		<p>
				<br />一个windows nt 里的一般用户可以连到库，但无一般SQL语句的执行权，授权给一个用户：<br />&gt;db2 grant sql语句(例如：select) on 表名 to user 用户名<br />取消该用户的权：<br />&gt;db2 revoke sql语句 on 表名 from 用户名</p>
		<p>
				<br />DB2日志有两种：循环日志和永久型日志<br />循环日志：有3个文件循环写，所以会产生以前的操作记录被覆盖。好处：日志文件大小不变，备份方便，但不可以在线备份。<br />永久日志：其日志文件不断增涨，但操作记录不会被覆盖，可以在线备份。</p>
		<p>如何备份：<br />&gt;db2 backup db 数据库名 to 设备名(如：c:\);<br />恢复：<br />&gt;db2 restore db 数据库名 from 设备名<br />(回滚rollforward我不太清楚)<br />注释：rollforword 是前滚的意思，向前到某一个时间，以保持数据的一致性，用于在线备份后的恢复，恢复是从log日志中开始到日志中的某一个时间，即可。只有在数据一致性得到保证的情况下，才能继续对数据库操作。</p>
		<p>连接到数据库时报回滚错误<br />用下面的命令：<br />db2 rollforward db fmisadd to end of logs and complete</p>
		<p>导出导入数据库：<br />--export<br />db2move hadb export -u userid -p password; <br />--import<br />db2move hadb import -u userid -p password;</p>
		<p>
				<br />导出库中表的数据：<br />&gt;export to 文件名.ixf of ixf select * from 表名<br />&gt;import from 文件名.ixf of ixf create into 表名<br />导出库的数据格式还有两种del(文件格式)和wsf，但ixf格式信息最全，包含表结构信息，可恢复出已删去的表。</p>
		<p>sql的inner/left/right/full join，这些概念在&lt;&lt;数据库概论&gt;&gt;中有说明，left以左表为主，right以右表为主，full左右表记录都会在查寻结果中。<br />例如：&gt;select aa,bb from db1 left join db2 on db1.id=db2.id</p>
		<p>
				<br />合并查寻：把两个或几个查寻结果合并到一个字段(条件是字段必须兼容)<br />格式：select ...... union select ....；</p>
		<p>使用临时表：<br />with tmptable (字段1，...) as (select....)   --建一个临时表<br />select 字段1,.... from tmptable,另一个表 where....   --使用该临时表于另一个表交叉查寻。<br />**order by 必需出现在结果集，在临时表中不能用。</p>
		<p>截取字符串<br />substr(字段名,开始位置,字符个数)</p>
		<p>判断是否是空<br />字段名 is null</p>
		<p>
				<br />例子：<br />到什么时候活了10000天:<br />select distinct date('1980-01-01')+10000 day from a<br />一共活了多少天:<br />select distinct days(current date)-days(date('1980-01-01')) from a</p>
		<p>类型转换：用cast ,例：<br />select distinct cast(current date as char(10))||'aa' from a</p>
		<p>case的使用：<br />select case when length(rtrim(学历))=0 then '未知学历' else xl end,rs from a<br />例：查寻一个公司的年龄分布：<br />with tmptable as (select case when year(current day)-csrq&lt;20 then '小于20岁'                                                    when year(current day)-csrq&lt;25 then '20-24岁'                                                     when year(current day)-csrq&lt;30 then '25-29岁'<br />                              when year(current day)-csrq&lt;35 then '30-34岁'<br />                              when year(current day)-csrq&lt;40 then '35-39岁'<br />                              when year(current day)-csrq&lt;45 then '40-44岁'<br />                              when year(current day)-csrq&lt;50 then '45-49岁' else '大于50岁' end<br />as x from a)<br />select x,count(*) from tmptable group by x;</p>
		<p>一个数据库中有些系统建的表是用来保存该库各种信息的，如：syscat.tables<br />例：查有多少个userid的表： <br />select count(*) from syscat.tables where type='T' and tabschema='uerid'<br />例：产生一个备分库中所有表的文本：<br />select 'export to '|| tabname || '.ixf of ixf select * from userid.' ||tabname||';' from syscat.tables where type='T' and tabschema='userid';</p>
		<p> </p>
		<p>性能调整：<br />影响到DB2性能的有：<br />能够利用服务器的性能：1.并行性 2.减少通信</p>
		<p>建立Index<br />  &lt;,&gt;,=      第一类搜索谓词，<br />  &lt;&gt;,like    第二类搜索谓词，<br />  需要用函数 第三类搜索谓词，</p>
		<p>select * from a <br />*尽量要哪个字段写哪个字段。</p>
		<p>blocking的概念      客户端请求一次，数据库返回n个记录。</p>
		<p>复合型SQL(我不太清楚)<br />注释：是指他所讲的联结union，建立临时表等复杂的sql语句。</p>
		<p>DB2会对SQL语句优化，系统对表的信息知道的越多，优化越好，所以要做runstats<br />runstats命令把表的信息告诉系统，一般当数据量增加一倍时用该命令一次。</p>
		<p>REORG命令是数据库整理，类似于磁盘碎片整理。</p>
		<p>
				<br />得到该instance的各种参数：(dbm cfg是整个DB2的参数，db cfg是对某个数据库的参数)<br />&gt;db2 get dbm cfg<br />&gt;db2 get db cfg for 数据库名<br />修改参数：<br />&gt;db2 update dbm cfg using 参数 你要的数<br />&gt;db2 update db cfg for 数据库名 using 参数 你要的数</p>
		<p> </p>
		<p>当第一个用户连结到该数据库时会申请一个内存缓冲，默认是250页每页4k即1M。<br />Buffer pool size&lt;4K&gt;  [BUFFPAGE]=250<br />修改该值：<br />&gt;db2 update db cfg for test using buffpage 你要的数<br />但它的有效还取决于syscat.bufferpools中的npages是否为-1，为-1时它才有效，否则以syscat.bufferpols中的npage为准。<br />可用下面的命令看：<br />&gt;select * from syscat.bufferpools<br />一般此值的设置应为系统内存的40％左右，太大时会使系统因动用虚拟内存从而太吃力。</p>
		<p>sql语句的优化级别：一般取2或5（最高为9）<br />Default query optinization class      &lt;DFT_QUENYOPT&gt;=5<br />该值越大优化越好，但优化所化时间也越长。</p>
		<p>并行性设置：<br />Degree=-1 并行性全由操作系统完成。<br />当操作系统有并行处理时，Degree=-1<br />*****CUP与硬盘的个数一般为1:4到1:6;</p>
		<p>用户最大连结数：<br />&lt;MAXAPPLS&gt;=40<br />BUFFPAGE与MAXPPLS的关系：BUFFPAGE&gt;2*MXAPPLS<br /><br />文章出处： <a href="http://tb.blog.csdn.net/TrackBack.aspx?PostId=290057">http://tb.blog.csdn.net/TrackBack.aspx?PostId=290057</a></p><img src ="http://www.blogjava.net/zqbchina/aggbug/131504.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zqbchina/" target="_blank">心砚</a> 2007-07-20 15:51 <a href="http://www.blogjava.net/zqbchina/articles/131504.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQLSTATE 消息</title><link>http://www.blogjava.net/zqbchina/articles/131458.html</link><dc:creator>心砚</dc:creator><author>心砚</author><pubDate>Fri, 20 Jul 2007 06:04:00 GMT</pubDate><guid>http://www.blogjava.net/zqbchina/articles/131458.html</guid><wfw:comment>http://www.blogjava.net/zqbchina/comments/131458.html</wfw:comment><comments>http://www.blogjava.net/zqbchina/articles/131458.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zqbchina/comments/commentRss/131458.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zqbchina/services/trackbacks/131458.html</trackback:ping><description><![CDATA[<p>SQLSTATE 消息<br /><br />本节列示 SQLSTATE 及其含义。SQLSTATE 是按类代码进行分组的；对于子代码，请参阅相应的表。</p>
		<p>表 2. SQLSTATE 类代码 类 <br />代码   <br />含义 要获得子代码， <br />参阅... <br />00 完全成功完成 表 3 <br />01 警告 表 4 <br />02 无数据 表 5 <br />07 动态 SQL 错误 表 6 <br />08 连接异常 表 7 <br />09 触发操作异常 表 8 <br />0A 功能部件不受支持 表 9 <br />0D 目标类型规范无效 表 10 <br />0F 无效标记 表 11 <br />0K RESIGNAL 语句无效 表 12 <br />0N SQL/XML 映射错误 表 13 <br />20 找不到 CASE 语句的条件 表 15 <br />21 基数违例 表 16 <br />22 数据异常 表 17 <br />23 约束违例 表 18 <br />24 无效的游标状态 表 19 <br />25 无效的事务状态 表 20 <br />26 无效 SQL 语句标识 表 21 <br />28 无效权限规范 表 23 <br />2D 无效事务终止 表 24 <br />2E 无效连接名称 表 25 <br />34 无效的游标名称 表 26 <br />36 游标灵敏度异常 表 27 <br />38 外部函数异常 表 28 <br />39 外部函数调用异常 表 29 <br />3B SAVEPOINT 无效 表 30 <br />40 事务回滚 表 31 <br />42 语法错误或访问规则违例 表 32 <br />44 WITH CHECK OPTION 违例 表 33 <br />46 Java DDL 表 34 <br />51 无效应用程序状态 表 35 <br />53 无效操作数或不一致的规范 表 36 <br />54 超出 SQL 限制，或超出产品限制 表 37 <br />55 对象不处于先决条件状态 表 38 <br />56 其他 SQL 或产品错误 表 39 <br />57 资源不可用或操作员干预 表 40 <br />58 系统错误 表 41 <br />5U 实用程序 表 42 </p>
		<p>类代码 00 完全成功完成<br />表 3. 类代码 00：完全成功完成 SQLSTATE 值   <br />含义 <br />00000 操作执行成功，并且未产生任何类型的警告或异常情况。 </p>
		<p>类代码 01 警告<br />表 4. 类代码 01：警告 SQLSTATE 值   <br />含义 <br />01002 发生 DISCONNECT 错误。 <br />01003 从列函数的参数消去 NULL 值。 <br />01004 字符串值在指定给具有较短长度的另一字符串数据类型时被截断。 <br />01005 SQLDA 中的条目数不够。 <br />01007 未授予特权。 <br />0100C 从过程返回了一个或多个特殊结果集。 <br />0100D 关闭的游标已在链中的下一个结果集上重新打开。 <br />0100E 生成的过程大于允许的最大结果集数目。只有第一个整数结果集已经返回到调用者。 <br />01503 结果列数比提供的主机变量数大。 <br />01504 UPDATE 或 DELETE 语句不包括 WHERE 子句。 <br />01506 对 DATE 或 TIMESTAMP 值进行了调整，以更正算术运算得出的无效日期。 <br />01509 由于用户虚拟机中的存储器不够，取消游标的分块。 <br />01515 已为主机变量指定了一个空值，因为列的非空值不在主机变量的范围之内。 <br />01516 已忽略不可用的 WITH GRANT OPTION。 <br />01517 用替代字符替换不能转换的字符。 <br />01519 已为主机变量指定了一个空值，因为数字值超出范围。 <br />01524 列函数的结果不包括由算术表达式求值得出的空值。 <br />01526 隔离级别已升级。 <br />01527 SET 语句引用的专用寄存器在 AS 上不存在。 <br />01539 连接成功但只应使用 SBCS 字符。 <br />01543 已忽略重复约束。 <br />01545 未限定列名已解释为相关引用。 <br />01550 索引未创建，因为具有指定描述的索引已经存在。 <br />01560 忽略了一个冗余的 GRANT。 <br />01562 在数据库配置文件中的新日志路径（newlogpth）无效。 <br />01563 日志文件的当前路径（logpath）无效。日志文件路径被复位为缺省值。 <br />01564 已为主机变量指定了空值，因为发生了被零除的错误。 <br />01586 该语句导致一个或多个表自动置于设置完整性暂挂状态。 <br />01589 语句包含有冗余规范。 <br />01592 在引用 SOURCE 函数的 CREATE FUNCTION 语句中，或： <br />输入参数的长度、精度或小数位大于源函数相应参数的长度、精度或小数位；或 <br />RETURNS 或 CAST FROM 参数的长度、精度或小数位比源函数的小；或 <br />CREATE FUNCTION 语句中的 CAST FROM 参数的长度、精度或小数位比 RETURNS 参数的大。<br />运行时可能发生截断（那时可能会引起错误）。 <br />01594 对于所有信息，SQLDA 内的条目数不够多（即，没有足够的描述符返回相异名称）。 <br />01595 该视图已替换现有无效视图。 <br />01596 没有为基于长字符串数据类型的单值类型创建比较函数。 <br />01598 尝试激活活动的事件监视器，或尝试释放不活动的事件监视器。 <br />01599 忽略 REBIND 上的绑定选项。 <br />01602 优化级别已降低。 <br />01603 CHECK DATA 处理过程中发现约束违例，已将其移至异常表。 <br />01604 已经说明了 SQL 语句，但是未执行它。 <br />01605 递归公共表表达式可能包含无限循环。 <br />01606 节点或系统数据库目录是空的。 <br />01607 只读事务中节点的时间差超过定义的阈值。 <br />01608 已经替换了不受支持的值。 <br />01609 生成的过程大于允许的最大结果集数目。只有第一个整数结果集已经返回到调用者。 <br />01610 从过程返回了一个或多个特殊结果集。 <br />01611 关闭的游标已在链中的下一个结果集上重新打开。 <br />01614 定位器数小于结果集数。 <br />01616 估计的 CPU 成本超出了资源限制。 <br />01618 重新分发节点组是更改数据库分区所必需的。 <br />01620 UNION ALL 的某些基本表可能是同一个表。 <br />01621 检索到的 LOB 值可能已更改。 <br />01622 语句成功完成，但在语句完成之后发生了系统错误。 <br />01623 忽略 DEGREE 的值。 <br />01625 模式名在 CURRENT PATH 中出现了多次。 <br />01626 数据库只有一个活动的缓冲池。 <br />01627 DATALINK 值可能无效，因为该表处理协调暂挂或协调不可能的状态。 <br />01632 并发连接数超出了该产品的定义授权。 <br />01633 可能不能使用具体化查询表来优化查询的处理。 <br />01636 数据库管理器一直未验证非增量数据的完整性。 <br />01637 未启用调试。 <br />01639 联合对象可能需要调用程序具有对数据源对象的必要特权。 <br />01641 Datalink 类型属性限制结构化类型的使用。 <br />01642 对于最大的可能 USER 缺省值，列不足够长。 <br />01643 对 SQL 例程中 SQLSTATE 或 SQLCODE 变量的赋值可能会被覆盖，不会激活任何处理程序。 <br />01645 SQL 过程的可执行文件未保存在数据库目录中。 <br />01648 忽略了 COMPRESS 列属性，因为对表取消激活了 VALUE COMPRESSION。 <br />01649 缓冲池操作已经完成，但是直到下一次数据库重新启动才会生效。 <br />01650 索引和表统计信息不一致。 <br />01651 成功激活了事件监视器，但是某些监视信息可能丢失了。 <br />01652 由于语句上下文而忽略了隔离子句。 <br />01653 权限授予给 USER。因为权限名称大于 8 字节，所以不考虑组。 <br />01654 未启动缓冲池。 <br />01655 成功创建了事件监视器，但是至少有一个事件监视器目标表已存在。 <br />01657 缓冲池操作在下一次数据库重新启动之后才会生效。 <br />01665 列名或参数名被截断。 <br />01667 可能不能使用视图来优化查询的处理。 <br />01669 由于远程目录与本地目录之间的模式不一致，因此，未彻底更新指定昵称的统计信息。 <br />01670 对新表来说，不存在缺省主表空间。 <br />01671 高速缓存的语句的环境与当前环境不同。将使用当前环境来重新优化指定的语句。 <br />01674 表空间属性对于查询性能不是最佳的。 <br />01675 指定的表空间数超过了需要的表空间数。多余的表空间将被忽略。 <br />01676 忽略了传送操作，因为授权标识已经是数据库对象的所有者。 <br />01677 对于已经定义了插件的服务器忽略了包装器选项。 <br />01678 对用户映射的更改只应用于联合目录表，而不应用于外部用户映射存储库。 <br />01679 无法为指定的授权标识建立可信连接。 <br />01684 不支持指定的语言环境。返回的消息使用的是英语语言环境。 <br />01686 表空间正在从 REGULAR 转换为 LARGE。必须对此表空间中的表的索引进行重组或重建，以便支持大型 RID。 <br />01689 在未连接到数据源的情况下完成了 SQL 编译。 <br />0168A 在数据源上找不到源过程的程序包主体，或者它无效。 <br />01H51 “MQSeries 应用程序消息传递接口”消息被截断。 <br />01H52 例程的执行已完成，但是执行期间至少遇到了一个错误或警告。提供了更多信息。 <br />01H53 例程遇到了警告。参阅 SQLCODE 以获取详细信息。 <br />01HXX 由用户定义的函数或外部过程 CALL 返回了有效警告 SQLSTAE。 </p>
		<p>类代码 02 无数据<br />表 5. 类代码 02：无数据 SQLSTATE 值   <br />含义 <br />02000 发生下述异常之一： <br />SELECT INTO 语句或 INSERT 语句的子查询的结果为空表。 <br />在搜索的 UPDATE 或 DELETE 语句内标识的行数为零。 <br />在 FETCH 语句中引用的游标位置处于结果表最后一行之后。<br /> <br />02501 游标位置对于当前行的 FETCH 无效。 <br />02502 检测到删除或更新孔 <br />02506 遇到了错误，并且已按 RETURN DATA UNTIL 子句指定那样容许它。 </p>
		<p>类代码 07 动态 SQL 错误<br />表 6. 类代码 07：动态 SQL 错误 SQLSTATE 值   <br />含义 <br />07001 对于参数标记的数目来说，主机变量的数目不正确。 <br />07002 调用参数列表或控制块无效。 <br />07003 在 EXECUTE 语句内标识的语句是一条 select 语句，或未处于已预编译状态。 <br />07004 动态参数需要 USING 子句或 INTO 子句。 <br />07005 游标的语句名标识的是一个不能与游标关联的已预编译语句。 <br />07006 由于其数据类型的缘故不能使用某输入主机变量。 </p>
		<p>类代码 08 连接异常<br />表 7. 类代码 08：连接异常 SQLSTATE 值   <br />含义 <br />08001 应用程序请求器不能建立连接。 <br />08002 连接已存在。 <br />08003 连接不存在。 <br />08004 应用程序服务器拒绝了建立连接。 <br />08007 事务解析未知。 <br />08502 用 TWOPHASE 的 SYNCPOINT 运行的应用程序进程发出的 CONNECT 语句无效，因为无事务管理器可用。 <br />08504 当处理指定的路径重命名配置文件时遇到错误。 </p>
		<p>类代码 09 触发操作异常<br />表 8. 类代码 09：触发操作异常 SQLSTATE 值   <br />含义 <br />09000 触发 SQL 语句失败。 </p>
		<p>类代码 0A 不支持功能部件<br />表 9. 类代码 0A：不支持功能部件 SQLSTATE 值   <br />含义 <br />0A001 CONNECT 语句无效，因为进程不处于可连接状态。 <br />0A502 未对此数据库实例启用操作。 <br />0A503 由于潜在的数据不一致，不能编译联合插入、更新或删除操作。 </p>
		<p>类代码 0D 目标类型规范无效<br />表 10. 类代码 0D：目标类型规范无效 SQLSTATE 值   <br />含义 <br />0D000 目标结构化数据类型规范是源结构化数据类型的正确子类型。 </p>
		<p>类代码 0F 无效标记<br />表 11. 类代码 OF：无效标记 SQLSTATE 值   <br />含义 <br />0F001 LOB 标记变量当前不表示任何值。 </p>
		<p>类代码 0K RESIGNAL 语句无效<br />表 12. 类代码 0K：RESIGNAL 语句无效 SQLSTATE 值   <br />含义 <br />0K000 RESIGNAL 语句不在处理程序中。 </p>
		<p>类代码 0N SQL/XML 映射错误<br />表 13. 类代码 0N：SQL/XML 映射错误 SQLSTATE 值   <br />含义 <br />0N002 无法将字符映射至有效 XML 字符。 </p>
		<p>类代码 10 XQuery 错误<br />表 14. 类代码 10：XQuery 错误 SQLSTATE 值   <br />含义 <br />10000 XQuery 错误。 <br />10501 XQuery 表达式缺少静态或动态上下文组件的指定。 <br />10502 在 XQuery 表达式的序言中遇到了错误。 <br />10503 在 XQuery 或 XPath 表达式中定义了重复的名称。 <br />10504 在无效 URI 中指定了 XQuery 名称空间声明。 <br />10505 字符、标记或子句在 XQuery 表达式中缺少了或者无效。 <br />10506 XQuery 表达式引用了一个未定义的名称。 <br />10507 处理 XPath 或 XQuery 表达式时遇到了类型错误。 <br />10508 XQuery 表达式在已计算的构造函数中包括一个无效的名称表达式。 <br />10509 指定了不受支持的 XQuery 语言功能部件。 <br />10510 未指定字符串文字作为强制类型转换表达式操作数或构造函数参数。 <br />10601 在处理 XQuery 函数或运算符时遇到了算术错误。 <br />10602 在处理 XQuery 函数或运算符时遇到了数据类型转换错误。 <br />10603 在处理 XQuery 函数或运算符时遇到了字符处理错误。 <br />10604 未提供文档上下文来处理 XQuery 函数。 <br />10605 在处理 XQuery 函数或运算符时遇到了日期时间错误。 <br />10606 没有上下文项用来处理 XQuery 函数或运算符。 <br />10607 在处理 XQuery 函数或运算符时遇到了名称空间错误。 <br />10608 在 XQuery 函数或运算符的参数中遇到了错误。 <br />10609 在处理 XQuery 函数或运算符时遇到了正则表达式错误。 <br />10610 在处理 XQuery 函数或运算符时遇到了类型错误。 <br />10611 在处理 XQuery 函数或运算符时遇到了未标识的错误。 <br />10901 XQuery 原子值超出了 DB2 XQuery 数据类型的范围。 <br />10902 XQuery 原子值超过了 DB2 XQuery 运算符或函数的长度限制。 <br />10903 已超过相匹配的 XQuery 节点数的内部限制。 </p>
		<p>类代码 20 找不到 CASE 语句的条件<br />表 15. 类代码 20：找不到 Case 语句的条件 SQLSTATE 值   <br />含义 <br />20000 找不到 CASE 语句的条件。 </p>
		<p>类代码 21 基数违例<br />表 16. 类代码 21：基数违例 SQLSTATE 值   <br />含义 <br />21000 SELECT INTO 的结果是一个多行的结果表，或者，基本谓词的子查询结果为多个值。 <br />21501 对自引用表进行多行 INSERT 是无效的。 <br />21502 主键的多行 UPDATE 是无效的。 <br />21504 从删除规则为 RESTRICT 或 SET NULL 的自引用表进行多行 DELETE 是无效的。 <br />21505 行函数返回的内容不能超过一行。　 <br />21506 表的同一行不能是多个更新、删除或插入操作的目标。 </p>
		<p>类代码 22 数据异常<br />表 17. 类代码22：数据异常 SQLSTATE 值   <br />含义 <br />22001 字符数据，发生右截断；例如，更新或插入值对于列来说太长（字符串），或者日期时间值由于太小而不能赋给主机变量。 <br />22002 检测到空值或缺少指示符参数；例如，不能将空值赋给主机变量，因为没有指定指示符变量。 <br />22003 数值超出范围。 <br />22004 不能从定义为 PARAMETER STYLE GENERAL 的过程或者从用非空参数调用的类型保留方法中返回空值。 <br />22007 检测到无效的日期时间格式；即指定了无效的字符串表示法或值。 <br />22008 发生日期时间字段溢出；例如，对日期或时间戳记算术运算的结果不在有效日期范围之内。 <br />2200G 大多数特定类型都不匹配。 <br />2200L XML 值不是具有单个根元素的结构良好的文档。 <br />2200M 未能将值作为结构良好的 XML 文档进行解析或者根据 XML 模式来验证该值。 <br />2200S XML 注释无效。 <br />2200T XML 处理指令无效。 <br />2200W XML 值包含未能序列化的数据。 <br />22011 发生子字符串错误；例如，SUBSTR 的参数超出范围。 <br />22012 用零作除数是无效的。 <br />22018 对于 CAST、DECIMAL、FLOAT、或 INTEGER 标量函数，字符值是无效的。 <br />22019 LIKE 谓词有无效转义字符。 <br />22021 某字符不在编码字符集中。 <br />22024 以 NUL 结束的输入主机变量或参数不包含 NUL。 <br />22025 LIKE 谓词字符串模式包含无效的转义字符。 <br />2202D 配合 mutator 方法使用了空实例。 <br />2202H 在 TABLESAMPLE 子句中指定的样本大小无效。 <br />22501 变长字符串的长度控制字段为负值或大于最大值。 <br />22504 混合数据值是无效的。 <br />22506 对日期时间专用寄存器的引用无效，因为 TOD 时钟发生故障或操作系统时区参数超出范围。 <br />22522 CCSID 值根本无效，对数据类型或子类型无效，或对编码方案无效。 <br />22525 数据分区键值无效。 <br />22526 键变换函数没有生成任何行或生成了重复的行。 <br />22527 对多行 INSERT 操作检测到了无效的输入数据。 <br />22532 在 XML 模式存储库中未找到 XSROBJECT。 <br />22533 在 XML 模式存储库中未找到唯一的 XSROBJECT。 <br />22534 XML 模式文档未通过使用包括或重新定义而连接至其他 XML 模式文档。 <br />22535 XML 模式未声明指定的全局元素。 <br />22536 XML 值不包含必需的根元素。 <br />225D1 未启用指定的 XML 模式以进行分解。 <br />225D2 在分解 XML 文档期间发生了 SQL 错误。 <br />225D3 分解 XML 文档时遇到了对于 XML 模式类型无效的值。 <br />225D4 分解 XML 文档时遇到了对于目标 SQL 类型无效的值。 <br />225D5 分解 XML 文档时遇到了上下文中未知或无效的 XML 节点。 <br />225D6 指定的 XML 模式需要迁移到当前版本以支持分解。 <br />225D7 分解 XML 文档时遇到了一个根元素，该根元素不是 XML 模式中的复杂类型的全局元素。 <br />225DE 无法启用 XML 模式以进行分解。 </p>
		<p>类代码 23 约束违例<br />表 18. 类代码 23：约束违例 SQLSTATE 值   <br />含义 <br />23001 RESTRICT 更新或删除规则防止父键被更新或删除。 <br />23502 插入或更新值为空，但该列不能包含空值。 <br />23503 外键的插入或更新值无效。 <br />23504 NO ACTION 更新或删除规则防止父键被更新或删除。 <br />23505 发生由唯一索引或唯一约束强加的约束违例。 <br />23510 使用由 RLST 表强加的命令时发生约束违例。 <br />23511 不能删除父行，因为检查约束限制该删除。 <br />23512 不能添加检查约束，因为该表含有不满足约束定义的行。 <br />23513 INSERT 或 UPDATE 的结果行不符合检查约束定义。 <br />23514 检查数据处理中发现约束违例。 <br />23515 未能创建唯一索引，或者不能添加唯一约束，因为该表包含指定键的重复值。 <br />23520 不能定义外键，因为其所有的值都不同于父表的父键。 <br />23521 对目录表的更新违反了内部约束。 <br />23522 标识列值的范围或者序列用完。 <br />23523 已经为安全标号列提供了无效值。 <br />23524 UNION ALL 视图内的无效行移动。 <br />23525 未能插入或更新 XML 值，这是因为在插入或更新 XML 列的索引期间检测到错误。 <br />23526 未能创建 XML 列的索引，因为在将 XML 值插入到索引中时检测到错误。 </p>
		<p>类代码 24 无效的游标状态<br />表 19. 类代码 24：无效的游标状态 SQLSTATE 值   <br />含义 <br />24501 标识的游标未打开。 <br />24502 在 OPEN 语句中标识的游标已经打开。 <br />24504 在 UPDATE、DELETE、SET 或 GET 语句中标识的游标未定位在行上。 <br />24506 在 PREPARE 中标识的语句是一个打开游标语句。 <br />24510 对一个删除孔或更新孔尝试了<br /><br />UPDATE 或 DELETE 操作。 <br />24512 结果表与基本表不一致。 <br />24513 不允许 FETCH NEXT、PRIOR、CURRENT 或 RELATIVE，原因是游标位置未知。 <br />24514 先前的错误已禁用此游标。 <br />24516 已对结果集指定了一个游标。 <br />24517 外部函数或方法将游标保持为打开。 </p>
		<p> </p>
		<p>类代码 25 无效的事务状态<br />表 20. 类代码 25：无效的事务状态 SQLSTATE 值   <br />含义 <br />25000 插入、更新或删除操作在指定它的上下文中无效。 <br />25001 该语句只允许作为工作单元的第一条语句。 <br />25501 该语句只允许作为工作单元的第一条语句。 <br />25502 操作在单个事务中不能多次出现。 </p>
		<p>类代码 26 无效 SQL 语句标识<br />表 21. 类代码 26：无效 SQL 语句标识 SQLSTATE 值   <br />含义 <br />26501 标识的语句不存在。 </p>
		<p>类代码 27 触发的数据更改违例<br />表 22. 类代码 27：触发的数据更改违例 SQLSTATE 值   含义 <br />27000 试图在同一 SQL 语句中多次更改同一个表中的同一行。 </p>
		<p>类代码 28 无效权限规范<br />表 23. 类代码 28：无效权限规范 SQLSTATE 值   <br />含义 <br />28000 权限名称无效。 </p>
		<p>类代码 2D 无效事务终止<br />表 24. 类代码 2D：无效事务终止 SQLSTATE 值   <br />含义 <br />2D521 SQL COMMIT 或 ROLLBACK 在当前操作环境中无效。 <br />2D522 ATOMIC 复合语句中不允许 COMMIT 和 ROLLBACK。 <br />2D528 动态 COMMIT 对于应用程序执行环境无效。 <br />2D529 动态 ROLLBACK 对于应用程序执行环境无效。 </p>
		<p>类代码 2E 无效连接名称<br />表 25. 类代码 2E：无效连接名称 SQLSTATE 值   <br />含义 <br />2E000 连接名称无效。 </p>
		<p>类代码 34 无效的游标名称<br />表 26. 类代码 34：无效的游标名称 SQLSTATE 值   <br />含义 <br />34000 游标名无效。 </p>
		<p>类代码 36 无效游标规范<br />表 27. 类代码 36：无效游标规范 SQLSTATE 值   <br />含义 <br />36001 不能为指定的 SELECT 语句定义敏感游标。 </p>
		<p>类代码 38 外部函数异常<br />表 28. 类代码 38：外部函数异常 SQLSTATE 值   <br />含义 <br />38XXX 外部例程或触发器返回有效错误 SQLSTATE。 <br />38001 不允许外部例程执行 SQL 语句。 <br />38002 例程尝试修改数据，但例程未定义为 MODIFIES SQL DATA。 <br />38003 例程中不允许该语句。 <br />38004 例程尝试读取数据，但例程未定义为 READS SQL DATA。 <br />38501 （使用 SIMPLE CALL 或 SIMPLE CALL WITH NULLS 调用约定）调用用户定义的函数、外部过程或触发器时出错。 <br />38502 不允许外部函数执行 SQL 语句。 <br />38503 用户定义的函数异常终止（abend）。 <br />38504 用户定义的函数已被用户中断，以停止可能的循环条件。 <br />38505 FINAL CALL 上的例程中不允许 SQL 语句。 <br />38506 函数因来自 OLE DB 提供程序的错误而失败。 <br />38552 SYSFUN 模式（由 IBM 提供）中的函数已异常终止。 <br />可以在消息正文中找到下列原因码之一： </p>
		<p>01 <br />数值超出范围 <br />02 <br />被零除 <br />03 <br />算术溢出或下溢 <br />04 <br />日期格式无效 <br />05 <br />时间格式无效 <br />06 <br />时间戳记格式无效 <br />07 <br />时间戳记持续时间的字符表示法无效 <br />08 <br />时间间隔类型无效（必须是 1、2、4、8、16、32、64、128、256 之一） <br />09 <br />字符串太长 <br />10 <br />字符串函数中的长度或位置超出范围 <br />11 <br />浮点数的字符表示法无效  <br />38553 系统模式中的例程已因错误而终止。 <br />38H01 MQSeries 函数未能初始化。 <br />38H02 MQSeries 的“应用程序消息传递接口”未能终止会话。 <br />38H03 MQSeries 的“应用程序消息传递接口”未能正确地处理消息。 <br />38H04 MQSeries 的“应用程序消息传递接口”未能发送消息。 <br />38H05 MQSeries 的“应用程序消息传递接口”未能读取／接收消息。 <br />38H06 MQSeries 的“应用程序消息传递接口”预订（不预订）请求失败。 <br />38H07 MQSeries 的“应用程序消息传递接口”未能落实工作单元。 <br />38H08 MQSeries 的“应用程序消息传递接口”策略错误。 <br />38H09 MQSeries XA（两阶段落实）API 调用错误。 <br />38H0A MQSeries 的“应用程序消息传递接口”未能回滚工作单元。 </p>
		<p>类代码 39 外部函数调用异常<br />表 29. 类代码 39：外部函数调用异常 SQLSTATE 值   <br />含义 <br />39001 用户定义的函数已返回无效 SQLSTATE。 <br />39004 不允许 IN 或 INOUT 参数为空值。 <br />39501 与参数相关联的 eye-catcher（引人注目的事物）已被修改。 </p>
		<p>类代码 3B SAVEPOINT 无效<br />表 30. 类代码 3B：SAVEPOINT 无效 SQLSTATE 值   <br />含义 <br />3B001 保存点无效。 <br />3B002 已经达到最大保存点数目。 <br />3B501 检测到重复的保存点名。 <br />3B502 指定了 RELEASE 或 ROLLBACK TO SAVEPOINT，但是保存点不存在。 <br />3B503 在触发器或全局事务中不允许 SAVEPOINT、 RELEASE SAVEPOINT 或 ROLLBACK TO SAVEPOINT。 </p>
		<p>类代码 40 事务回滚<br />表 31. 类代码 40：事务回滚 SQLSTATE 值   <br />含义 <br />40001 发生了伴随自动回滚的超时或死锁。 <br />40003 语句完整性未知。 <br />40504 由于系统错误导致工作单元被回滚。 <br />40506 由于 SQL 错误，当前事务已回滚。 <br />40507 由于创建索引时发生故障，因此当前事务已回滚。 </p>
		<p>类代码 42 语法错误或访问规则违例<br />表 32. 类代码 42：语法错误或访问规则违例 SQLSTATE 值   <br />含义 <br />42501 授权标识不具有对标识对象执行指定操作的特权。 <br />42502 授权标识不具有执行指定操作的特权。 <br />42504 无法从指定的权限名撤销指定的特权、安全标号或免除凭证。 <br />42506 发生所有者授权失败。 <br />42508 不能将指定的数据库特权授予 PUBLIC。 <br />42509 因为 STATICRULES 选项而未授权 SQL 语句。 <br />42511 未能检索 DATALINK 值。 <br />42512 授权标识对受保护列没有访问权。 <br />42514 授权标识不具有对象的所有权需要的特权。 <br />42516 用户映射存储库中的认证失败。 <br />42519 不允许此授权标识对受保护表执行操作。 <br />42520 由于此授权标识没有安全标号，所以无法执行内置函数。 <br />42521 无法将权限或特权授予指定的授权标识。 <br />42522 此授权标识没有凭证，因此无法保护列或者对该列除去保护。 <br />42601 字符、标记或子句无效或丢失。 <br />42602 检测到名称中有无效字符。 <br />42603 检测到未终止的字符串常量。 <br />42604 检测到无效数字或字符串常量。 <br />42605 为标量函数指定的参数的数目无效。 <br />42606 检测到无效十六进制常数。 <br />42607 列函数的操作数无效。 <br />42608 在 VALUES 中使用 NULL 或 DEFAULT 是无效的。 <br />42609 运算符或谓词的所有操作数都是参数标记。 <br />42610 不允许参数标记。 <br />42611 列或参数定义无效。 <br />42612 语句字符串是一条 SQL 语句，它在它所出现的上下文中是不可接受的。 <br />42613 子句互斥。 <br />42614 重复关键字无效。 <br />42615 检测到无效备用项。 <br />42616 指定了无效的选项。 <br />42617 语句字符串是空白或空的。 <br />42618 不允许主机变量。 <br />42620 对 UPDATE 子句指定了只读 SCROLL。 <br />42621 检查约束无效。 <br />42622 名称或标号太长。 <br />42623 不能指定 DEFAULT 子句。 <br />42625 CASE 表达式无效。 <br />42627 必须在使用 EXPRESSION AS 子句的谓词规范之前指定 RETURNS 子句。 <br />42628 在变换定义中多次定义了 TO SQL 或 FROM SQL 变换函数。 <br />42629 必须为 SQL 例程指定参数名。 <br />42630 在嵌套复合语句中不能存在 SQLSTATE 或 SQLCODE 变量声明。 <br />42631 SQL 函数或方法中的 RETURN 语句必须包括返回值。 <br />42633 XMLATTRIBUTES 或 XMLFOREST 的参数需要 AS 子句。 <br />42634 XML 名称无效。 <br />42635 XML 名称空间前缀无效。 <br />42636 缺少 BY REF 子句，或者不正确使用了该子句。 <br />42637 无法在 DECLARE CURSOR 语句中指定 XQuery 表达式。 <br />42701 在插入或更新操作或 SET 转换变量语句中检测到重复列名。 <br />42702 由于名称重复，列引用有歧义。 <br />42703 检测到一个未定义的列、属性或参数名。　 <br />42704 检测到未定义的对象或约束名。 <br />42705 检测到未定义的服务器名。 <br />42707 ORDER BY 内的列名不标识结果表中的列。 <br />42709 在键列列表中指定了重复的列名。 <br />42710 检测到重复的对象或约束名。 <br />42711 在对象定义或 ALTER 语句中检测到重复列名或属性名。 <br />42712 在 FROM 子句中检测到重复的表标志符。 <br />42713 在对象列表中检测到重复对象。 <br />42720 在节点目录内未找到远程数据库的节点名。 <br />42723 模式中已经存在带有相同特征符的函数。 <br />42724 不能访问用于用户定义的函数或过程的外部程序。 <br />42725 直接引用了例程（不是通过特征符或者通过特定实例名进行引用），但是该例程有多个特定实例。 <br />42726 检测到指定的派生表的名称重复。 <br />42727 对新表来说，不存在缺省主表空间。 <br />42728 在节点组定义中检测到重复节点。 <br />42729 节点未定义。 <br />42730 容器名已由另一表空间使用。 <br />42731 容器名已由该表空间使用。 <br />42732 在 SET CURRENT PATH 语句中检测到重复的模式名。 <br />42734 检测到重复的参数名、SQL 变量名、游标名、条件名或标号。 <br />42735 对缓冲池，未定义表空间的节点组。 <br />42736 在 LEAVE 语句上指定的标号找不到或无效。 <br />42737 未定义在处理程序中指定的条件。 <br />42738 在 FOR 语句的 DECLARE CURSOR 语句中指定了重复的列名或未命名的列。 <br />42739 检测到重复的变换。 <br />42740 未找到指定类型的变换。未删除任何变换。 <br />42741 未对数据类型定义变换组。 <br />42742 类型表或带类型视图层次结构中已存在同类子表或子视图。 <br />42743 在索引扩展名中未找到搜索方法。　 <br />42744 在变换组中未定义 TO SQL 或 FROM SQL 变换函数。 <br />42745 例程将用现有方法定义覆盖关系。 <br />42746 在同一类型层次结构中，方法名不能与结构化类型名相同。 <br />42748 存储路径对于数据库来说已存在或者被指定了多次。 <br />42749 对于 XML 模式来说，已经存在具有相同目标名称空间和模式位置的 XML 模式文档。 <br />4274A 在 XML 模式存储库中未找到 XSROBJECT。 <br />4274B 在 XML 模式存储库中未找到唯一的 XSROBJECT。 <br />4274F 在安全标号组件中未定义组件元素。 <br />4274G 在给定安全标号所使用的安全标号策略中未定义安全标号组件。 <br />4274H 指定的安全策略不存在指定的访问规则。 <br />4274I 指定的安全策略不存在安全标号。 <br />4274J 数据库分区组已被此缓冲池使用。 <br />42802 插入或更新值的数目与列数不相同。 <br />42803 在 SELECT 或 HAVING 子句中的列引用无效，因为它不是分组列；或者在 GROUP BY 子句中的列引用无效。 <br />42804 CASE 表达式中的结果表达式不兼容。 <br />42805 ORDER BY 子句中的整数不标识结果表中的列。 <br />42806 不能将某值赋予某主机变量, 因为数据类型不兼容。 <br />42807 对该对象不允许执行 INSERT、UPDATE 或 DELETE。 <br />42808 插入或更新操作中标识的列不可更新。 <br />42809 标识的对象不是语句所应用的对象类型。 <br />42810 FOREIGN KEY 子句中没有标识基本表。 <br />42811 指定的列数与 SELECT 子句中的列数不相同。 <br />42813 WITH CHECK OPTION 不能用于指定的视图。 <br />42814 无法删除该列，因为它是表中唯一的列。 <br />42815 数据类型、长度、小数位、值或 CCSID 无效。 <br />42816 表达式中的日期时间值或持续时间无效。 <br />42817 由于某个视图或约束依赖于该列，并且指定了 RESTRICT，或者由于该列包含在分区键中，或者由于该列是安全标号列，所以无法删除该列。 <br />42818 运算符或函数的操作数不兼容或者不可比较。 <br />42819 算术运算的操作数或需要数字的函数的操作数不是数字。 <br />42820 数字常数太长，或其值不在该数据类型取值范围内。 <br />42821 更新或插入值与列不兼容。 <br />42823 从仅允许一列的子查询中返回了多列。 <br />42824 LIKE 的操作数不是字符串，或第一个操作数不是列。 <br />42825 UNION、INTERSECT、EXCEPT 或 VALUES 的行没有兼容列。 <br />42826 UNION、INTERSECT、EXCEPT 或 VALUES 的行的列数不相同。 <br />42827 UPDATE 或 DELETE 中标识的表与游标指定的表不相同。 <br />42828 由 UPDATE 或 DELETE 语句的游标指定的表不能修改，或该游标是只读游标。 <br />42829 FOR UPDATE OF 无效，因为由该游标指定的结果表不能修改。 <br />42830 外键不符合父键的描述。 <br />42831 主键或唯一键列不允许空值。 <br />42832 不允许对系统对象执行该操作。 <br />42834 不能指定 SET NULL，因为不能对外键的任何列指定空值。 <br />42835 在指定的派生表之间不能指定循环引用。 <br />42836 指定的递归派生表的规范无效。 <br />42837 不能改变该列，原因是它的属性与当前的列属性不兼容。 <br />42838 检测到无效使用了表空间。 <br />42839 索引和长列不能处于与该表独立的表空间内。 <br />42840 检测到无效使用了 AS CAST 选项。 <br />42841 参数标记不能是用户定义的类型或引用类型。 <br />42842 列定义无效，因为指定的选项与列描述不一致。 <br />42845 检测到无效使用了 VARIANT 或 EXTERNAL ACTION 函数。 <br />42846 不支持从源类型到目标类型的强制类型转换。 <br />42849 外部例程不支持所指定的选项。 <br />42852 在 GRANT 或 REVOKE 中指定的特权无效或不一致。（例如，视图上的 GRANT ALTER。） <br />42853 指定了选项的两个备用项，或者同一选项被指定了多次。 <br />42854 选择列表中的结果列数据类型与在带类型视图或具体化查询表定义中定义的类型不兼容。 <br />42855 不允许对此主机变量指定 LOB。此游标的 LOB 值的所有访存的目标主机变量必须是定位器或 LOB 变量。 <br />42858 不能将该操作应用于指定对象。 <br />42863 检测到 REXX 中有未定义的主机变量。 <br />42866 在 CREATE FUNCTION 语句的 CAST FROM 子句中的 RETURNS 子句的数据类型对于有源函数或函数体中的 RETURN 语句返回的数据类型不适合。 <br />42867 指定了冲突的选项。 <br />42872 FETCH 语句子句与游标定义不兼容。 <br />42875 要在 CREATE SCHEMA 中创建的对象的限定符必须与模式名相同。 <br />42877 不能限定该列名。 <br />42878 无效的函数或过程名称与 EXTERNAL 关键字一起使用。 <br />42879 在 CREATE FUNCTION 语句中一个或多个输入参数的数据类型对于源函数中相应的数据类型不适合。 <br />42880 CAST TO 和 CAST FROM 数据类型不兼容，或总会导致固定字符串截断。 <br />42881 使用基于行的函数无效。 <br />42882 特定实例名限定符与函数名限定符不相同。 <br />42883 找不到具有匹配特征符的例程。 <br />42884 找不到具有指定名称和兼容参数的任何例程。 <br />42885 在 CREATE FUNCTION 语句中指定的输入参数数目与 SOURCE 子句中指定的函数所提供的参数数目不匹配。 <br />42886 IN、OUT 或 INOUT 参数属性不匹配。 <br />42887 在该函数出现的上下文中该函数无效。 <br />42888 表没有主键。 <br />42889 该表已有主键。 <br />42890 在引用子句中指定了列表，但是标识的父表没有指定列名的唯一约束。 <br />42891 重复的 UNIQUE 约束已存在。 <br />42893 无法删除、改变或传输该对象或约束，或者无法从对象中撤销权限，因为还有其他对象依赖于该对象。 <br />42894 DEFAULT 值无效。 <br />42895 对于静态 SQL，不能使用输入主机变量，因为其数据类型与过程或用户定义的函数的参数不兼容。 <br />428A0 用户定义的函数所基于的有源函数出错。 <br />428A1 不能访问主机文件变量所引用的文件。 <br />428A2 表不能指定给多节点节点组，因为它没有分区键。 <br />428A3 为事件监视器指定了无效路径。 <br />428A4 为事件监视器选项指定了无效值。 <br />428A5 在 SET INTEGRITY 语句中指定的异常表结构不正确，或者已用生成的列、约束或触发器定义了该异常表。 <br />428A6 在 SET INTEGRITY 语句中指定的异常表不能与正在检查的表之一相同。 <br />428A7 检查的表数目与在 SET INTEGRITY 语句中指定的异常表数目不匹配。 <br />428A8 在父表或底层的表处于设置完整性暂挂状态时，不能对派生表使用 SET INTEGRITY 语句复位设置完整性暂挂状态。 <br />428A9 节点范围无效。 <br />428AA 列名不是事件监视器表的有效列。 <br />428B0 在 ROLLUP、CUBE 或 GROUPING SETS 中有非法嵌套。 <br />428B1 未指定给特定节点的表空间容器的规范数目不正确。 <br />428B2 容器的路径名无效。 <br />428B3 指定了无效的 SQLSTATE。 <br />428B7 在 SQL 语句中指定的编号不在有效范围内。 <br />428BO 不能为联合数据源创建方案。 <br />428C0 不能删除该节点，因为它是节点组中唯一的节点。 <br />428C1 只能为表指定一个 ROWID、IDENTITY 或安全标号列。 <br />428C2 检查函数体指出应已在 CREATE FUNCTION 语句中指定给出的子句。 <br />428C4 谓词运算符两边的元素的数目不相同。 <br />428C5 从数据源中找不到数据类型的数据类型映射。 <br />428C9 不能将 ROWID 列指定为 INSERT 或 UPDATE 的目标列。 <br />428CA 处于追加方式的表不能具有集群索引。 <br />428CB 表空间的页大小必须与相关联的缓冲池的页大小相匹配。 <br />428D1 不能访问 DATALINK 值所引用的文件。 <br />428D4 在 OPEN、CLOSE 或 FETCH 语句中不能引用在 FOR 语句中指定的游标。 <br />428D5 结束标号与开始标号不匹配。 <br />428D6 NOT ATOMIC 语句不允许 UNDO。 <br />428D7 不允许条件值。 <br />428D8 SQLSTATE 或 SQLCODE 变量的声明或使用无效。 <br />428DB 作为超类型、超表或超视图，该对象无效。　 <br />428DC 对于此类型的变换，该函数或方法无效。 <br />428DD 未定义要求的变换。 <br />428DE PAGESIZE 值不受支持。 <br />428DF 在 CREATE CAST 中指定的数据类型无效。 <br />428DG 在 CREATE CAST 中指定的函数无效。 <br />428DH 操作对于类型表无效。 <br />428DJ 不能更改或删除继承列或属性。 <br />428DK 已定义引用列的作用域。 <br />428DL 外部函数或有源函数的参数已定义了作用域。 <br />428DM 作用域表或视图对于引用类<br /><br />型无效。 <br />428DN 未在外部函数的 RETURNS 子句中指定 SCOPE，或在有源函数的 RETURN 子句中指定了 SCOPE。 <br />428DP 该类型不是结构化类型。 <br />428DQ 子表或子视图的模式名不能与其上一级表或上一级视图的模式名不同。 <br />428DR 无法将操作应用于子表或子视图。 <br />428DS 不能在子表中定义指定列的索引。　 <br />428DT 表达式的操作数不是有效的作用域引用类型。 <br />428DU 要求的类型层次结构中不包括的一种类型。　 <br />428DV 解析引用运算符的左操作数无效。 <br />428DW 不能使用解析引用运算符来引用对象标识列。 <br />428DX 对象标识列是定义一个类型表或带类型视图层次结构的根表或根视图所必需的。 <br />428DY 不能对目标对象类型更新统计信息。 <br />428DZ 不能更新对象标识列。 <br />428E0 索引的定义与索引扩展名的定义不匹配。 <br />428E1 用于产生范围的表函数的结果与索引扩展名的键变换表函数的结果不一致。 <br />428E2 目标键参数的数目或类型与索引扩展名的键变换函数的数目或类型不匹配。 <br />428E3 索引扩展名中函数的参数无效。 <br />428E4 函数在 CREATE INDEX EXTENSION 语句中不受支持。 <br />428E5 只能用用户定义的谓词来指定 SELECTIVITY 子句。 <br />428E6 用户定义的谓词中的方法的搜索参数与索引扩展名的相应搜索方法的搜索参数不匹配。 <br />428E7 用户定义的谓词中跟在比较运算符后的操作数类型与 RETURNS 数据类型不匹配。 <br />428E8 搜索目标或搜索参数参数与正在创建的该函数的参数名不匹配。 <br />428E9 在相同的使用规则中参数的参数名不能同时作为搜索目标和搜索参数。 <br />428EA 带类型视图中的全查询无效。 <br />428EB 当上一级视图中的某一列为可更新时，子视图中相应的列不能是只读的。 <br />428EC 为具体化查询表指定的全查询无效。 <br />428ED 不能构造具有 Datalink 或 Reference 类型属性的结构化类型。 <br />428EE 选项对此数据源无效。 <br />428EF 该选项的值对此数据源无效。 <br />428EG 丢失此数据源所必需的选项。 <br />428EH 不能 ADD 已定义的选项。 <br />428EJ 不能 SET 或 DROP 尚未添加的选项。 <br />428EK 已声明的全局临时表名的限定符必须是 SESSION。 <br />428EL 变换函数不能与函数或方法一起使用。 <br />428EM TRANSFORM GROUP 子句是必需的。 <br />428EN 变换组被指定为未使用。 <br />428EP 结构化类型不能直接或间接依赖于它本身。 <br />428EQ 例程的返回类型与主题类型不同。 <br />428ER 在删除方法主体之前，不能删除方法规范。 <br />428ES 方法主体与方法规范的语言类型不对应。 <br />428EU 在服务器定义中未指定 TYPE 或 VERSION。 <br />428EV 对于该数据源类型，传递（Pass-Through）功能不受支持。 <br />428EW 表不能与具体化查询表互相转换。 <br />428EX 例程不能用作变换函数，因为它是内置函数或方法。 <br />428EY 用户定义的谓词中搜索目标的数据类型与指定索引扩展名的源键的数据类型不匹配。 <br />428EZ OLAP 函数的窗口规范无效。 <br />428F0 ROW 函数必须包括至少两列。 <br />428F1 SQL TABLE 函数必须返回表结果。 <br />428F2 SQL 过程中的 RETURN 语句值的数据类型必须是 INTEGER。 <br />428F3 SCROLL 与 WITH RETURN 是互斥的。 <br />428F4 在 FETCH 上指定的 SENSITIVITY 不允许用于游标。 <br />428F6 游标是可滚动的，但结果表涉及来自表函数的输出。 <br />428F7 尝试对外部例程进行的操作仅应用于 SQL 例程。 <br />428F9 在此上下文中不能指定序列表达式。 <br />428FA 十进制数的小数位必须为零。 <br />428FB 序列名不能是由系统为标识列生成的序列。 <br />428FC 加密密码的长度无效。 <br />428FD 用于解密的密码与加密数据时所使用的密码不匹配。 <br />428FE 数据不是 ENCRYPT 函数的结果。 <br />428FF 缓冲池规范无效。 <br />428FG 登台表或具体化查询表定义无效。 <br />428FH SET INTEGRITY 选项无效 <br />428FI 指定了 ORDER OF，但表标志符不包含 ORDER BY 子句。 <br />428FJ 视图或具体化查询表的外部全查询不允许使用 ORDER BY。 <br />428FL 在指定 SQL 数据更改语句的上下文中，不允许 SQL 数据更改语句。 <br />428FM SELECT 中的 INSERT 语句指定了一个不是对称视图的视图。 <br />428FP 只允许将一个 INSTEAD OF 触发器用于对主题视图的每种操作。 <br />428FQ INSTEAD OF 触发器不能指定使用 WITH CHECK OPTION 定义的视图、在使用 WITH CHECK OPTION 定义的另一个视图上定义的视图或者嵌套在使用 WITH ROW MOVEMENT 子句定义的视图中的视图。 <br />428FT 表与指定的数据分区操作不兼容。 <br />428FU 从 FROM SQL 变换函数或方法返回的内置类型与 TO SQL 变换函数或方法的相应内置类型不匹配。 <br />428FV 不能将方法定义为覆盖方法。 <br />428FZ 仅为某些操作定义了 INSTEAD OF 触发器的视图不能在 MERGE 语句中用作目标。 <br />428G1 数据分区数超过了表的表空间数。 <br />428G2 无法从表中删除最后一个数据分区。 <br />428G3 当全查询中的 SQL 数据更改语句的目标视图定义了 INSTEAD OF 触发器时，FINAL TABLE 无效。 <br />428G4 无效使用了 INPUT SEQUENCE 排序。 <br />428G5 UPDATE 语句的赋值子句必须至少指定不是 INCLUDE 列的一列。 <br />428G6 指定了不能从全查询的 FROM 子句中的数据更改语句的目标中选择的一列。 <br />428G8 不能启用视图以进行查询优化。 <br />428GA 不能添加、删除或改变联合选项。 <br />428GD PARTITION BY 子句必须指定单个列，并且它必须与 ORGANIZE BY 子句的第一列相同。 <br />428GE 源表无法连接至分区目标表。 <br />428GG 无效使用了容许错误的嵌套表表达式。 <br />428GO 列选项在透明 DDL 语句中无效。 <br />428GI XML 模式不完整，因为缺少 XML 模式文档。 <br />428GP 无法为类型为 ARRAY 的组件指定多个元素。 <br />428GR 已经将具有相同访问类型（READ 或 WRITE）的安全标号授予给授权标识。 <br />428GQ 安全标号的 GRANT 与组件的现有已授权的安全标号相冲突。 <br />428GS 对该过程指定的选项值与源过程的对应选项不匹配。 <br />428GT 表未受安全策略保护。 <br />42901 列函数不包括列名。 <br />42903 WHERE 子句或 SET 子句包括无效引用，例如列函数。 <br />42904 由于编译错误，未创建 SQL 过程。 <br />42907 字符串太长。 <br />42908 语句不包括必需的列表。 <br />42910 复合语句中不允许该语句。 <br />42911 十进制除法运算无效，因为其结果的小数位为负。 <br />42912 列不能更新，因为它未在游标的 select 语句的 UPDATE 子句中标识。 <br />42914 DELETE 无效，因为子查询中引用的表可能会受该操作影响。 <br />42915 检测到无效引用约束。 <br />42916 不能创建别名，因为它会导致重复的别名链。 <br />42917 不能显式删除或改变该对象。 <br />42918 用户定义的数据类型不能用系统定义数据类型名（例如 INTEGER）创建。 <br />42919 不允许嵌套复合语句。 <br />42921 容器不能添加至该表空间。 <br />42925 指定的递归派生表不能指定 SELECT DISTINCT，而必须指定 UNION ALL。 <br />42928 不能为该表指定 WITH EMPTY TABLE。 <br />42932 程序预编译假设不正确。 <br />42939 不能使用该名称，因为指定的标识是保留给系统使用的。 <br />42961 指定的服务器名与当前服务器不匹配。 <br />42962 长列、LOB 列、XML 列或结构化类型列不能用于索引、键或约束。 <br />42963 指定的安全标号列无效。 <br />42968 连接失败，因为没有当前软件许可证。 <br />42969 未创建程序包。 <br />42972 MERGE 语句的连接条件或 ON 子句中的表达式引用多个操作数表中的列。 <br />42985 例程中不允许该语句。 <br />42987 不允许此语句出现在过程或触发器中。 <br />42989 使用表达式生成的列或者安全标号列不能在前触发器中使用。 <br />42990 不允许唯一索引或唯一约束，因为键列不是分区键列的超集。 <br />42991 BOOLEAN、BINARY 和 VARBINARY 数据类型当前仅在内部受支持。 <br />42993 定义的列太大而不能记录。 <br />42994 不支持原始设备容器。 <br />42995 所请求的函数不应用于全局临时表。 <br />42997 此版本的 DB2 应用程序请求器、DB2 应用程序服务器或两者的组合不支持该功能。 <br />429A1 节点组对于表空间无效。 <br />429A9 SQL 语句不能由 DataJoiner 处理。 <br />429B2 为结构化类型或列指定的直接插入长度值太小。 <br />429B3 可能未在子表中定义对象。 <br />429B4 数据过滤函数不能是 LANGUAGE SQL 函数。 <br />429B5 索引扩展名中实例参数的数据类型无效。 <br />429B8 用 PARAMETER STYLE JAVA 定义的例程不能具有作为参数类型或返回类型的结构化类型。 <br />429B9 在属性赋值中不能使用 DEFAULT 或 NULL。 <br />429BA FEDERATED 关键字必须与对联合数据库对象的引用配合使用。 <br />429BB 在 SQL 例程中不支持对参数或变量指定的数据类型。 <br />429BC 在 ALTER TABLESPACE 语句中有多个容器操作。 <br />429BE 主键或唯一键是维子句中的列的子集。 <br />429BG 范围集群表不支持该函数。 <br />429BH 分区表定义包含不受支持的列定义，该列可能是标识列、DATALINK 列或 XML 列。 <br />429BJ 在视图中无效使用了 WITH ROW MOVEMENT。 <br />429BK 由于移动行涉及到基础视图，因此，尝试更新视图无效。 <br />429BL 在非法上下文中调用了将修改 SQL 数据的函数。 <br />429BO 不能为联合数据源创建方案。 <br />429BP 昵称列表达式无效。 <br />429BS 涉及到 XMLPATTERN 子句或使用数据类型 XML 定义的列的索引定义无效。 <br />429BT 由于存在依赖性而使得转移所有权失败。 <br />429BU 无法访问插件的用户映射存储库中的用户映射。 <br />429BZ 由于其中一个底层表受保护，所以对 UNION ALL 视图执行的更新、删除或插入操作失败。 <br />429C0 查询必须包含使用了所指示的列的谓词。 </p>
		<p> </p>
		<p>类代码 44 WITH CHECK OPTION 违例<br />表 33. 类代码 44：WITH CHECK OPTION 违例 SQLSTATE 值   <br />含义 <br />44000 不允许插入或更新操作，因为结果行不满足视图定义。 </p>
		<p>类代码 46 Java DDL<br />表 34. 类代码 46：Java DDL SQLSTATE 值   <br />含义 <br />46001 Java DDL － 无效 URL。 <br />46002 Java DDL － 无效 jar 名称。 <br />46003 Java DDL － 无效类删除。 <br />46007 Java DDL － 无效特征符。 <br />46008 Java DDL － 无效方法规范。 <br />46103 Java 例程遇到了 ClassNotFound 异常。 <br />46501 Java DDL － 未实现可选组件。 </p>
		<p>类代码 51 无效应用程序状态<br />表 35. 类代码 51：无效应用程序状态 SQLSTATE 值   <br />含义 <br />51002 未找到与 SQL 语句执行请求相对应的程序包。 <br />51003 一致性标记不匹配。 <br />51004 SQLDA 中的地址无效。 <br />51005 上一系统错误已禁用此函数。 <br />51008 预编译的程序的发行版号无效。 <br />51015 尝试执行在绑定时发现有错的节。 <br />51017 用户没有登录。 <br />51021 在应用程序进程执行了回滚操作之后才能执行 SQL 语句。 <br />51022 当 CONNECT 语句中指定的服务器已存在连接（不论处于当前状态还是休眠状态）时，指定权限名称的 CONNECT 无效。 <br />51023 该数据库已由数据库管理器的另一实例使用。 <br />51024 不能使用视图，因为它已被标记为不可操作。 <br />51025 在 XA 事务处理环境中的应用程序未用 SYNCPOINT TWOPHASE 绑定。 <br />51026 无法打开事件监视器，因为它的目标路径已由另一事件监视器使用。 <br />51027 因为表是用户维护的具体化查询表或未处于设置完整性暂挂状态，所以 SET INTEGRITY 语句的 IMMEDIATE CHECKED 选项无效。 <br />51028 不能使用程序包，因为它被标记为不可操作。 <br />51030 在应用程序进程中尚未调用 ALLOCATE CURSOR 或 ASSOCIATE LOCATORS 语句中所引用的过程。 <br />51034 使用 MODIFIES SQL DATA 定义的例程在调用它的上下文中无效。 <br />51035 不能使用 PREVVAL 表达式，原因是在此会话中还没有为序列生成值。 <br />51038 SQL 语句可能不再由例程发出。 <br />51039 未设置 ENCRYPTION PASSWORD 值。 <br />51040 编译环境无效。 </p>
		<p>类代码 53 无效操作数或不一致的规范<br />表 36. 类代码 53：无效操作数或不一致的规范 SQLSTATE 值   <br />含义 <br />53038 键限制值的数目为零或者大于键中的列数。 <br />53040 不能像指定的那样更改缓冲池。 <br />53045 键限制常量的数据类型与列的数据类型不相同。 <br />53090 同一条 SQL 语句中只能引用具有一种编码方案（ASCII、EBCDIC 或 Unicode）的数据。 <br />53091 指定的编码方案与当前用于包含对象的编码方案不相同。 </p>
		<p>类代码 54 超过 SQL 或产品限制<br />表 37. 类代码 54：超过 SQL 限制或产品限制 SQLSTATE 值   <br />含义 <br />54001 语句太长或者太复杂。 <br />54002 字符串常量太长。 <br />54004 语句中 SELECT 或 INSERT 列表中的项或表名太多。 <br />54006 并置的结果太长。 <br />54008 键太长，键的列太长，或者键的列数太多。 <br />54010 表的记录长度太长。 <br />54011 为表或视图指定了太多列。 <br />54023 用于函数或过程的参数或自变量数目超出限制。 <br />54028 已达到并发 LOB 句柄最大数。 <br />54029 已达到打开目录扫描最大数。 <br />54030 活动事件监视器已达最大数。 <br />54031 已对事件监视器分配了最大文件数。 <br />54032 已达到表的最大大小。 <br />54033 已达到分区映射最大数。 <br />54034 表空间的所有容器名的组合长度太长。 <br />54035 已超过内部对象限制。 <br />54036 容器或存储路径的路径名太长。 <br />54037 表空间的容器映射太复杂。 <br />54038 超出了嵌套例程或触发器的最大深度。 <br />54045 已超出类型层次结构的最大级别。 <br />54046 索引扩展名中已超出允许的参数的最大值。 <br />54047 已超出表空间的最大大小。 <br />54048 具有足够页大小的临时表空间不存在。 <br />54049 结构化类型的实例的长度超过了系统限制。 <br />54050 在结构化类型中超过了允许的最大属性数目。 <br />54052 缓冲池的块页数对缓冲池对于缓冲池的大小来说太大了。 <br />54053 为 BLOCKSIZE 指定的值不在有效范围内。 <br />54054 超过了分区数或者超过了表空间分区数与分区限制键的相应长度的组合。 <br />54057 XML 元素名称、属性名称、名称空间前缀或 URI 太长。 <br />54058 XML 路径的内部表示太长。 <br />54059 只具有空格字符的文本节点字符串值太长，无法进行 STRIP WHITESPACE 处理。 <br />54061 对安全标号组件指定了太多元素。 <br />54062 已经超过了安全策略中的最大组件数。 </p>
		<p>类代码 55 对象不处于先决条件状态<br />表 38. 类代码 55：对象不处于先决条件状态。 SQLSTATE 值   <br />含义 <br />55001 数据库必须迁移。 <br />55002 未正确定义解释表。 <br />55006 对象不能删除，因为它当前正由同一应用程序进程使用。 <br />55007 不能改变对象，因为它当前正由同一应用程序进程使用。 <br />55009 系统尝试对只读文件或写保护软盘进行写入。 <br />55012 在表中已存在一个集群索引。 <br />55019 表的状态对于该操作无效。 <br />55022 未向此数据库注册文件服务器。 <br />55023 调用例程时发生错误。 <br />55024 表空间不能删除，因为与表相关的数据也在另一表空间中。 <br />55025 必须重新启动数据库。 <br />55026 不能删除临时表空间。 <br />55031 错误映射文件的格式不正确。 <br />55032 CONNECT 语句无效，因为在该应用程序启动后，数据库管理器停止。 <br />55033 事件监视器不能在创建它或修改它所处的同一工作单元内激活。 <br />55034 事件监视器处于无效的操作状态。 <br />55035 不能删除该表，因为它是受保护的。 <br />55036 不能删除该节点，因为它未从该分区映射除去。 <br />55037 不能删除该分区键，因为该表在多节点节点组内。 <br />55038 该节点组不能使用，因为它正在进行重新平衡。 <br />55039 不允许访问或状态转换，因为该表空间未处于适当状态。 <br />55041 在进行重新平衡时，不能将容器添加至表空间。 <br />55043 当基于该类型的类型表或带类型视图存在时，不能改变结构化类型的属性。 <br />55045 不能为该例程创建“SQL 归档”（SAR）文件，因为服务器上未提供所需组件。 <br />55046 指定的 SQL 归档与目标环境不匹配。 <br />55047 外部函数或方法尝试访问联合对象。 <br />55048 不能再加密已加密的数据。 <br />55049 未正确定义事件监视器表。 <br />55051 ALTER BUFFERPOOL 语句当前正在处理中。 <br />55054 不能将方法定义为覆盖方法。 <br />55056 由于未启用数据库进行联合，因此不能更新昵称统计信息。 <br />55057 不允许使用该语句，因为它将使增量维护某些从属表失效。 <br />55060 还没有为数据库定义自动存储器。 <br />55061 无法对自动存储器表空间更改表空间存储器。 <br />55062 因为没有对数据库启用自动存储器，所以不能提供存储路径。 <br />55063 对于该操作来说，XML 模式未处于正确状态。 <br />55064 无法将基于标号的访问控制应用于列，因为表没有安全策略。 <br />55065 一个表最多只能有一种安全策略。 <br />55066 表不能分配新页，因为索引尚不支持大型 RID。 <br />55067 表不能生成受保护的表，因为 MQT 或登台表依赖于它。 </p>
		<p>类代码 56 其他 SQL 或产品错误<br />表 39. 类代码 56：其他 SQL 或产品错误 SQLSTATE 值   <br />含义 <br />56016 为数据分区指定了无效范围。 <br />56031 子句或标量函数无效，因为该系统不支持混合数据和 DBCS 数据。 <br />56033 长字符串列的插入值或更新值必须是主机变量或 NULL。 <br />56038 此环境不支持请求的功能部件。 <br />56072 由于低级别服务器不支持函数，所以执行失败，这不会影响后续 SQL 语句的执行。 <br />56084 在 DRDA 中不支持 LOB 数据。 <br />56091 执行复合 SQL 语句时发生多个错误。 <br />56092 权限类型不能确定，因为权限名称既是用户标识又是组标识。 <br />56095 绑定选项无效。 <br />56097 在 DEVICE 上构建的 TABLESPACE 中不允许 LONG VARCHAR 和 LONG VARGRAPHIC 字段。 <br />56098 在隐式重新绑定或预编译期间出错。 <br />56099 目标数据库不支持 REAL 数据类型。 <br />560A0 对 LOB 值的操作失败。 <br />560AA 只有 Unicode 数据库图形数据才支持使用此子句或标量函数。 <br />560AC 包装器定义不能用于指定类型或版本的数据源。 <br />560AF 当使用网关集中器时，PREPARE 语句不受支持。 <br />560B0 调整的新表空间或表空间容器大小值无效。 <br />560B1 存储过程中有无效的游标规范。 <br />560B7 对于多行 INSERT，对于每一行，序列表达式的用法都必须相同。 <br />560BB 对于动态预编译的 CALL 语句中的 INOUT 参数，必须在 USING 和 INTO 子句中使用相同的主机变量。 <br />560BC 访问文件时发生错误。 <br />560BD 联合服务器从数据源中接收到意外的错误代码。 <br />560BF 加密工具不可用。 <br />560C0 不能在 SQL 函数或 SQL 方法中使用以 Unicod<br /><br />e 编码方案创建的表。 <br />560C1 以 Unicode 编码方案创建的表不能是类型表或者包含图形类型或用户定义的类型。 <br />560C2 为已删除表写历史记录文件条目失败。 <br />560C3 后触发器不能修改为 INSERT 语句插入的一行。 <br />560C6 引用约束不能修改由全查询内的 SQL 数据更改语句修改的行。 <br />560C8 不能更新某些昵称统计信息。 <br />560C9 不能说明指定的语句。 <br />560CB 联合服务器从 Web Service 数据源中接收到 SOAP 故障。 <br />560CD 在检索警报配置设置时指定的一个或多个值无效。 <br />560CE 由于最近的落实或回滚操作，使得 SQL 变量不可供引用。 <br />560CF 无法将表空间转换为大型表空间。 <br />560CG XML 值包含一些 XML 节点的组合，该组合导致超过了内部标识限制。 <br />560CH 超过了 XML 值中 XML 节点的子节点的最大数目。 <br />560CI 指定要返回给客户机的结果集无效。 <br />560CJ 必须在 IBMCATGROUP 数据库分区组中创建表空间。 </p>
		<p> </p>
		<p>类代码 57 资源不可用或操作员干预<br />表 40. 类代码 57：资源不可用或操作员干预 SQLSTATE 值   <br />含义 <br />57001 表不可用，因为它没有主索引。 <br />57003 尚未激活指定的缓冲池。 <br />57007 对象不能使用，因为 DROP 或 ALTER 处于暂挂状态。 <br />57009 虚拟存储器或数据库资源暂时不可用。 <br />57011 虚拟存储器或数据库资源不可用。 <br />57012 非数据库资源不可用。这不会影响后续语句的成功执行。 <br />57013 非数据库资源不可用。这将影响后继语句的成功执行。 <br />57014 按照请求取消了处理。 <br />57016 因为表不活动，所以不能访问它。 <br />57017 未定义字符转换。 <br />57019 该语句因资源问题未成功。 <br />57020 包含数据库的驱动器被锁定。 <br />57021 软盘驱动器门是打开的。 <br />57022 不能创建表，因为语句的授权标识不拥有任何合适的 dbspaces。 <br />57030 与应用程序服务器的连接超出安装定义的限制。 <br />tp57032 已启动最大并发数据库数。 <br />57033 发生死锁或超时，而没有自动回滚。 <br />57036 事务日志不属于当前的数据库。 <br />57046 不能启动新的事务，因为数据库或实例被停顿。 <br />57047 不能创建内部数据库文件，因为该目录不可访问。 <br />57048 访问表空间的容器时发生错误。 <br />57049 已达到操作系统进程界限。 <br />57050 文件服务器当前不可用。　 <br />57051 估计的 CPU 成本超出了资源限制。 <br />57052 节点不可用，因为它所含有的容器不足以满足所有的临时表空间。 <br />57053 因为冲突操作，所以不能对表执行操作。 <br />57055 带有足够页大小的临时表空间不可用。　 <br />57056 程序包不可用，因为数据库处于 NO PACKAGE LOCK 方式。 <br />57057 由于 SQL 语句的 DRDA 链中的优先条件，不能执行该 SQL 语句。 <br />57059 表空间中没有足够的空间用于执行指定的操作。 </p>
		<p>类代码 58 系统错误<br />表 41. 类代码 58：系统错误 SQLSTATE 值   <br />含义 <br />58004 发生系统错误（它不一定阻止后续 SQL 语句的成功执行）。 <br />58005 发生系统错误（它阻止后续 SQL 语句的成功执行）。 <br />58008 由于分发协议错误致使执行失败，它不影响后续 DDM 命令或 SQL 语句的成功执行。 <br />58009 由于分发协议错误致使执行失败，它导致对话的释放。 <br />58010 由于分发协议错误致使执行失败，它将影响后续 DDM 命令或 SQL 语句的成功执行。 <br />58011 进行绑定时 DDM 命令无效。 <br />58012 具有指定程序包名和一致性标记的绑定进程不活动。 <br />58014 DDM 命令不受支持。 <br />58015 DDM 对象不受支持。 <br />58016 DDM 参数不受支持。 <br />58017 DDM 参数值不受支持。 <br />58018 不支持 DDM 应答消息。 <br />58023 系统错误导致当前程序被取消。 <br />58030 发生 I/O 错误。 <br />58031 连接因系统错误而未成功。 <br />58032 不能将该进程用于设防方式的用户定义的函数。 <br />58034 尝试在 DMS 表空间中寻找对象的页时检测到错误。 <br />58035 尝试在 DMS 表空间中释放对象的页时检测到错误。 <br />58036 指定的内部表空间标识不存在。 </p>
		<p>类代码 5U 实用程序<br />表 42. 类代码 5U：实用程序 SQLSTATE 值   <br />含义 <br />5U001 指定的函数或功能部件不受支持。 <br />5U002 指定的应用程序当前不存在。 <br />5U003 找不到活动监控器报告。 <br />5U004 保存监视任务时所提供的一个或多个值无效。 <br />5U005 指定的操作方式无效。 <br />5U006 未打开必需的监视开关。 <br />5U007 返回了 CLP 错误。有关详细信息，请参阅 CLP 消息文档。 <br />5U008 实用程序操作标识无效。 <br />5U009 已达到存储路径的最大数目。 <br />5U010 对非目录数据库分区执行的复原操作不能指定自动存储路径。 <br />5U011 复原操作必须指定自动存储路径。 <br />5U012 路径中的数据库分区表达式无效或者不正确地使用了它。 <br />5U013 不能继续进行复原，因为数据库分区不可用。 <br />5U014 授权标识没有对表运行 LOAD 命令所必需的 LBAC 凭证。 <br />5U0ZZ 例程遇到了错误。参阅 SQLCODE 以获取详细信息。 <br />ZZZZZ 占位符 sqlstate 仅供开发使用。在交付代码之前必须更改它。<br /><br />文章来源：<a href="http://www.51fy.cn/data/MSSQL/200703/31846.htm"><font color="#1a8bc8">http://www.51fy.cn/data/MSSQL/200703/31846.htm</font></a></p><img src ="http://www.blogjava.net/zqbchina/aggbug/131458.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zqbchina/" target="_blank">心砚</a> 2007-07-20 14:04 <a href="http://www.blogjava.net/zqbchina/articles/131458.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>jdbc连接db2</title><link>http://www.blogjava.net/zqbchina/articles/131324.html</link><dc:creator>心砚</dc:creator><author>心砚</author><pubDate>Thu, 19 Jul 2007 09:46:00 GMT</pubDate><guid>http://www.blogjava.net/zqbchina/articles/131324.html</guid><wfw:comment>http://www.blogjava.net/zqbchina/comments/131324.html</wfw:comment><comments>http://www.blogjava.net/zqbchina/articles/131324.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zqbchina/comments/commentRss/131324.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zqbchina/services/trackbacks/131324.html</trackback:ping><description><![CDATA[<p>public static void main(String[] args) {<br />  Connection conn = null;<br />  PreparedStatement ps = null;<br />  ResultSet rs = null;<br />  String url = "jdbc:db2://192.168.3.23:50000/dbname",<br />      username = "username", <br />      password = "password";</p>
		<p>  try {<br />   Class.forName("com.ibm.db2.jcc.DB2Driver");<br />   conn = DriverManager.getConnection(url, username, password);<br />   ps = conn.prepareStatement("select colname from tablename");<br />   rs = ps.executeQuery();<br />   while (rs.next()) {<br />    System.out.println(rs.getString(1));<br />   }<br />  } catch (Exception e) {<br />   e.printStackTrace();<br />  } finally {<br />   try {<br />    if (rs != null) rs.close();<br />    if (ps != null) ps.close();<br />    if (conn != null) conn.close();<br />   } catch (SQLException e) {<br />    e.printStackTrace();<br />   }<br />  }<br /> }</p><img src ="http://www.blogjava.net/zqbchina/aggbug/131324.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zqbchina/" target="_blank">心砚</a> 2007-07-19 17:46 <a href="http://www.blogjava.net/zqbchina/articles/131324.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>初识DB2</title><link>http://www.blogjava.net/zqbchina/articles/127771.html</link><dc:creator>心砚</dc:creator><author>心砚</author><pubDate>Tue, 03 Jul 2007 02:54:00 GMT</pubDate><guid>http://www.blogjava.net/zqbchina/articles/127771.html</guid><wfw:comment>http://www.blogjava.net/zqbchina/comments/127771.html</wfw:comment><comments>http://www.blogjava.net/zqbchina/articles/127771.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zqbchina/comments/commentRss/127771.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zqbchina/services/trackbacks/127771.html</trackback:ping><description><![CDATA[<p>
				<font size="1">1，CLP的运行：<br /><br />   直接在cmd中键入：db2，报错：DB21061E  未初始化命令行环境。<br /><br />   键入：db2cmd，这时会打开一个CLP窗口，在这里键入db2后，就可以进行sql命令操作了。如：<br /><br />   db2 =&gt; connect to sample<br /><br /><br />2，表空间的创建：<br /><br />     在创建表空间，选择“容器”，如果你选择的容器（windows os）是一个非空的文件夹，那么将会报错：<br /><br />            [IBM][CLI Driver][DB2/NT] SQL0298N  容器路径不正确。  SQLSTATE=428B2<br /><br />    只需将“容器”改为一个空的文件夹即可。<br /><br /><br />3，创建数据库：<br /><br />      一个数据库最少有三个表空间：用户表、目录表和临时表，这些表空间可以采取让OS来管理，也可以让DB本身来管理，这里我采用让OS来进行管理表空间，容器的建立如下：<br /><br />               用户表（空间）－－－ d:\MyDB\userTabSpace<br />               目录表（空间）－－－ d:\MyDB\dirTabSpace<br />               临时表（空间）－－－ d:\MyDB\tempTabSpace<br /><br />4，在java中用JDBC连接DB2数据库，先用eclipse中的Database Explorer连接：<br />       <br />      a，当Class选用DB2中E:\IBM\SQLLIB\java\db2java.zip 下的COM.ibm.db2.jdbc.app.DB2Driver时，Database Explorer可以连接上数据库；当Class选用DB2中E:\IBM\SQLLIB\java\db2jcc.jar 下的com.ibm.db2.jcc.DB2Driver时，Database Explorer连接不上数据库，报错：No license was found，需要将包db2jcc_license_cu.jar加载到classpath下。<br /><br />5，在用restore命令对DB2进行数据恢复时，如果有多个备份文件与为备份数据库映像所提供的时间戳记值相匹配的话，那么将不能正常恢复，这里采用了一个比较土的方法：如130324.001，改为：130324A.001，那么将会认为这个文件与备份数据库映像所提供的时间戳记值不同，不予恢复考虑。<br /><br />6，oracle中的decode()函数，看看在DB2中都被折腾成什么样子了：<br /><br />  语句： select id,case when id=1 then '邹清兵' when id=2 then '马明灯' else name end as 姓名,name from test；<br /><br />ID          姓名       NAME<br />----------- ---------- ----------<br />          1 邹清兵     zqb<br />          2 马明灯     mmd<br />          3 kyy        kyy</font>
		</p>
		<p>
				<font size="1">  3 条记录已选择。<br /><br />7，DB2中<span lang="EN-US" style="LINE-HEIGHT: 150%">db2start启动数据库，<span lang="EN-US" style="LINE-HEIGHT: 150%">db2stop用来关闭数据库。但如果有数据库正在连接时，是不能关闭数据库的，只有先断开数据库（connect reset）连接才能再关闭数据库（db2stop）；当然，也可以强行关闭数据库（db2stop force）。</span></span></font>
		</p>
		<p>
				<font size="1">8，查错方法总结：<br />         通过SQLSTATE代码得到其错误原因，如：<br />               db2  ?    08004，其中08004是SQLSTATE代码；当然，有时候我们得到的并不一定是SQLSTATE代码，这时可以同样通过命令： db2  ?  SQL1068N，来得到其SQLSTATE代码。</font>
				<br />
				<br />
				<font size="1">9，oracle中的rownum，可以用DB2中的row_number() over()来替代，也可以用fetch first 3 rows only，如：<br />    select * from (select row_number() over() as rownum,t.* from xxx t) where rownum &lt; 3<br />    (select   *   from   xxx   fetch   first   20   rows   only)   except   (select   *   from   xxx   fetch   first   10   rows   only)</font>
		</p><img src ="http://www.blogjava.net/zqbchina/aggbug/127771.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zqbchina/" target="_blank">心砚</a> 2007-07-03 10:54 <a href="http://www.blogjava.net/zqbchina/articles/127771.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>