﻿<?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-Terry的Blog-随笔分类-oracle</title><link>http://www.blogjava.net/terry-zj/category/4742.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 31 Aug 2010 19:43:12 GMT</lastBuildDate><pubDate>Tue, 31 Aug 2010 19:43:12 GMT</pubDate><ttl>60</ttl><item><title>Oracle instant客户端配置</title><link>http://www.blogjava.net/terry-zj/archive/2010/08/30/330216.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Sun, 29 Aug 2010 17:26:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2010/08/30/330216.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/330216.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2010/08/30/330216.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/330216.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/330216.html</trackback:ping><description><![CDATA[<strong>Oracle instant客户端下载地址</strong><br />
<font size="4"><a href="http://www.oracle.com/technetwork/topics/winsoft-085727.html" target="_blank">http://www.oracle.com/<wbr>technetwork/topics/winsoft-<wbr>085727.html</a><br />
</font><a class="boldbodylink" href="http://download.oracle.com/otn/nt/instantclient/112010/instantclient-basic-win32-11.2.0.1.0.zip" id="file36" name="file36" onclick="youMustAgreePrompt();">instantclient-basic-win32-11.2.0.1.0.zip</a><br />
<font size="4"><br />
<strong>解压后</strong></font><strong>在客户端根目录创建tnsnames.ora文件</strong><br />
XE1 =
<br />
(DESCRIPTION =
<br />
&nbsp; (ADDRESS = (PROTOCOL = TCP)(HOST = 16.157.1.1)(PORT = 1521))
<br />
(CONNECT_DATA =
<br />
(SERVER = DEDICATED)
<br />
(SERVICE_NAME = XE1)
<br />
)
<br />
<br />
XE2 =
<br />
(DESCRIPTION =
<br />
&nbsp; (ADDRESS = (PROTOCOL = TCP)(HOST = 16.157.1.2)(PORT = 1521))
<br />
(CONNECT_DATA =
<br />
(SERVER = DEDICATED)
<br />
(SID= XE2)
<br />
)
<br />
<br />
配置PL/SQL Developer<br />
<strong>配置PL/SQL的oracle的目录位置</strong><br />
tool--&gt;preferences--&gt;<wbr>connection--&gt;oracle home
和 OCI Library 的路径<br />
<br />
在PL/SQL Developer安装目录下建立一个start.bat脚本文件<br />
设置环境变量<br />
set path=C:\instantclient_11_2<br />
set ORACLE_HOME=C:\instantclient_<wbr>11_2<br />
set TNS_ADMIN=C:\instantclient_11_<wbr>2<br />
set NLS_LANG=AMERICAN_AMERICA.<wbr>AL32UTF8<br />
start PLSQLDev.exe
<br />
<br />
具体说明NLS_LANG的取值<br />
格式:NLS_LANG=language_territory.charset
<br />
<br />
取值来源:select * from v$nls_parameters
<br />
查询nls的参数，获得数据库服务器端的字符编码
,需要保证要设置客户端字符集与服务器端字符集一致
<br />
NLS_LANGUAGE
<br />
NLS_CHARACTERSET
<br />
<br />
<font size="4"><br />
</font>
<img src ="http://www.blogjava.net/terry-zj/aggbug/330216.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2010-08-30 01:26 <a href="http://www.blogjava.net/terry-zj/archive/2010/08/30/330216.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>日文字符中常见的乱码情况---正波浪线“～”</title><link>http://www.blogjava.net/terry-zj/archive/2006/04/20/42108.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Thu, 20 Apr 2006 02:46:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2006/04/20/42108.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/42108.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2006/04/20/42108.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/42108.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/42108.html</trackback:ping><description><![CDATA[
		<p>在一般的日文字符表示正常的情况下正波浪线“～”任然经常会出现乱码的情况。<br /><br />数据库参数NLS Database Parameters<br />NLS_CHARACTERSET                   JA16SJIS <br />NLS_NCHAR_CHARACTERSET   AL16UTF16<br /><br />一：对于VARCHAR2字段<br />现象：在页面上输入“～”存入DB后再取出到页面时变成“?”<strong>（页面的字符设置为charset=shift-jis）</strong><br />调查：<br />1 页面提交后在java中观察编码为\uff5e<br />2 java中定义一个字符变量“～”观察编码为\uff5e<br />3 编码为\uff5e的字符存入数据库再取出的编码为\u301c<br />4 用Object Browser观察数据库中字符都正常<br />结论：存入数据库时编码发生了变化\uff5e ---&gt; \u301c<br />解决：取出数据时遍历发现\u301c就转换为\uff5e<br />      public String getString(int columnIndex) throws SQLException {<br />         // TODO: ～を変更<br />         String value = rs.getString(columnIndex);<br />         if (value != null){<br />              StringBuffer sbDest = new StringBuffer();<br />              char ch;<br />              for(int j= 0;j&lt; value.length();j++){<br />                  ch = value.charAt(j);<br />                  if(ch == 0x301c){<br />                      sbDest.append("\uff5e"); // ～<br />                  }else{<br />                      sbDest.append(ch);<br />                  }<br />              }<br />              value = sbDest.toString();<br />         }</p>
		<p>         return value;<br />     }<br /><br />二：对于NVARCHAR2字段<br />现象：在页面上输入正波浪线“～”存入DB后再取出到页面时变成反波浪线“〜”<strong>（页面的字符设置为charset=UTF-8）<br /></strong>用Object Browser工具察看表中的数据 发现是正波浪线“～” 编码为\u301c。（实际上用Object Browser看\u301c  \uff5e都是正波浪线）<br />如果用NVARCHAR2字段，那么正确的操作后可以存入\uff5e<br /><br />试验用表 Products ，表中的列定义如下所示<br />id - VARCHAR2(10) — 产品 id<br />lang_id — VARCHAR2(10) — 语言 id<br />description — NVARCHAR2(2000) — Unicode 编码的产品描述<br /><br />JDBC 允许 Java 程序访问 Oracle9i 数据库中的 NVARCHAR2 数据类型的列。Oracle JDBC 驱动程序把 SQL NCHAR/NVARCHAR2 列中的数据从本地字符集编码（UTF8 或 AL16UTF16）直接转化为 UTF-16 编码的 Java 字符串。<br />为此，我们需要把 Java 字符串绑定到一个 NVARCHAR2 列。下面的代码段显示了完成这项任务的代码。</p>
		<p>// Get an Oracle preparedstatement<br />OraclePreparedStatement orastmt =(OraclePreparedStatement)connection.prepareStatement(<br />"INSERT INTO PRODUCTS VALUES(?,?,?)");<br />// Bind the 3rd parameter to NVARCHAR2 form so that the data is stored as unicode<br /><strong>orastmt.setFormOfUse(3,OraclePreparedStatement.FORM_NCHAR);<br /></strong>orastmt.setString(1,product.getId());<br />orastmt.setString(2,product.getLangId());<br />orastmt.setString(3,product.getDescription());<br />orastmt.executeUpdate();<br />orastmt.close();</p>
		<p>使用 orastmt.setFormOfUse() 方法来指定列的类型是 NVARCHAR2。确保数据以Unicode 编码存储。<br /><br />关于NVARCHAR2字段的操作参考：<br /><a href="http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/9i_jdbc/NCHARsupport4UnicodeSample/Readme.html">http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/9i_jdbc/NCHARsupport4UnicodeSample/Readme.html</a><br /><br />注意这段话：<br />The only difference in usage between the SQL CHAR and SQL NCHAR datatypes occur in a data bind situation. <br />The JDBC program must call the setFormOfUse() method to specify if the data is bound for a SQL NCHAR<br />datatype and <strong>it must be called before binding</strong> Java variables to SQL NCHAR datatypes.<br /><strong>必须先setFormOfUse再绑定变量。否则存入数据库中的仍是\u301c<br /></strong></p>
<img src ="http://www.blogjava.net/terry-zj/aggbug/42108.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2006-04-20 10:46 <a href="http://www.blogjava.net/terry-zj/archive/2006/04/20/42108.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>比较Oracle SQL中的IN &amp; EXISTS</title><link>http://www.blogjava.net/terry-zj/archive/2006/04/18/41662.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Tue, 18 Apr 2006 08:01:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2006/04/18/41662.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/41662.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2006/04/18/41662.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/41662.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/41662.html</trackback:ping><description><![CDATA[
		<p>在Oracle SQL中取数据时有时要用到in 和 exists 那么他们有什么区别呢？<br /><br /><strong>1 性能上的比较<br /></strong>比如Select * from T1 where x in ( select y from T2 )<br />执行的过程相当于:<br />select * <br />  from t1, ( select distinct y from t2 ) t2<br /> where t1.x = t2.y;<br /><br />相对的</p>
		<p>select * from t1 where exists ( select null from t2 where y = x )<br />执行的过程相当于:<br />for x in ( select * from t1 )<br />   loop<br />      if ( exists ( select null from t2 where y = x.x )<br />      then <br />         OUTPUT THE RECORD<br />      end if<br />end loop<br />表 T1 不可避免的要被完全扫描一遍</p>
		<p>分别适用在什么情况?<br />以子查询 ( select y from T2 )为考虑方向<br />如果子查询的结果集很大需要消耗很多时间，但是T1比较小执行( select null from t2 where y = x.x )非常快，那么exists就比较适合用在这里<br />相对应得子查询的结果集比较小的时候就应该使用in.<br /><br /><strong>2 含义上的比较<br /></strong>在标准的scott/tiger用户下<br /></p>
		<table style="WIDTH: 367pt; BORDER-COLLAPSE: collapse" cellspacing="0" cellpadding="0" width="487" border="0" x:str="">
				<colgroup>
						<col style="WIDTH: 19pt; mso-width-source: userset; mso-width-alt: 914" width="25" />
						<col style="WIDTH: 38pt; mso-width-source: userset; mso-width-alt: 1865" span="2" width="51" />
						<col style="WIDTH: 47pt; mso-width-source: userset; mso-width-alt: 2267" width="62" />
						<col style="WIDTH: 29pt; mso-width-source: userset; mso-width-alt: 1389" width="38" />
						<col style="WIDTH: 61pt; mso-width-source: userset; mso-width-alt: 2962" width="81" />
						<col style="WIDTH: 46pt; mso-width-source: userset; mso-width-alt: 2230" span="2" width="61" />
						<col style="WIDTH: 43pt; mso-width-source: userset; mso-width-alt: 2084" width="57" />
				</colgroup>
				<tbody>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl45" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 19pt; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" width="25" height="17" x:str="   ">
										<span style="mso-spacerun: yes">
												<font face="ＭＳ ゴシック" size="2">
														<strong>   </strong>
												</font>
										</span>
								</td>
								<td class="xl45" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 38pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width="51">
										<font face="ＭＳ ゴシック" size="2">
												<strong>EMPNO</strong>
										</font>
								</td>
								<td class="xl45" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 38pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width="51">
										<font face="ＭＳ ゴシック" size="2">
												<strong>ENAME</strong>
										</font>
								</td>
								<td class="xl45" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 47pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width="62">
										<font face="ＭＳ ゴシック" size="2">
												<strong>JOB</strong>
										</font>
								</td>
								<td class="xl45" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 29pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width="38">
										<font face="ＭＳ ゴシック" size="2">
												<strong>MGR</strong>
										</font>
								</td>
								<td class="xl45" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 61pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width="81">
										<font face="ＭＳ ゴシック" size="2">
												<strong>HIREDATE</strong>
										</font>
								</td>
								<td class="xl45" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 46pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width="61">
										<font face="ＭＳ ゴシック" size="2">
												<strong>SAL</strong>
										</font>
								</td>
								<td class="xl45" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 46pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width="61">
										<font face="ＭＳ ゴシック" size="2">
												<strong>COMM</strong>
										</font>
								</td>
								<td class="xl45" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 43pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width="57">
										<strong>
												<font face="ＭＳ ゴシック" size="2">DEPTNO</font>
										</strong>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl33" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">1</font>
								</td>
								<td class="xl33" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7499</font>
								</td>
								<td class="xl43" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">ALLEN</font>
								</td>
								<td class="xl34" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: windowtext; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">SALESMAN</font>
								</td>
								<td class="xl37" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7698</font>
								</td>
								<td class="xl35" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: windowtext; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29637">
										<font face="ＭＳ ゴシック" size="2">1981/02/20</font>
								</td>
								<td class="xl40" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">1600.00</font>
								</td>
								<td class="xl36" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: windowtext; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">300.00</font>
								</td>
								<td class="xl37" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">30</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">2</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7521</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">WARD</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">SALESMAN</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7698</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29639">
										<font face="ＭＳ ゴシック" size="2">1981/02/22</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">1250.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">500.00</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">30</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">3</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7566</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">JONES</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">MANAGER</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7839</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29678">
										<font face="ＭＳ ゴシック" size="2">1981/04/02</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">2975.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">
										</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">20</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">4</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7654</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">MARTIN</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">SALESMAN</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7698</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29857">
										<font face="ＭＳ ゴシック" size="2">1981/09/28</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">1250.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">1400.00</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">30</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">5</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7698</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">BLAKE</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">MANAGER</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7839</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29707">
										<font face="ＭＳ ゴシック" size="2">1981/05/01</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">2850.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">
										</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">30</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">6</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7782</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">CLARK</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">MANAGER</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7839</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29746">
										<font face="ＭＳ ゴシック" size="2">1981/06/09</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">2450.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">
										</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">10</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">7</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7788</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">SCOTT</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">ANALYST</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7566</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="31886">
										<font face="ＭＳ ゴシック" size="2">1987/04/19</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">3000.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">
										</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">20</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">8</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7839</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">KING</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">PRESIDENT</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">　</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29907">
										<font face="ＭＳ ゴシック" size="2">1981/11/17</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">5000.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">
										</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">10</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">9</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7844</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">TURNER</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">SALESMAN</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7698</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29837">
										<font face="ＭＳ ゴシック" size="2">1981/09/08</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">1500.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">0.00</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">30</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">10</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7876</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">ADAMS</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">CLERK</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7788</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="31920">
										<font face="ＭＳ ゴシック" size="2">1987/05/23</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">1100.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">
										</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">20</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">11</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7900</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">JAMES</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">CLERK</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7698</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29923">
										<font face="ＭＳ ゴシック" size="2">1981/12/03</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">950.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">
										</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">30</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">12</font>
								</td>
								<td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7902</font>
								</td>
								<td class="xl44" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">FORD</font>
								</td>
								<td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">ANALYST</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7566</font>
								</td>
								<td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="29923">
										<font face="ＭＳ ゴシック" size="2">1981/12/03</font>
								</td>
								<td class="xl41" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">3000.00</font>
								</td>
								<td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">
										</font>
								</td>
								<td class="xl38" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">20</font>
								</td>
						</tr>
						<tr style="HEIGHT: 12.75pt" height="17">
								<td class="xl29" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height="17">
										<font face="ＭＳ ゴシック" size="2">13</font>
								</td>
								<td class="xl29" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7934</font>
								</td>
								<td class="xl24" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">MILLER</font>
								</td>
								<td class="xl30" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">
										<font face="ＭＳ ゴシック" size="2">CLERK</font>
								</td>
								<td class="xl39" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">7782</font>
								</td>
								<td class="xl31" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" align="right" x:num="29974">
										<font face="ＭＳ ゴシック" size="2">1982/01/23</font>
								</td>
								<td class="xl42" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">1300.00</font>
								</td>
								<td class="xl32" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:str="">
										<font face="ＭＳ ゴシック" size="2">　</font>
								</td>
								<td class="xl39" style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: #ece9d8; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" align="right" x:num="">
										<font face="ＭＳ ゴシック" size="2">10</font>
								</td>
						</tr>
				</tbody>
		</table>
		<br />执行<br />SQL&gt; select count(*) from emp where empno not in ( select mgr from emp );<br />COUNT(*)<br />----------<br />         0<br />SQL&gt; select count(*) from emp T1<br />  2  where not exists ( select null from emp T2 where t2.mgr = t1.empno ); -- 这里子查询中取出null并没有什么特殊作用，只是表示取什么都一样。<br />COUNT(*)<br />----------<br />         8<br />结果明显不同，问题就出在MGR=null的那条数据上。任何值X not in (null)  结果都不成立。<br />用一个小例子试验一下:<br />select * from dual where dummy not in ( NULL ) -- no rows selected<br />select * from dual where NOT( dummy not in ( NULL ) ) --no rows selected<br />知觉上这两句SQL总有一句会取出数据的，但是实际上都没有。SQL中逻辑表达式的值可以有三种结果（true false null）而null相当于false.<br /><br /><br /><img src ="http://www.blogjava.net/terry-zj/aggbug/41662.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2006-04-18 16:01 <a href="http://www.blogjava.net/terry-zj/archive/2006/04/18/41662.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL优化是重点(转载)</title><link>http://www.blogjava.net/terry-zj/archive/2006/03/30/38291.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Thu, 30 Mar 2006 09:32:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2006/03/30/38291.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/38291.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2006/03/30/38291.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/38291.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/38291.html</trackback:ping><description><![CDATA[
		<p>信息系统访问量又不大，瓶颈一般不会出现在应用层，极有可能在数据库这一层，不用急着看程序。先找出逻辑读取次数最多的SQL，硬盘读取次数最多的SQL，找到SQL，对于SQL进行优化。看看有没有发生全表扫描的地方。 <br />一般发生全表扫描，极有可能是没有建立合理的索引，或者索引由于左边引用函数或其它原因造成索引失效。 <br />对于运行一年多的系统，最好要自己写一个自动重建索引的程序，定时重建索引。 <br />或者使用TOAD工具帮你重建索引。 </p>
		<p>另外在看一下数据库的CPU占用率，如果占用率在经常在80%－100%，那一定要是SQL或存储过程及trigger中写的不好。 </p>
		<p>不需要从应用层找SQL，方向性错误，太累，也看不出效果。 <br />而应当使用pl/SQL, toad等工具，分析出最bad的SQL语句，一看到这些语句后，再修改应用层的查询就是了。又快又方便。 </p>
		<p> </p>
		<p>-- 逻辑读多的SQL <br />select * from (select buffer_gets, sql_text <br />from v$sqlarea <br />where buffer_gets &gt; 500000 <br />order by buffer_gets desc) where rownum&lt;=30; </p>
		<p>-- 执行次数多的SQL <br />select sql_text,executions from <br />(select sql_text,executions from v$sqlarea order by executions desc) <br />where rownum&lt;81; </p>
		<p>-- 读硬盘多的SQL <br />select sql_text,disk_reads from <br />(select sql_text,disk_reads from v$sqlarea order by disk_reads desc) <br />where rownum&lt;21; </p>
		<p>-- 排序多的SQL <br />select sql_text,sorts from <br />(select sql_text,sorts from v$sqlarea order by sorts desc) <br />where rownum&lt;21; </p>
		<p>--分析的次数太多，执行的次数太少，要用绑变量的方法来写sql <br />set pagesize 600; <br />set linesize 120; <br />select substr(sql_text,1,80) "sql", count(*), sum(executions) "totexecs" <br />from v$sqlarea <br />where executions &lt; 5 <br />group by substr(sql_text,1,80) <br />having count(*) &gt; 30 <br />order by 2;<br /><br />转载地址 <a href="http://forum.javaeye.com/viewtopic.php?t=19464">http://forum.javaeye.com/viewtopic.php?t=19464</a></p>
<img src ="http://www.blogjava.net/terry-zj/aggbug/38291.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2006-03-30 17:32 <a href="http://www.blogjava.net/terry-zj/archive/2006/03/30/38291.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PL/SQL支持嵌套事务</title><link>http://www.blogjava.net/terry-zj/archive/2006/01/27/29303.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Fri, 27 Jan 2006 08:20:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2006/01/27/29303.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/29303.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2006/01/27/29303.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/29303.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/29303.html</trackback:ping><description><![CDATA[<P><STRONG>使用场景:</STRONG> <BR>当一个PL/SQL程序执行出错 需要输出log信息到数据库表中的时候 就会遇到这个难题.<BR>log的内容要提交到表中 但是前面出错的内容却不能提交.虽然我们可以在出错时先Rollback 等log好了<BR>再commit.但是这样毕竟比较麻烦.实际上PL/SQL本身支持嵌套事务.<BR>看下面的小例子:<BR>CREATE OR REPLACE procedure Test1<BR>as<BR><STRONG>PRAGMA AUTONOMOUS_TRANSACTION; -- </STRONG>关键就是这句<BR>begin<BR>--set transaction read write;<BR>insert into aaa values(1,4,7);<BR>commit;<BR>end;<BR>/</P>
<P>CREATE OR REPLACE procedure Test2<BR>as<BR>begin<BR>--set transaction read write;<BR>insert into aaa values(2,5,8);<BR>Test1;<BR>insert into aaa values(3,6,9);<BR>rollback;<BR>end;<BR>/<BR>当execute Test2完了时在AAA表中插入了一行（1，4，7）。<BR><BR>--------------------------------------------------------------------------------------------------------------------------<BR><STRONG>理论知识:</STRONG><BR>AUTONOMOUS TRANSACTION(自治事务)的介绍:<BR><BR>在基于低版本的ORACLE做一些项目的过程中,有时会遇到一些头疼的问题.,比如想在执行当前一个由多个DML组成的transaction(事务)时,为每一步DML记录一些信息到跟踪表中,由于事务的原子性,这些跟踪信息的提交将决定于主事务的commit或rollback. 这样一来写程序的难度就增大了, 程序员不得不把这些跟踪信息记录到类似数组的结构中,然后在主事务结束后把它们存入跟踪表.哎,真是麻烦!</P>
<P>有没有一个简单的方法解决类似问题呢？</P>
<P>ORACLE8i的AUTONOMOUS TRANSACTION(自治事务，以下AT)是一个很好的回答。</P>
<P>AT 是由主事务(以下MT)调用但是独立于它的事务。在AT被调用执行时，MT被挂起，在AT内部，一系列的DML可以被执行并且commit或rollback.</P>
<P>注意由于AT的独立性，它的commit和rollback并不影响MT的执行效果。在AT执行结束后，主事务获得控制权，又可以继续执行了。</P>
<P>如何实现AT的定义呢？我们来看一下它的语法。其实非常简单。</P>
<P>只需下列PL/SQL的声明部分加上PRAGMA AUTONOMOUS_TRANSACTION 就可以了。</P>
<P>1．&nbsp; 顶级的匿名PL/SQL块</P>
<P>2．&nbsp; Functions 或 Procedure（独立声明或声明在package中都可）</P>
<P>3．&nbsp; SQL Object Type的方法</P>
<P>4．&nbsp; 触发器。</P>
<P>&nbsp;&nbsp;比如：</P>
<P>&nbsp;在一个独立的procedure中声明AT</P>
<P>CREATE OR REPLACE PROCEDURE </P>
<P>&nbsp;&nbsp; Log_error(error_msg IN VARCHAR2(100))</P>
<P>IS</P>
<P>&nbsp;&nbsp; PRAGMA AUTONOMOUS_TRANSACTION;</P>
<P>BEGIN</P>
<P>&nbsp;&nbsp; Insert into Error_log values ( sysdate,error_msg);</P>
<P>&nbsp;&nbsp; COMMIT;</P>
<P>END;</P>
<P>下面我们来看一个例子，（win2000 advanced server + oracle8.1.6 , connect as scott）</P>
<P>建立一个表:</P>
<P>create table msg (msg varchar2(120));</P>
<P>首先,用普通的事务写个匿名PL/SQL块：</P>
<P>&nbsp;declare </P>
<P>&nbsp;&nbsp; cnt&nbsp; number := -1;&nbsp;&nbsp; --} Global variables </P>
<P>&nbsp;&nbsp; procedure local is </P>
<P>&nbsp;&nbsp; begin </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select count(*) into cnt from msg; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbms_output.put_line('local: # of rows is '||cnt); </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert into msg values ('New Record'); </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; commit; </P>
<P>&nbsp;&nbsp; end; </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp; begin </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete from msg ;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; commit;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert into msg values ('Row 1'); </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select count(*) into cnt from msg; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbms_output.put_line('main: # of rows is '||cnt); </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rollback; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert into msg values ('Row 2'); </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; commit; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select count(*) into cnt from msg; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbms_output.put_line('main: # of rows is '||cnt); </P>
<P>&nbsp;&nbsp; end; </P>
<P>运行结果(注意打开serveroutput)</P>
<P>local: # of rows is 1&nbsp;&nbsp; -&gt; 子程序local中可以’看到’主匿名块中的uncommitted记录 </P>
<P>main: # of rows is 2&nbsp;&nbsp;&nbsp; -&gt; 主匿名块可以’看到’2条记录(它们都是被local commit掉的) </P>
<P>local: # of rows is 2&nbsp;&nbsp; -&gt; 子程序local首先’看到’2条记录,然后又commit了第三条记录</P>
<P>local: # of rows is 4&nbsp;&nbsp; -&gt; 子程序local又’看到’了新增加的记录(它们都是被local commit掉的),然后又commit了第五条记录</P>
<P>main: # of rows is 5&nbsp;&nbsp;&nbsp; -&gt; 主匿名块最后’看到’了所有的记录.</P>
<P>从这个例子中,我们看到COMMIT和ROLLBACK的位置无论是在主匿名块中或者在子程序中,都会影响到整个当前事务.</P>
<P>现在用AT改写一下匿名块中的procedure local:</P>
<P>... </P>
<P>&nbsp;&nbsp; procedure local is </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pragma AUTONOMOUS_TRANSACTION; </P>
<P>&nbsp;&nbsp; begin </P>
<P>... </P>
<P>重新运行(注意打开serveroutput)</P>
<P>local: # of rows is 0&nbsp;&nbsp; -&gt; 子程序local中无法可以’看到’主匿名块中的uncommitted记录 (因为它是独立的)</P>
<P>main: # of rows is 2&nbsp;&nbsp;&nbsp; -&gt; 主匿名块可以’看到’2条记录,但只有一条是被commited.</P>
<P>local: # of rows is 1&nbsp;&nbsp; -&gt; 子程序local中可以’看到’它前一次commit的记录,但是主匿名块中的记录已经被提前rollback了</P>
<P>local: # of rows is 3&nbsp;&nbsp; -&gt; 子程序local 中可以’看到’3条记录包括主匿名块commit的记录</P>
<P>main: # of rows is 4&nbsp;&nbsp;&nbsp; -&gt;主匿名块最后’看到’了所有的记录.</P>
<P>很明显,AT是独立的,在它执行时,MT被暂停了. AT的COMMIT,ROLLBACK并不影响MT的执行.</P>
<P>运用AT时,有一些注意事项,简单列举如下:</P>
<P>1.&nbsp;&nbsp;&nbsp;&nbsp; 在匿名PL/SQL块中,只有顶级的匿名PL/SQL块可以被设为AT</P>
<P>2.&nbsp;&nbsp;&nbsp;&nbsp; 如果AT试图访问被MT控制的资源,可能有deadlock发生. </P>
<P>3.&nbsp;&nbsp;&nbsp;&nbsp; Package 不能被声明为AT,只有package所拥有的function和procedure 才能声明为AT</P>
<P>4.&nbsp;&nbsp;&nbsp;&nbsp; AT程序必须以commit 或rollback结尾,否则会产生Oracle错误ORA-06519: active autonomous transaction detected and rolled back</P>
<P>在程序开发时,如果充分运用AUTONOMOUS TRANSACTION的特性,一定能取得事倍功半的效果.</P><img src ="http://www.blogjava.net/terry-zj/aggbug/29303.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2006-01-27 16:20 <a href="http://www.blogjava.net/terry-zj/archive/2006/01/27/29303.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL and PL/SQL</title><link>http://www.blogjava.net/terry-zj/archive/2005/12/06/22794.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Tue, 06 Dec 2005 14:29:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2005/12/06/22794.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/22794.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2005/12/06/22794.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/22794.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/22794.html</trackback:ping><description><![CDATA[<P><FONT size=2>SQL and PL/SQL <BR>&nbsp;<BR>Oracle 的内置函数提供了全角和半角字符转换的功能:<BR>SELECT TO_SINGLE_BYTE('１２３ａｂｃＸＹＺ') FROM dual -- 123abcXYZ<BR>SELECT TO_MULTI_BYTE('123abcXYZ') FROM dual -- １２３ａｂｃＸＹＺ</FONT></P>
<P><FONT size=2>一些PL/SQL的小特性:</FONT></P>
<P><FONT size=2>DECLARE<BR>&nbsp;&nbsp;&nbsp; -- Local variables here<BR>&nbsp;&nbsp;&nbsp; i&nbsp;&nbsp; INTEGER;<BR>&nbsp;&nbsp;&nbsp; idx VARCHAR2(2000);<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; TYPE word_list IS TABLE OF idx%TYPE INDEX BY idx%TYPE;<BR>&nbsp;&nbsp;&nbsp; the_list word_list;</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; wChar VARCHAR2(2000);</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; wTmp varchar2(2000);<BR>&nbsp;&nbsp;&nbsp; num1 NUMBER(12);<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; chr1 CHAR(5);<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; FUNCTION tstChar(inputChr IN CHAR) RETURN NUMBER IS <BR>&nbsp;&nbsp;&nbsp; BEGIN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbms_output.put_line('|' || inputChr || '|');<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RETURN 1;<BR>&nbsp;&nbsp;&nbsp; END;<BR>BEGIN<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Max Min value<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; num1 := greatest(100,200,300,210,120,99);<BR>&nbsp;&nbsp;&nbsp; dbms_output.put_line(num1); -- 300<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; wTmp := greatest('abc','bcd','cde','xxx','zzz','yyy');<BR>&nbsp;&nbsp;&nbsp; dbms_output.put_line(wTmp); -- zzz<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; wTmp := least('abc','bcd','cde','xxx','zzz','yyy');<BR>&nbsp;&nbsp;&nbsp; dbms_output.put_line(wTmp); -- abc<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; substr<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; wTmp := 'abcdefg';<BR>&nbsp;&nbsp;&nbsp; wTmp := substr(wTmp,-3,2);<BR>&nbsp;&nbsp;&nbsp; dbms_output.put_line(wTmp); -- ef<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lpad<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; wTmp := lpad(wTmp,10,'?');<BR>&nbsp;&nbsp;&nbsp; dbms_output.put_line(wTmp); -- ????????ef</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; wTmp := NULL;<BR>&nbsp;&nbsp;&nbsp; wTmp := lpad(wTmp,10,'?');<BR>&nbsp;&nbsp;&nbsp; dbms_output.put_line(wTmp); -- null</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length of char<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; chr1 := 'aaa';<BR>&nbsp;&nbsp;&nbsp; num1 := tstChar(chr1);<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; table indexed by varchar2<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; dbms_output.put_line('------ test 1 collection index by varchar2------');<BR>&nbsp;&nbsp;&nbsp; the_list('key1') := 'value1';<BR>&nbsp;&nbsp;&nbsp; the_list('key2') := 'value2';<BR>&nbsp;&nbsp;&nbsp; the_list('key3') := 'value3';<BR>&nbsp;&nbsp;&nbsp; the_list('key0') := NULL;</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; idx := the_list.FIRST();</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; WHILE idx IS NOT NULL LOOP<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(idx || '&nbsp;&nbsp; ' || the_list(idx));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idx := the_list.NEXT(idx);<BR>&nbsp;&nbsp;&nbsp; END LOOP;</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; IF the_list.EXISTS('aaa') THEN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('aaa');<BR>&nbsp;&nbsp;&nbsp; ELSE<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('no aaa');<BR>&nbsp;&nbsp;&nbsp; END IF;</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(the_list.COUNT);<BR>&nbsp;&nbsp;&nbsp; the_list.delete('key1');<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(the_list.COUNT);</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; handle null<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; dbms_output.put_line('------ test 2&nbsp; handle null------');<BR>&nbsp;&nbsp;&nbsp; idx := NULL;<BR>&nbsp;&nbsp;&nbsp; idx := CASE WHEN idx IS NULL THEN 'is null' WHEN idx IS NOT NULL THEN 'is not null' ELSE 'else' END;<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(idx);</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; idx := NULL;<BR>&nbsp;&nbsp;&nbsp; SELECT decode(idx, NULL, 'is null', 'is not null', 'else')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INTO idx<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM dual;<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(idx);</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; idx := NULL;<BR>&nbsp;&nbsp;&nbsp; idx := REPLACE('old_string_1', NULL, 'replace null');<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(idx);</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; idx := REPLACE('old_string_2', '_', NULL);<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(idx);</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; idx := 'apple' || NULL || NULL || 'sauce';<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(idx);</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 动态sql<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; wChar := 'select to_char(sysdate,''yyyy/mm/dd'') from dual ';<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; execute immediate wChar into idx;<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('test execute immediate = ' || idx);<BR>&nbsp;&nbsp;&nbsp; </FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 隐式光标<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------&nbsp;&nbsp;&nbsp; </FONT></P>
<P><FONT size=2>--&nbsp;&nbsp;&nbsp; for rec in (select *&nbsp; from mststrc21) loop<BR>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('rec = ' || rec.pantpatternno);<BR>--&nbsp;&nbsp;&nbsp; end loop;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trim()<BR>&nbsp;&nbsp;&nbsp; -------------------------------------------------------------&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; --Trim(Leading|Trailing|Both trim_character from trim_source)<BR>&nbsp;&nbsp;&nbsp; idx := TRIM(' abc ');<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('|' || idx || '|');<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; idx := TRIM('　abc　'); -- full space<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('|' || idx || '|');<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; idx := TRIM(leading '　' FROM '　abc　'); -- full space<BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('|' || idx || '|');<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; idx := TRIM(leading 'ab' FROM 'abc'); <BR>&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('|' || idx || '|'); -- ORA-30001: 切捨てセットの文字は1つにする必要があります<BR>&nbsp;&nbsp;&nbsp; <BR>EXCEPTION<BR>&nbsp;&nbsp;&nbsp; WHEN NO_DATA_FOUND THEN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('NO_DATA_FOUND');&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(SQLCODE);&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(SQLERRM);<BR>&nbsp;&nbsp;&nbsp; WHEN TOO_MANY_ROWS THEN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('TOO_MANY_ROWS');&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(SQLCODE);&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(SQLERRM);<BR>&nbsp;&nbsp;&nbsp; WHEN OTHERS THEN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line('OTHERS');&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(SQLCODE);&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dbms_Output.Put_line(SQLERRM);&nbsp;&nbsp;&nbsp; <BR>END;</FONT></P><img src ="http://www.blogjava.net/terry-zj/aggbug/22794.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2005-12-06 22:29 <a href="http://www.blogjava.net/terry-zj/archive/2005/12/06/22794.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>提交一个查询有必要用事务吗?(转载) </title><link>http://www.blogjava.net/terry-zj/archive/2005/12/06/22792.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Tue, 06 Dec 2005 14:25:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2005/12/06/22792.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/22792.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2005/12/06/22792.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/22792.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/22792.html</trackback:ping><description><![CDATA[<H2><FONT size=2>如果只提交一个查询，有必要用事务吗？这个问题之前已经讨论过 </FONT></H2>
<P><A href="http://forum.javaeye.com/viewtopic.php?t=1603"><FONT color=#003366 size=2>http://forum.javaeye.com/viewtopic.php?t=1603</FONT></A><FONT size=2> </FONT></P>
<P><FONT size=2>但是并没有得出明确的结论。先让我们看看事务的定义： </FONT></P>
<P><FONT size=2>引用: </FONT></P>
<P><FONT size=2>Transactions are described in terms of ACID properties, which are as follows: <BR>n Atomic: all changes to the database made in a transaction are rolled back if any <BR>change fails. <BR>n Consistent: the effects of a transaction take the database from one consistent <BR>state to another consistent state. <BR>n Isolated: the intermediate steps in a transaction are not visible to other users of <BR>the database. <BR>n Durable: when a transaction is completed (committed or rolled back), its effects <BR>persist in the database. <BR>&nbsp;</FONT></P>
<P><BR><FONT size=2>即ACID的定义，从上面看来，似乎除了isolated之外，和只读查询都没有关系。那么是否只读查询不需要事务呢？ </FONT></P>
<P><FONT size=2>再看看Oracle对于只读事务的定义： </FONT></P>
<P><FONT size=2>引用: <BR>Read-Only Transactions <BR>By default, Oracle guarantees statement-level read consistency. The set of data returned by a single query is consistent with respect to a single point in time. However, in some situations, you might also require transaction-level read consistency. This is the ability to run multiple queries within a single transaction, all of which are read-consistent with respect to the same point in time, so that queries in this transaction do not see the effects of intervening committed transactions. </FONT></P>
<P><FONT size=2>If you want to run a number of queries against multiple tables and if you are not doing any updating, you prefer a read-only transaction. After indicating that your transaction is read-only, you can run as many queries as you like against any table, knowing that the results of each query are consistent with respect to the same point in time. </FONT></P>
<P><BR><FONT size=2>Oracle默认情况下保证了SQL语句级别的读一致性，即在该条SQL语句执行期间，它只会看到执行前点的数据状态，而不会看到执行期间数据被其他SQL改变的状态。 </FONT></P>
<P><FONT size=2>而Oracle的只读查询(read-only transaction)则保证了事务级别的读一致性，即在该事务范围内执行的多条SQL都只会看到执行前点的数据状态，而不会看到事务期间的任何被其他SQL改变的状态。 </FONT></P>
<P><FONT size=2>因此我们可以得出结论： </FONT></P>
<P><FONT size=2>如果你一次执行单条查询语句，则没有必要启用事务支持，数据库默认支持SQL执行期间的读一致性； <BR>如果你一次执行多条查询语句，例如统计查询，报表查询，在这种场景下，多条查询SQL必须保证整体的读一致性，否则，在前条SQL查询之后，后条SQL查询之前，数据被其他用户改变，则该次整体的统计查询将会出现读数据不一致的状态，此时，应该启用事务支持。 </FONT></P>
<P><BR><FONT size=2>只读事务与读写事务区别 </FONT></P>
<P><FONT size=2>对于只读查询，可以指定事务类型为readonly，即只读事务。由于只读事务不存在数据的修改，因此数据库将会为只读事务提供一些优化手段，例如Oracle对于只读事务，不启动回滚段，不记录回滚log。 </FONT></P>
<P><FONT size=2>在JDBC中，指定只读事务的办法为： <BR>connection.setReadOnly(true); </FONT></P>
<P><FONT size=2>在Hibernate中，指定只读事务的办法为： <BR>session.setFlushMode(FlushMode.NEVER); <BR>此时，Hibernate也会为只读事务提供Session方面的一些优化手段 </FONT></P>
<P><FONT size=2>在Spring的Hibernate封装中，指定只读事务的办法为： <BR>bean配置文件中，prop属性增加“readOnly”</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2>我在MySQL4.1试验了一下，过程和结果如下： </FONT></P>
<P><FONT size=2>数据库：MySQL4.1 <BR>表类型：InnoDB <BR>Spring：1.1.2 <BR>Hibernate：2.1.7 </FONT></P>
<P><FONT size=2>使用Spring的声明式事务管理 </FONT></P>
<P><FONT size=2>试验过程如下： </FONT></P>
<P><FONT size=2>不设置查询方法的事务类型(即不需要事务)：访问查询页面，后台执行Spring的Bean方法，让Hibernate发送select语句，然后手工在MySQL里面修改该记录某字段值，再访问查询页面，发现被修改过的字段值并没有变化，Hibernate输出的log显示，数据库还是把老的字段值返回，而没有返回新的字段值。 </FONT></P>
<P><FONT size=2>设置查询方法的事务类型(只读事务)：访问查询页面，后台执行Spring的Bean方法，让Hibernate发送select语句，然后手工在MySQL里面修改该记录某字段值，再访问查询页面，发现被修改过的字段值已经变化，Hibernate输出的log显示，数据库返回新的字段值。 </FONT></P>
<P><FONT size=2>这个试验说明，至少在MySQL4.1的InnoDB情况下，不使用只读事务的查询将无法读取到数据更新值，必须使用只读事务来保证读记录的数据一致性。这个结果非常令我诧异，和我预期完全两样。 </FONT></P>
<P><FONT size=2>我将在Oracle平台上试试看会有什么样的结果。 </FONT></P>
<P><FONT size=2>BTW: 如果MySQL的表类型改为MyISAM，那么即使不设置事务，也不会出现读数据不一致的现象。</FONT></P>
<P><BR><FONT size=2>oracle有两种方法保证在事务级读数据一致性(Transaction-Level Read Consistency) </FONT></P>
<P><FONT size=2>一是用SET TRANSACTION ISOLATION LEVEL SERIALIZABLE , <BR>当执行这条命令后读数据时会产生一些重复copy, 你也可以做数据修改, 但在大量数据修改的情况下容易造成deadlock或异常, 用commit或rollback将把ISOLATION LEVEL设回为缺省模式read committed, </FONT></P>
<P><BR><FONT size=2>二是用SET TRANSCATION READ ONLY <BR>当执行这条命令时数据库会生成一个快照的latch, 这个latch会耗费一些resource, 如果你想进行数据修改会导致异常. 用commit或rollback会把latch释放掉, 也将把ISOLATION LEVEL设回为缺省模式read committed,</FONT></P><img src ="http://www.blogjava.net/terry-zj/aggbug/22792.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2005-12-06 22:25 <a href="http://www.blogjava.net/terry-zj/archive/2005/12/06/22792.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle9i的全文检索技术</title><link>http://www.blogjava.net/terry-zj/archive/2005/12/06/22790.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Tue, 06 Dec 2005 14:13:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2005/12/06/22790.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/22790.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2005/12/06/22790.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/22790.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/22790.html</trackback:ping><description><![CDATA[<SPAN id=BlogViewId><TR><TD class=ellipse><SPAN class=bvTitle id=subjcns!1pnXmtZJZoGE64AUuta1hh1Q!154><FONT size=2>Oracle9i的全文检索技术<BR></FONT></SPAN><FONT size=2>参考:<BR></FONT><A href="http://www.lc.leidenuniv.nl/awcourse/oracle/"><FONT size=2>Oracle book</FONT></A><BR><A href="http://searchdatabase.techtarget.com.cn/searchdatabase/504969453998440448/20050104/1896262.shtml"><FONT size=2>http://searchdatabase.techtarget.com.cn/searchdatabase/504969453998440448/20050104/1896262.shtml</FONT></A><BR><A href="http://www.e800.com.cn/articles/36/1091788059721_2.html"><FONT size=2>http://www.e800.com.cn/articles/36/1091788059721_2.html</FONT></A><BR><A href="http://www.oracle.com/global/cn/oramag/oracle/04-sep/o54text.html"><FONT size=2>http://www.oracle.com/global/cn/oramag/oracle/04-sep/o54text.html</FONT></A>
<P><FONT size=2>------ Test Oracle text<BR>CREATE TABLE hdocs (<BR>ID NUMBER PRIMARY KEY,<BR>fmt VARCHAR2(10),<BR>text VARCHAR2(80)<BR>);</FONT></P>
<P><FONT size=2>CREATE INDEX hdocsx ON hdocs(text) INDEXTYPE IS ctxsys.CONTEXT<BR>PARAMETERS ('datastore ctxsys.file_datastore<BR>&nbsp;filter ctxsys.inso_filter<BR>&nbsp;format column fmt<BR>');</FONT></P>
<P><FONT size=2>--&nbsp; charset column cset // can set charset</FONT></P>
<P><FONT size=2>INSERT INTO hdocs VALUES(1, 'binary', 'D:\OracleText\Oracle.pdf');<BR>INSERT INTO hdocs VALUES(2, 'text', 'D:\OracleText\1.txt');<BR>INSERT INTO hdocs VALUES(3, 'binary', 'D:\OracleText\mydoc.doc');<BR>COMMIT; </FONT></P>
<P><FONT size=2>select t.*, score(1) from hdocs t WHERE contains(text,'索引タイプの構文', 1) &gt; 0</FONT></P>
<P><FONT size=2>-- 索引の同期化<BR>BEGIN<BR>&nbsp; ctx_ddl.sync_index('hdocsx', '2M');<BR>END;<BR>/</FONT></P>
<P><FONT size=2>-- sync<BR>SET SERVEROUTPUT ON<BR>DECLARE<BR>&nbsp; job NUMBER;<BR>BEGIN<BR>&nbsp; DBMS_JOB.SUBMIT(job, 'ctx_ddl.sync_index(''hdocsx'');', SYSDATE, 'SYSDATE + (3/1440)');<BR>&nbsp; DBMS_OUTPUT.PUT_LINE('job '||job||' has been submitted.');<BR>END;<BR>/</FONT></P>
<P><FONT size=2>-- optimizer <BR>DECLARE <BR>&nbsp; VARIABLE jobno NUMBER;&nbsp; <BR>BEGIN&nbsp; <BR>&nbsp; DBMS_JOB.SUBMIT(:jobno,'ctx_ddl.optimize_index(''hdocsx'',''FULL'');', SYSDATE, 'SYSDATE + 1');&nbsp; <BR>&nbsp; <BR>&nbsp; COMMIT;&nbsp; <BR>END;<BR>/<BR><BR></FONT><FONT size=2>create or replace procedure syncidx<BR>is<BR>begin<BR>execute immediate<BR>'alter index hdocsx rebuild online' ||<BR>' parameters ( ''sync'' )' ;<BR>execute immediate<BR>'alter index hdocsx rebuild online' ||<BR>' parameters ( ''optimize full maxtime unlimited'' )' ;<BR>end syncidx;<BR>/<BR><BR></FONT><FONT size=2>SET SERVEROUTPUT ON<BR>DECLARE<BR>&nbsp; job NUMBER;<BR>BEGIN<BR>&nbsp; DBMS_JOB.SUBMIT(job, 'syncidx;', SYSDATE, 'SYSDATE + (3/1440)');<BR>&nbsp; DBMS_JOB.RUN(job);<BR>&nbsp; DBMS_OUTPUT.PUT_LINE('job '||job||' has been submitted.');<BR>END;<BR>/</FONT></P></TD></TR></SPAN><img src ="http://www.blogjava.net/terry-zj/aggbug/22790.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2005-12-06 22:13 <a href="http://www.blogjava.net/terry-zj/archive/2005/12/06/22790.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle小特性</title><link>http://www.blogjava.net/terry-zj/archive/2005/12/06/22788.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Tue, 06 Dec 2005 14:08:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2005/12/06/22788.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/22788.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2005/12/06/22788.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/22788.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/22788.html</trackback:ping><description><![CDATA[<SPAN id=BlogViewId><TR><TD class=ellipse><SPAN class=bvTitle id=subjcns!1pnXmtZJZoGE64AUuta1hh1Q!152><FONT size=2>Oracle小特性</FONT></SPAN></TD></TR><TR><TD class=bvh8></TD></TR><TR><TD id=msgcns!1pnXmtZJZoGE64AUuta1hh1Q!152>
<P><FONT size=2>特性1: PL/SQL中 select into 一个变量和直接给这个个变量赋值效果不同.<BR>DECLARE<BR>&nbsp;&nbsp;&nbsp; vTmp VARCHAR2(1000);<BR>BEGIN<BR>&nbsp;&nbsp;&nbsp; SELECT to_char(sysdate,'EE','NLS_CALENDAR=''Japanese Imperial''') -- 年号<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INTO vTmp<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM dual; <BR>END;</FONT></P>
<P><FONT size=2>结果: PL/SQL procedure successfully completed</FONT></P>
<P><FONT size=2>DECLARE<BR>&nbsp; vTmp VARCHAR2(1000);<BR>BEGIN<BR>&nbsp; vTmp := to_char(sysdate,'EE','NLS_CALENDAR=''Japanese Imperial''');&nbsp; -- vTmp := '平成'<BR>END;</FONT></P>
<P><FONT size=2>结果: ORA-06502: PL/SQL: 数値または値のエラーが発生しました<BR>ORA-06512: 行4</FONT></P>
<P><FONT size=2>特性2:用一个record变量直接修改表的记录.record中字段和表的字段的对应关系.<BR>create table EMP<BR>(<BR>&nbsp; EMPNO&nbsp;&nbsp;&nbsp; NUMBER(4) not null,<BR>&nbsp; ENAME&nbsp;&nbsp;&nbsp; VARCHAR2(10),<BR>&nbsp; JOB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VARCHAR2(9),<BR>&nbsp; MGR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NUMBER(4),<BR>&nbsp; HIREDATE DATE,<BR>&nbsp; SAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NUMBER(7,2),<BR>&nbsp; COMM&nbsp;&nbsp;&nbsp;&nbsp; NUMBER(7,2),<BR>&nbsp; DEPTNO&nbsp;&nbsp; NUMBER(2)<BR>)</FONT></P>
<P><FONT size=2>create table EMP_2<BR>(<BR>&nbsp; EMPNO&nbsp;&nbsp;&nbsp; NUMBER(4) not null,<BR>&nbsp; JOB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VARCHAR2(9),<BR>&nbsp; ENAME&nbsp;&nbsp;&nbsp; VARCHAR2(10),<BR>&nbsp; MGR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NUMBER(4),<BR>&nbsp; HIREDATE DATE,<BR>&nbsp; COMM&nbsp;&nbsp;&nbsp;&nbsp; NUMBER(7,2),<BR>&nbsp; SAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NUMBER(7,2),<BR>&nbsp; DEPTNO&nbsp;&nbsp; NUMBER(2)<BR>)</FONT></P>
<P><FONT size=2>DECLARE<BR>&nbsp;&nbsp;&nbsp; rec EMP_2%ROWTYPE;<BR>BEGIN <BR>&nbsp;&nbsp;&nbsp; SELECT * <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INTO rec<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM emp<BR>&nbsp;&nbsp;&nbsp;&nbsp; WHERE empno = 9999 ; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; INSERT INTO EMP_2 VALUES rec;<BR>END;</FONT></P>
<P><FONT size=2>EMP<BR>&nbsp;&nbsp; &nbsp;EMPNO&nbsp;ENAME&nbsp;JOB&nbsp;MGR&nbsp;HIREDATE&nbsp;SAL&nbsp;COMM&nbsp;DEPTNO<BR>1&nbsp;9999&nbsp;terry1&nbsp;CLERK&nbsp;7782&nbsp;1982/01/23&nbsp;1300.00&nbsp;&nbsp;10</FONT></P>
<P><FONT size=2>EMP_2<BR>&nbsp;&nbsp; &nbsp;EMPNO&nbsp;JOB&nbsp;ENAME&nbsp;MGR&nbsp;HIREDATE&nbsp;COMM&nbsp;SAL&nbsp;DEPTNO<BR>1&nbsp;9999&nbsp;terry1&nbsp;CLERK&nbsp;7782&nbsp;1982/01/23&nbsp;1300.00&nbsp;&nbsp;10</FONT></P>
<P><FONT size=2>特性3:取日本年号</FONT></P>
<P><FONT size=2>SELECT to_char(SYSDATE, 'EEYY MONTH DAY&nbsp; MM/DD HH24:MI:SS', 'NLS_CALENDAR=''Japanese Imperial''') FROM dual<BR>&gt;&gt;&gt;<BR>平成17 4月&nbsp; 火曜日&nbsp; 04/19 17:34:15</FONT></P></TD></TR></SPAN><img src ="http://www.blogjava.net/terry-zj/aggbug/22788.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2005-12-06 22:08 <a href="http://www.blogjava.net/terry-zj/archive/2005/12/06/22788.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle SQL依然无可替代--《Mastering Oracle SQL》(转载)</title><link>http://www.blogjava.net/terry-zj/archive/2005/12/06/22786.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Tue, 06 Dec 2005 14:04:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2005/12/06/22786.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/22786.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2005/12/06/22786.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/22786.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/22786.html</trackback:ping><description><![CDATA[<SPAN id=BlogViewId><TR><TD class=ellipse><SPAN class=bvTitle id=subjcns!1pnXmtZJZoGE64AUuta1hh1Q!144><FONT size=2>转载 Oracle SQL依然无可替代--《Mastering Oracle SQL》</FONT></SPAN></TD></TR><TR><TD class=bvh8></TD></TR><TR><TD id=msgcns!1pnXmtZJZoGE64AUuta1hh1Q!144>
<P><FONT size=2>选择自 </FONT><A id=ArticleTitle1_ArticleTitle1_AuthorLink href="http://dev.csdn.net/user/calvinxiu"><FONT size=2>calvinxiu</FONT></A><FONT size=2> 的 Blog&nbsp; </FONT><A href="http://dev.csdn.net/user/calvinxiu"><FONT size=2>http://dev.csdn.net/user/calvinxiu</FONT></A></P>
<P><FONT size=2>天寒地冻，呆在家里又读完了《Mastering Oracle SQL》2nd，发现Oracle的功能还是很强悍，光函数就有两百个，HSQL是很难比拟的。接下来的硬骨头，看来要么冒险用Hibernate3.0 的SQL Mapping功能，要么就自己跑JDBC组装VO了。 </FONT></P>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><FONT size=2><STRONG>1.报表合计专用的Rollup函数<BR></STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 销售报表<BR>&nbsp; 广州&nbsp;&nbsp;&nbsp;&nbsp; 1月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2000元<BR>&nbsp; 广州&nbsp;&nbsp;&nbsp;&nbsp; 2月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2500元<BR>&nbsp; 广州&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4500元<BR>&nbsp; 深圳&nbsp;&nbsp;&nbsp;&nbsp; 1月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1000元<BR>&nbsp; 深圳&nbsp;&nbsp;&nbsp;&nbsp; 2月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2000元<BR>&nbsp; 深圳&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3000元<BR>&nbsp; 所有地区&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7500元<BR></FONT></DIV>
<DIV><BR><FONT size=2>以往的查询SQL:<BR>Select&nbsp; area,month,sum(money) from SaleOrder group by area,month<BR>然后广州，深圳的合计和所有地区合计都需要在程序里自行累计</FONT></DIV>
<DIV><BR><FONT size=2>1.其实可以使用如下SQL:&nbsp;&nbsp; Select area,month,sum(total_sale) from SaleOrder group by <STRONG>rollup</STRONG>(area,month)就能产生和报表一模一样的纪录</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>2.如果year不想累加，可以写成&nbsp;&nbsp; Select year,month,area,sum(total_sale) from SaleOrder group by <STRONG>year</STRONG>, <STRONG>rollup</STRONG>(month,area)&nbsp;&nbsp;&nbsp;另外Oracle 9i还支持如下语法:&nbsp;&nbsp; Select year,month,area,sum(total_sale) from SaleOrder group by rollup(<STRONG>(year,month),</STRONG>area)</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>3.如果使用Cube(area,month)而不是RollUp(area,month)，除了获得每个地区的合计之外，还将获得每个月份的合计，在报表最后显示。</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>4.Grouping让合计列更好读<BR>&nbsp; RollUp在显示广州合计时，月份列为NULL，但更好的做法应该是显示为"所有月份"<BR>&nbsp; Grouping就是用来判断当前Column是否是一个合计列，1为yes，然后用Decode把它转为"所有月份"&nbsp; Select&nbsp; <STRONG>Decode(Grouping(area),1,'所有地区',area)</STRONG> area,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Decode(Grouping(month),1,'所有月份',month),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum(money)<BR>&nbsp;&nbsp;From SaleOrder&nbsp;<BR>&nbsp;&nbsp;Group by RollUp(area,month);</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2><STRONG>2.对多级层次查询的start with.....connect by</STRONG><BR>&nbsp;&nbsp; 比如人员组织,产品类别,Oracle提供了很经典的方法</FONT></DIV>
<DIV><FONT size=2>SELECT <STRONG>LEVE</STRONG>L, name, emp_id,manager_emp_id<BR>FROM employee<BR><STRONG>START WITH </STRONG>manager_emp_id is null<BR><STRONG>CONNECT BY PRIOR </STRONG>emp_id = manager_emp_id;</FONT></DIV>
<DIV><FONT size=2>上面的语句demo了全部的应用,start with指明从哪里开始遍历树,如果从根开始,那么它的manager应该是Null,如果从某个职员开始,可以写成emp_id='11'<BR>CONNECT BY 就是指明父子关系,注意PRIOR位置<BR>另外还有一个LEVEL列,显示节点的层次</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2><STRONG>3.更多报表/分析决策功能</STRONG><BR>3.1 分析功能的基本结构<BR>&nbsp;&nbsp;&nbsp;&nbsp; 分析功能() over( partion子句,order by子句,窗口子句)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;概念上很难讲清楚,还是用例子说话比较好.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>3.2 Row_Number 和 Rank, DENSE_Rank<BR>&nbsp;&nbsp;&nbsp; 用于选出Top 3 sales这样的报表<BR>&nbsp;&nbsp;&nbsp; 当两个业务员可能有相同业绩时,就要使用Rank和Dense_Rank<BR>&nbsp;&nbsp;&nbsp; 比如<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 金额&nbsp;&nbsp;&nbsp; RowNum&nbsp; Rank&nbsp; Dense_Rank<BR>&nbsp;&nbsp;&nbsp; 张三 4000元&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<BR>&nbsp;&nbsp;&nbsp; 李四 3000元&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<BR>&nbsp;&nbsp;&nbsp; 钱五 2000元&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<BR>&nbsp;&nbsp;&nbsp; 孙六 2000元&nbsp;&nbsp;&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<BR>&nbsp;&nbsp;&nbsp; 丁七 1000元&nbsp;&nbsp;&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; 这时,应该把并列第三的钱五和孙六都选进去,所以用Ranking功能比RowNumber保险.至于Desnse还是Ranking就看具体情况了。</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; SELECT salesperson_id, SUM(tot_sales) sp_sales,<BR>&nbsp;&nbsp;&nbsp; <STRONG>RANK( ) OVER </STRONG>(ORDER BY SUM(tot_sales) DESC) sales_rank<BR>&nbsp;&nbsp;&nbsp; FROM orders<BR>&nbsp;&nbsp;&nbsp; GROUP BY salesperson_id</FONT></DIV>
<DIV><FONT size=2>3.3 NTILE 把纪录平分成甲乙丙丁四等 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 比如我想取得前25%的纪录,或者把25%的纪录当作同一个level平等对待,把另25%当作另一个Level平等对待</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; SELECT cust_nbr, SUM(tot_sales) cust_sales,<BR>&nbsp;&nbsp;&nbsp; <STRONG>NTILE(4) OVER </STRONG>(ORDER BY SUM(tot_sales) DESC) sales_quartile<BR>&nbsp;&nbsp;&nbsp; FROM orders<BR>&nbsp;&nbsp;&nbsp; GROUP BY cust_nbr<BR>&nbsp;&nbsp;&nbsp; ORDER BY 3,2 DESC;NTITLE(4)把纪录以 SUM(tot_sales)排序分成4份.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>3.4 辅助分析列和Windows Function<BR>&nbsp;&nbsp;&nbsp;&nbsp; 报表除了基本事实数据外,总希望旁边多些全年总销量,到目前为止的累计销量,前后三个月的平均销量这样的列来参考.<BR>&nbsp;&nbsp;&nbsp; 这种前后三个月的平均和到目前为止的累计销量就叫windows function, 见下例&nbsp;&nbsp;&nbsp; SELECT month, SUM(tot_sales) monthly_sales,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUM(SUM(tot_sales)) OVER (ORDER BY month<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <STRONG>ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW</STRONG>) max_preceeding<BR>&nbsp;&nbsp;&nbsp; FROM orders<BR>&nbsp;&nbsp;&nbsp; GROUP BY month<BR>&nbsp;&nbsp;&nbsp; ORDER BY month;<BR><BR><BR><BR>&nbsp;&nbsp;&nbsp; SELECT month, SUM(tot_sales) monthly_sales,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AVG(SUM(tot_sales)) OVER (ORDER BY month <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <STRONG>ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING</STRONG>) rolling_avg&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; FROM orders<BR>&nbsp;&nbsp;&nbsp; GROUP BY month<BR>&nbsp;&nbsp;&nbsp; ORDER BY month;</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; Windows Function的关键就是Windows子句的几个取值<BR>&nbsp;&nbsp;&nbsp; 1 PRECEDING 之前的一条记录<BR>&nbsp;&nbsp;&nbsp; 1 FOLLOWING 之后的一条记录<BR>&nbsp;&nbsp;&nbsp; UNBOUNDED PRECEDING 之前的所有记录<BR>&nbsp;&nbsp;&nbsp; CURRENT ROW 当前纪录</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2><STRONG>4.SubQuery总结</STRONG><BR>&nbsp; SubQuery天天用了,理论上总结一下.SubQuery 分三种<BR>&nbsp; 1.Noncorrelated 子查询&nbsp;&nbsp; 最普通的样式.<BR>&nbsp; 2.Correlated Subqueries&nbsp; 把父查询的列拉到子查询里面去,头一回cyt教我的时候理解了半天.<BR>&nbsp; 3.Inline View&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 也被当成最普通的样式用了.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp; 然后Noncorrelated 子查询又有三种情况<BR>&nbsp; 1.返回一行一列&nbsp;&nbsp;&nbsp; where price &lt; (select max(price) from goods )<BR>&nbsp;&nbsp;2.返回多行一列&nbsp;&nbsp;&nbsp; where price&gt;= ALL (select price from goods where type=2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or where NOT price&lt; ANY(select price from goods where type=2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;最常用的IN其实就是=ANY()<BR>&nbsp; 3.返回多行多列&nbsp;&nbsp;&nbsp; 一次返回多列当然就节省了查询时间 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UPDATE monthly_orders&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SET (tot_orders, max_order_amt) =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;(SELECT COUNT(*), MAX(sale_price)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM cust_order)<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>DELETE FROM line_item<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE (order_nbr, part_nbr) IN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SELECT order_nbr, part_nbr FROM cust_order c)</FONT></DIV></TD></TR></SPAN><img src ="http://www.blogjava.net/terry-zj/aggbug/22786.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2005-12-06 22:04 <a href="http://www.blogjava.net/terry-zj/archive/2005/12/06/22786.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于数据库名(db_name)、实例名(instance_name)、ORACLE_SID (转载)</title><link>http://www.blogjava.net/terry-zj/archive/2005/12/06/22784.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Tue, 06 Dec 2005 13:57:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2005/12/06/22784.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/22784.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2005/12/06/22784.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/22784.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/22784.html</trackback:ping><description><![CDATA[<P><FONT size=2>数据库名(DB_NAME)、实例名(Instance_name)、以及操作系统环境变量(ORACLE_SID) </FONT></P>
<P><FONT size=2>在ORACLE7、8数据库中只有数据库名(db_name)和数据库实例名(instance_name)。在ORACLE8i、9i中出现了新的参数，即数据库域名(db_domain)、服务名(service_name)、以及操作系统环境变量(ORACLE_SID)。这些都存在于同一个数据库中的标识，用于区分不同数据库的参数。 </FONT></P>
<P><FONT size=2>一、什么是数据库名(db_name)? 数据库名是用于区分数据的内部标识，是以二进制方式存储于数据库控制文件中的参数，在数据安装或创建之后将不得修改。数据库安装完成后，该参数被写入数据库参数文件pfile中，格式如下： </FONT></P>
<P><FONT size=2>db_name="orcl" <BR>db_domain=dbcenter.toys.com <BR>instance_name=orcl <BR>service_names=orcl.dbcenter.toys.com <BR>control_file=...............<BR><BR>在每一个运行的ORACLE8i数据库中都有一个数据库名(db_name),如果一个服务器程序中创建了两个数据库，则有两个数据库名。其控制参数据分属在不同的pfile中控制着相关的数据库。 </FONT></P>
<P><FONT size=2>二、什么是数据库实例名(instance_name) 数据库实例名则用于和操作系统之间的联系，用于对外部连接时使用。在操作系统中要取得与数据库之间的交互，必须使用数据库实例名。例如，要和某一个数据库server连接，就必须知道其数据库实例名，只知道数据库名是没有用的，与数据库名不同，在数据安装或创建数据库之后，实例名可以被修改。数据库安装完成后，该实例名被写入数据库参数文件pfile中，格式如下： <BR>db_name="orcl" #(不允许修改) <BR>db_domain=dbcenter.toys.com <BR>instance_name=orcl #(可以修改,可以与db_name相同也可不同) <BR>service_names=orcl.dbcenter.toys.com <BR>control_file=...............<BR>数据库名与实例名之间的关系。 数据库名与实例名之间的关系一般是一一对应关系，有一个数据库名就有一个实例名，如果在一个服务器中创建两个数据库，则有两个数据库名，两个数据库实例名，用两个标识确定一个数据库，用户和实例相连接。 但在8i、9i的并行服务器结构中，数据库与实例之间不存在一一对应关系，而是一对多关系，(一个数据库对应多个实例，同一时间内用户只一个实例相联系，当某一实例出现故障，其它实例自动服务，以保证数据库安全运行。) </FONT></P>
<P><FONT size=2>三、操作系统环境变量(ORACLE_SID) 在实际中，对于数据库实例名的描述有时使用实例名(instance_name)参数，有时使用ORACLE_SID参数。这两个都是数据库实例名，它们有什么区别呢？(经常弄混) </FONT></P>
<P><FONT size=2>(ORACLE_SID) OS&lt;----------------&gt; ORACLE 数据库 &lt;--------(Instance_name(实例名)) </FONT></P>
<P><FONT size=2>上图表示实例名instance_name、ORACLE_SID与数据库及操作系统之间的关系，虽然这里列出的两个参数都是数据库实例名，但instance_name参数是ORACLE数据库的参数，此参数可以在参数文件中查询到，而ORACLE_SID参数则是操作系统环境变量。 操作系统环境变量ORACLE_SID用于和操作系统交互。也就是说，在操作系统中要想得到实例名，就必须使用ORACLE_SID。此参数与ORACLE_BASE、ORACLE_HOME等用法相同。在数据库安装之后，ORACLE_SID被用于定义数据库参数文件的名称。如： $ORACLE_BASE/admin/DB_NAME/pfile/init$ORACLE_SID.ora。 定义方法:&nbsp; export ORACLE_SID=orcl </FONT></P>
<P><FONT size=2>如果在同一服务器中创建了多个数据库，则必然同时存在多个数据库实例,这时可以重复上述定义过程，以选择不同实例。 </FONT></P>
<P><FONT size=2>还可以用 [oracle@Datacent]$ . oraenv 来切换不同的ORACLE_SID来通过操作系统来启动不同的实例(instance)</FONT></P><img src ="http://www.blogjava.net/terry-zj/aggbug/22784.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2005-12-06 21:57 <a href="http://www.blogjava.net/terry-zj/archive/2005/12/06/22784.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JDBC更新长VARCHAR2字段</title><link>http://www.blogjava.net/terry-zj/archive/2005/11/13/19542.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Sat, 12 Nov 2005 16:01:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2005/11/13/19542.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/19542.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2005/11/13/19542.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/19542.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/19542.html</trackback:ping><description><![CDATA[<P><FONT size=2>JDBC更新长VARCHAR2字段<BR><BR>oracle8开始VARCHAR2字段最大长度达到了4000.但是我们并不能简单的用jdbc输入这么大的字符串。<BR>让我们看看以下的情况:<BR>数据库参数 NLS Database Parameters：<BR>NLS_CHARACTERSET&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JA16SJIS<BR>NLS_NCHAR_CHARACTERSET&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AL16UTF16<BR></FONT><FONT size=2><BR>如果用pstmt.setString(index, value)更新一个字段;&nbsp;value是1000个日文字符 那么我们回得到出错信息:<BR><FONT size=2>java.sql.SQLException: データ・サイズがこの型の最大サイズを超えています。: 3000<BR>出错信息表示oracle认为你输入了3000长度的字符。<BR></FONT>经过几次实验可以发现pstmt.setString(index, value)只能更新长度&lt;=2000的字段。<BR>(原因不明 和oracle7时VARCHAR2字段最长为2000有关?)<BR>长度的计算方法:(英文字母和数字的数量+日文字符的数量*3)&lt;=2000<BR>比如“123パラメータ”的长度是18<BR></FONT><FONT size=2>&nbsp;&nbsp;&nbsp; <BR>更新较长的varchar2字段时应该用pstmt.setCharacterStream(...) <BR>且一次只能更新一个长varchar2字段。</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; private void updateChar(Connection conn,int index) throws SQLException{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String SQL = " UPDATE KMD_DOWNLOADRRK_T SET OUTPUTQUERY = ? " +<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " WHERE RRKCD = ?";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PreparedStatement pstmt = null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pstmt=conn.prepareStatement(SQL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //パラメータのセット<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String query = "length must &lt;= 2000";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StringReader read = new StringReader(query);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pstmt.setCharacterStream(1,read,query.length());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pstmt.setString(2, "001");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pstmt.executeUpdate();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }finally{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(pstmt != null) pstmt.close();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }</FONT></P>
<P><FONT size=2>setCharacterStream() 的使用比较复杂,&nbsp;Oracle网站上还介绍了一种解决办法:用两个参数对应一个字段<BR></FONT><FONT size=2>比如emp表中有一个字段memo <BR>insert into emp(memo) values (?||?); </FONT><FONT size=2>只要保证给每个参数赋的值不超过限制长度即可.<BR><BR>题外话：<BR>2000对于oracle PL/SQL中的VARCHAR2变量来说是比较特殊的是数字。<BR>定义一个小于2000的VARCHAR2变量，那么oracle就把它放在栈内存 如果大于2000就放在堆内存。<BR></FONT></P><img src ="http://www.blogjava.net/terry-zj/aggbug/19542.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2005-11-13 00:01 <a href="http://www.blogjava.net/terry-zj/archive/2005/11/13/19542.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle提供的序号函数</title><link>http://www.blogjava.net/terry-zj/archive/2005/11/12/19431.html</link><dc:creator>Terry的Blog</dc:creator><author>Terry的Blog</author><pubDate>Fri, 11 Nov 2005 16:23:00 GMT</pubDate><guid>http://www.blogjava.net/terry-zj/archive/2005/11/12/19431.html</guid><wfw:comment>http://www.blogjava.net/terry-zj/comments/19431.html</wfw:comment><comments>http://www.blogjava.net/terry-zj/archive/2005/11/12/19431.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry-zj/comments/commentRss/19431.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry-zj/services/trackbacks/19431.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Oracle提供的序号函数:以emp表为例:1: rownum 最简单的序号 但是在order by之前就确定值.select rownum,t.* from emp t order by ename&nbsp; 行数ROWNUMEMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO111787...&nbsp;&nbsp;<a href='http://www.blogjava.net/terry-zj/archive/2005/11/12/19431.html'>阅读全文</a><img src ="http://www.blogjava.net/terry-zj/aggbug/19431.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry-zj/" target="_blank">Terry的Blog</a> 2005-11-12 00:23 <a href="http://www.blogjava.net/terry-zj/archive/2005/11/12/19431.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>