??xml version="1.0" encoding="utf-8" standalone="yes"?>辽宁福彩快乐12:BlogJava - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/rabbit/学习笔记zh-cnTue, 14 Aug 2018 17:59:17 GMTTue, 14 Aug 2018 17:59:17 GMT60tips悬停 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/rabbit/archive/2014/05/07/413378.htmlRabbitRabbitWed, 07 May 2014 14:23:00 GMT//www.ot7t.com.cn/rabbit/archive/2014/05/07/413378.html//www.ot7t.com.cn/rabbit/comments/413378.html//www.ot7t.com.cn/rabbit/archive/2014/05/07/413378.html#Feedback0//www.ot7t.com.cn/rabbit/comments/commentRss/413378.html//www.ot7t.com.cn/rabbit/services/trackbacks/413378.html//www.php100.com/html/program/jquery/2013/0905/5970.html


//vadikom.com/demos/poshytip/


//www.cnblogs.com/best/archive/2011/09/27/2193572.html



JQuery插件TipsWindown 1.1

一个基于jQuery的弹出层。支持拖拽,支持内容为文字,图片,URL?至于兼容性。在IE6下,弹出对像无法绝对固定。其他应该没啥大问题?/p>

最新更新:(2010-08-12):修正IE6下不能遮住下拉菜单的BUG,增加拖动时半透明效果?/p>

应用演示

  1. 弹出文本信息提示?
    tipsWindown("提示","text:提示信息内容","250","150","true","","true","msg")
  2. 弹出页面中的某个ID的html?
    tipsWindown("标题","id:testID","300","200","true","","true","id")
  3. 弹出图片?
    tipsWindown("图片","img:图片路径","250","150","true","","true","img")
  4. get加载一?html文件(也可以?php/.asp?id=4之类的)?
    tipsWindown("标题","url:get?test.html","250","150","true","","true","text");
  5. 加载一个页面到框架显示?br />
    tipsWindown("标题","iframe://www.nowamagic.net","900","580","true","","true","leotheme");
  6. 弹出一个不能拖动且没有遮罩背景的文本信息层?
    tipsWindown("提示","text:提示信息内容","250","150","false","","false","msg")
  7. 弹出一个不能拖动,三秒钟自动关闭的层:
    tipsWindown("提示","text:提示信息内容","250","150","false","3000","true","msg")

参数说明

顺序 参数 功能 备注
1 title 弹出层的标题 必填,纯文本
2 content 弹出层的内容 text 文本内容
id 页面里某id的子标签
img 图片
url get或post某一页面里的html,该页面要求只包含body的子标签
iframe 目标地址在框架显?/td>
3 width 弹出层的?/td> 必填,比?#8220;200”。(不需要带px?/td>
4 height 弹出层的?/td> ?width
5 drag 是否可拖?/td> 必填,可选参数(true,false?/td>
6 time 自动消失时间 可不填,默认不自动关闭;参数可为?"")
7 showbg 是否显示遮罩?/td> 可不填,默认不显示(此项如填了,它前面的time也必须要填)
8 cssName 弹出层附加样式名 可不?/td>

像这种弹出透明背景层效果很常见了,除部分区域可以操作外其他区域不能操作,目前有提供插件,完全可以实现此种效果?/p>

查看本页源代码可获取所有所需的代码?/p>

Rabbit 2014-05-07 22:23 发表评论
]]>
批量插入(Test?/title><link>//www.ot7t.com.cn/rabbit/archive/2014/04/15/412487.html</link><dc:creator>Rabbit</dc:creator><author>Rabbit</author><pubDate>Tue, 15 Apr 2014 13:38:00 GMT</pubDate><guid>//www.ot7t.com.cn/rabbit/archive/2014/04/15/412487.html</guid><wfw:comment>//www.ot7t.com.cn/rabbit/comments/412487.html</wfw:comment><comments>//www.ot7t.com.cn/rabbit/archive/2014/04/15/412487.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.ot7t.com.cn/rabbit/comments/commentRss/412487.html</wfw:commentRss><trackback:ping>//www.ot7t.com.cn/rabbit/services/trackbacks/412487.html</trackback:ping><description><![CDATA[<ol start="1" style="font-size: 12px; line-height: 1.4em; margin: 0px 0px 1px; padding: 2px 0px; border: 1px solid #d1d7dc; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #2b91af; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace;"><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span style="color: #006699; font-weight: bold;"><</span><span style="color: #006699; font-weight: bold;">insert</span> <span style="color: red;">id</span>=<span style="color: blue;">"insertData"</span> <span style="color: red;">parameterType</span>=<span style="color: blue;">"java.util.List"</span> <span style="color: #006699; font-weight: bold;">></span>  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        INSERT INTO EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) (  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        <span style="color: #006699; font-weight: bold;"><</span><span style="color: #006699; font-weight: bold;">foreach</span> <span style="color: red;">collection</span>=<span style="color: blue;">"list"</span> <span style="color: red;">item</span>=<span style="color: blue;">"item"</span> <span style="color: red;">index</span>=<span style="color: blue;">"index"</span> <span style="color: red;">separator</span>=<span style="color: blue;">"union all"</span><span style="color: #006699; font-weight: bold;">></span>  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">            select  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                #{item.EMPNO,<span style="color: red;">jdbcType</span>=<span style="color: blue;">VARCHAR</span>},  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                #{item.ENAME,<span style="color: red;">jdbcType</span>=<span style="color: blue;">VARCHAR</span>},  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                #{item.JOB,<span style="color: red;">jdbcType</span>=<span style="color: blue;">VARCHAR</span>},  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                #{item.MGR,<span style="color: red;">jdbcType</span>=<span style="color: blue;">NUMERIC</span>},  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                #{item.MGR,<span style="color: red;">jdbcType</span>=<span style="color: blue;">NUMERIC</span>},  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                TO_DATE(#{item.HIREDATE,<span style="color: red;">jdbcType</span>=<span style="color: blue;">VARCHAR</span>},'yyyy-mm-dd')  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                  from dual  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        <span style="color: #006699; font-weight: bold;"></</span><span style="color: #006699; font-weight: bold;">foreach</span><span style="color: #006699; font-weight: bold;">></span>  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        )  </span></li><li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span style="color: #006699; font-weight: bold;"></</span><span style="color: #006699; font-weight: bold;">insert</span><span style="color: #006699; font-weight: bold;">></span> <br /><br />=====================================================================<br /><br /><br /><div class="yibqv">declare    </div><div class="yibqv">  type t_array is table of t_target%rowtype;    </div><div class="yibqv">  t_data t_array;    </div><div class="yibqv">  cursor c is    </div><div class="yibqv">    select null id, owner, object_name, null object_id, null xx, null yy    </div><div class="yibqv">    from dba_objects;    </div><div class="yibqv">begin    </div><div class="yibqv">  open c;    </div><div class="yibqv">  loop    </div><div class="yibqv">    fetch c bulk collect    </div><div class="yibqv">    into t_data limit 100;    </div><div class="yibqv">    </div><div class="yibqv">    forall i in 1 .. t_data.count    </div><div class="yibqv">      insert into t_target values t_data (i);    </div><div class="yibqv">    exit when c%notfound;    </div><div class="yibqv">  end loop;    </div><div class="yibqv">  close c;    </div><div class="yibqv">  commit;    </div><div class="yibqv">end; <br /><br /><br /><br /><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 21px; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;"><</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">insert </span><span style="margin: 0px; padding: 0px; color: #ff0000; line-height: 1.5 !important;">id</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">="insertByProc"</span><span style="margin: 0px; padding: 0px; color: #ff0000; line-height: 1.5 !important;"> statementType</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">="CALLABLE"</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">></span> <span style="margin: 0px; padding: 0px; color: #000000; line-height: 1.5 !important;"> <br />{call insertPro(#{name},#{age},#{sex},#{password},#{num})} </span> <br /><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;"></</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">insert</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">><br /><br /><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 21px; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">1</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">CREATE</span> DEFINER <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">=</span> `root`@`localhost` <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">PROCEDURE</span> `NewProc`(<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">IN</span> `name_in` <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">varchar</span>(<span style="margin: 0px; padding: 0px; color: #800000; font-weight: bold; line-height: 1.5 !important;">255</span>),<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">IN</span> `age_in` <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">int</span>,<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">IN</span> `sex_in` <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">varchar</span>(<span style="margin: 0px; padding: 0px; color: #800000; font-weight: bold; line-height: 1.5 !important;">255</span>),<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">IN</span> `password_in` <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">varchar</span>(<span style="margin: 0px; padding: 0px; color: #800000; font-weight: bold; line-height: 1.5 !important;">255</span>),<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">IN</span> `num_in` <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">int</span><span style="margin: 0px; padding: 0px; color: #000000; line-height: 1.5 !important;">) </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> 2</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">BEGIN</span> <span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> 3</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SET</span> <span style="margin: 0px; padding: 0px; color: #008000; line-height: 1.5 !important;">@a</span><span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">=</span><span style="margin: 0px; padding: 0px; color: #800000; font-weight: bold; line-height: 1.5 !important;">0</span><span style="margin: 0px; padding: 0px; color: #000000; line-height: 1.5 !important;">; </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> 4</span> <span style="margin: 0px; padding: 0px; color: #000000; line-height: 1.5 !important;">Label:LOOP </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> 5</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SET</span> <span style="margin: 0px; padding: 0px; color: #008000; line-height: 1.5 !important;">@a</span><span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">=</span><span style="margin: 0px; padding: 0px; color: #008000; line-height: 1.5 !important;">@a</span><span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">+</span><span style="margin: 0px; padding: 0px; color: #800000; font-weight: bold; line-height: 1.5 !important;">1</span><span style="margin: 0px; padding: 0px; color: #000000; line-height: 1.5 !important;">; </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> 6</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">INSERT</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">INTO</span> person ( name, age, sex, password) <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">VALUES</span><span style="margin: 0px; padding: 0px; color: #000000; line-height: 1.5 !important;"> (name_in,age_in,sex_in,password_in); </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> 7</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">IF</span> <span style="margin: 0px; padding: 0px; color: #008000; line-height: 1.5 !important;">@a</span><span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">=</span>num_in <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">THEN</span> <span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> 8</span> <span style="margin: 0px; padding: 0px; color: #000000; line-height: 1.5 !important;"> LEAVE Label; </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> 9</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">END</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">IF</span><span style="margin: 0px; padding: 0px; color: #000000; line-height: 1.5 !important;">; </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">10</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">END</span><span style="margin: 0px; padding: 0px; color: #000000; line-height: 1.5 !important;"> LOOP Label; </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">11</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">END</span>;</pre></span></pre></div><br /></span></li></ol><img src ="//www.ot7t.com.cn/rabbit/aggbug/412487.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.ot7t.com.cn/rabbit/" target="_blank">Rabbit</a> 2014-04-15 21:38 <a href="//www.ot7t.com.cn/rabbit/archive/2014/04/15/412487.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle中Hint深入理解 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/rabbit/archive/2013/11/08/406141.htmlRabbitRabbitFri, 08 Nov 2013 06:44:00 GMT//www.ot7t.com.cn/rabbit/archive/2013/11/08/406141.html//www.ot7t.com.cn/rabbit/comments/406141.html//www.ot7t.com.cn/rabbit/archive/2013/11/08/406141.html#Feedback0//www.ot7t.com.cn/rabbit/comments/commentRss/406141.html//www.ot7t.com.cn/rabbit/services/trackbacks/406141.htmlHint概述
基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担。但有时它也聪明反被聪明误,选择了很差的执行计划,使某个语句的执行变得奇慢无比?/font>

此时就需要DBA进行人为的干预,告诉优化器使用我们指定的存取路径或连接类型生成执行计划,从而使语句高效的运行。例如,如果我们认为对于一个特定的语句,执行全表扫描要比执行索引扫描更有效,则我们就可以指示优化器使用全表扫描。在Oracle 中,是通过为语句添?Hints(提示)来实现干预优化器优化的目的?br />不建议在代码中使用hint,在代码使用hint使得CBO无法根据实际的数据状态选择正确的执行计划。毕?/font> 数据是不断变化的?/font> 10g以后的CBO也越来越完善,大多数情况下我们该让Oracle自行决定采用什么执行计划?/font>

Oracle Hints是一种机制,用来告诉优化器按照我们的告诉它的方式生成执行计划。我们可以用Oracle Hints来实现:
1) 使用的优化器的类?br />2) 基于代价的优化器的优化目标,是all_rows还是first_rows?br />3) 表的访问路径,是全表扫描,还是索引扫描,还是直接利用rowid?br />4) 表之间的连接类型
5) 表之间的连接顺序
6) 语句的并行程?/font>

除了”RULE”提示外,一旦使用的别的提示,语句就会自动的改为使用CBO优化器,此时如果你的数据字典中没有统计数据,就会使用缺省的统计数据。所以建议大家如果使用CBO或Hints提示,则最好对表和索引进行定期的分析?/font>

如何使用Hints:

Hints只应用在它们所在sql语句?statement block,由select、update、delete关键字标?上,对其它SQL语句或语句的其它部分没有影响。如:对于使用union操作?个sql语句,如果只在一个sql语句上有Hints,则该Hints不会影响另一个sql语句?/font>

我们可以使用注释(comment)来为一个语句添加Hints,一个语句块只能有一个注释,而且注释只能放在SELECT, UPDATE, or DELETE关键字的后面

使用Oracle Hints的语法:

{DELETE|INSERT|SELECT|UPDATE} /*+ hint [text] [hint[text]]... */

or

{DELETE|INSERT|SELECT|UPDATE} --+ hint [text] [hint[text]]...

注解?br />1) DELETE、INSERT、SELECT和UPDATE是标识一个语句块开始的关键字,包含提示的注释只能出现在这些关键字的后面,否则提示无效?br />2) “+”号表示该注释是一个Hints,该加号必须立即跟在”/*”的后面,中间不能有空格?br />3) hint是下面介绍的具体提示之一,如果包含多个提示,则每个提示之间需要用一个或多个空格隔开?br />4) text 是其它说明hint的注释性文?/font>

5)使用表别名。如果在查询中指定了表别名,那么提示必须也使用表别名。例如:select /*+ index(e,dept_idx) */ * from emp e;
6)不要在提示中使用模式名称:如果在提示中指定了模式的所有者,那么提示将被忽略。例如:
select /*+ index(scott.emp,dept_idx) */ * from emp

注意:如果你没有正确的指定Hints,Oracle将忽略该Hints,并且不会给出任何错误?br />hint被忽?/strong>

如果CBO认为使用hint会导致错误的结果时,hint将被忽略,详见下?br />SQL> select /*+ index(t t_ind) */ count(*) from t;
Execution Plan
----------------------------------------------------------
Plan hash value: 2966233522
-------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |
-------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |     1 |    57   (2)| 00:00:01 |
|   1 |  SORT AGGREGATE    |      |     1 |            |          |
|   2 |   TABLE ACCESS FULL| T    | 50366 |    57   (2)| 00:00:01 |
-------------------------------------------------------------------

因为我们是对记录求总数,且我们并没有在建立索引时指定不能为空,索引如果CBO选择在索引上进行count时,但索引字段上的值为空时,结果将不准确,故CBO没有选择索引?/font>
SQL>  select /*+ index(t t_ind) */ count(id) from t;
Execution Plan
----------------------------------------------------------
Plan hash value: 646498162
--------------------------------------------------------------------------
| Id  | Operation        | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT |       |     1 |     5 |   285   (1)| 00:00:04 |
|   1 |  SORT AGGREGATE  |       |     1 |     5 |            |          |
|   2 |   INDEX FULL SCAN| T_IND | 50366 |   245K|   285   (1)| 00:00:04 |
--------------------------------------------------------------------------

因为我们只对id进行count,这个动作相当于count索引上的所有id值,这个操作和对表上的id字段进行count是一样的(组函数会忽略null?

Hint的具体用?br />

和优化器相关的hint

1?*+ ALL_ROWS */
表明对语句块选择基于开销的优化方?并获得最佳吞吐量,使资源消耗最小化.
SELECT /*+ ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';

2?*+ FIRST_ROWS(n) */
表明对语句块选择基于开销的优化方?并获得最佳响应时?使资源消耗最小化.
SELECT /*+FIRST_ROWS(20) */ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';
3?*+ RULE*/
表明对语句块选择基于规则的优化方?
SELECT /*+ RULE */ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';
和访问路径相关的hint

1?*+ FULL(TABLE)*/
表明对表选择全局扫描的方?
SELECT /*+FULL(A)*/ EMP_NO,EMP_NAM FROM BSEMPMS A WHERE EMP_NO='SCOTT';

2?*+ INDEX(TABLE INDEX_NAME) */
表明对表选择索引的扫描方?
SELECT /*+INDEX(BSEMPMS SEX_INDEX) */ * FROM BSEMPMS WHERE SEX='M';
5?*+ INDEX_ASC(TABLE INDEX_NAME)*/
表明对表选择索引升序的扫描方?
SELECT /*+INDEX_ASC(BSEMPMS PK_BSEMPMS) */ * FROM BSEMPMS WHERE DPT_NO='SCOTT';
6?*+ INDEX_COMBINE*/
为指定表选择位图访问路经,如果INDEX_COMBINE中没有提供作为参数的索引,将选择出位图索引的布尔组合方式.
SELECT /*+INDEX_COMBINE(BSEMPMS SAL_BMI HIREDATE_BMI) */  * FROM BSEMPMS
WHERE SAL<5000000 AND HIREDATE

7?*+ INDEX_JOIN(TABLE INDEX_NAME1 INDEX_NAME2) */
当谓词中引用的列都有索引的时候,可以通过指定采用索引关联的方式,来访问数?br />
select /*+ index_join(t t_ind t_bm) */ id from t where id=100 and object_name='EMPLOYEES'
8?*+ INDEX_DESC(TABLE INDEX_NAME)*/
表明对表选择索引降序的扫描方?

SELECT /*+INDEX_DESC(BSEMPMS PK_BSEMPMS) */ * FROM BSEMPMS WHERE DPT_NO='SCOTT';
9?*+ INDEX_FFS(TABLE INDEX_NAME) */
对指定的表执行快速全索引扫描,而不是全表扫描的办法.
SELECT /* + INDEX_FFS(BSEMPMS IN_EMPNAM)*/ * FROM BSEMPMS WHERE DPT_NO='TEC305';

10?*+ INDEX_SS(T T_IND) */
?i开始,oracle引入了这种索引访问方式。当在一个联合索引中,某些谓词条件并不在联合索引的第一列时,可以通过Index Skip Scan来访问索引获得数据。当联合索引第一列的唯一值个数很少时,使用这种方式比全表扫描效率高?/font>

SQL> create table t as select 1 id,object_name from dba_objects;
Table created.
SQL> insert into t select 2,object_name from dba_objects;      
50366 rows created.
SQL> insert into t select 3,object_name from dba_objects;      
50366 rows created.

SQL> insert into t select 4,object_name from dba_objects;      
50366 rows created.

SQL> commit;
Commit complete.
SQL> create index t_ind on t(id,object_name);
Index created.
SQL> exec dbms_stats.gather_table_stats('HR','T',cascade=>true);
PL/SQL procedure successfully completed.
执行全表扫描
SQL> select /*+ full(t) */ * from t where object_name='EMPLOYEES';
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     5 |   135 |   215   (3)| 00:00:03 |
|*  1 |  TABLE ACCESS FULL| T    |     5 |   135 |   215   (3)| 00:00:03 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("OBJECT_NAME"='EMPLOYEES')
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
        942  consistent gets
          0  physical reads
          0  redo size
        538  bytes sent via SQL*Net to client
        385  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          6  rows processed
不采用hint
SQL>  select * from t where object_name='EMPLOYEES';
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2869677071
--------------------------------------------------------------------------
| Id  | Operation        | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT |       |     5 |   135 |     5   (0)| 00:00:01 |
|*  1 |  INDEX SKIP SCAN | T_IND |     5 |   135 |     5   (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access("OBJECT_NAME"='EMPLOYEES')
       filter("OBJECT_NAME"='EMPLOYEES')
Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
         17  consistent gets
          1  physical reads
          0  redo size
        538  bytes sent via SQL*Net to client
        385  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          6  rows processed

当全表扫描扫描了942个块,联合索引只扫描?7个数据块。可以看到联合索引的第一个字段的值重复率很高时,即使谓词中没有联合索引的第一个字段,依然会使用index_ss方式,效率远远高于全表扫描效率。但?/font>
第一个字段的值重复率很低时,使用 index_ss的效率要低于 全表扫描,读者可以自行实?/font>
和表的关联相关的hint

/*+ leading(table_1,table_2) */

在多表关联查询中,指定哪个表作为驱动表,即告诉优化器首先要访问哪个表上的数据?/span>
select /*+ leading(t,t1) */ t.* from t,t1 where t.id=t1.id;

/*+ order */

让Oracle根据from后面表的顺序来选择驱动表,oracle建议使用leading,他更为灵活
select /*+ order */ t.* from t,t1 where t.id=t1.id;
/*+ use_nl(table_1,table_2) */
在多表关联查询中,指定使用nest loops方式进行多表关联?/span>

select /*+ use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;

/*+ use_hash(table_1,table_2) */
在多表关联查询中,指定使用hash join方式进行多表关联?/span>

select /*+ use_hash(t,t1) */ t.* from t,t1 where t.id=t1.id;

在多表关联查询中,指定使用hash join方式进行多表关联,并指定表t为驱动表?/font>

select /*+ use_hash(t,t1) leading(t,t1) */ t.* from t,t1 where t.id=t1.id;

/*+ use_merge(table_1,table_2) */
在多表关联查询中,指定使用merge join方式进行多表关联?/span>

select /*+ use_merge(t,t1) */ t.* from t,t1 where t.id=t1.id;

/*+ no_use_nl(table_1,table_2) */
在多表关联查询中,指定不使用nest loops方式进行多表关联?/span>

select /*+ no_use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;

/*+ no_use_hash(table_1,table_2) */
在多表关联查询中,指定不使用hash join方式进行多表关联?/span>

select /*+ no_use_hash(t,t1) */ t.* from t,t1 where t.id=t1.id;

/*+ no_use_merge(table_1,table_2) */
在多表关联查询中,指定不使用merge join方式进行多表关联?/span>

select /*+ no_use_merge(t,t1) */ t.* from t,t1 where t.id=t1.id;

其他常用的hint

/*+ parallel(table_name n) */

在sql中指定执行的并行度,这个值将会覆盖自身的并行?br />

select /*+ parallel(t 4) */ count(*)  from t;

/*+ no_parallel(table_name) */

在sql中指定执行的不使用并?br />

select /*+ no_parallel(t) */ count(*)  from t;

/*+ append */以直接加载的方式将数据加载入?

insert into t /*+ append */ select * from t;

/*+ dynamic_sampling(table_name n) */

设置sql执行时动态采用的级别,这个级别为0~10
select /*+ dynamic_sampling(t 4) */ * from t where id > 1234

/*+ cache(table_name) */
进行全表扫描时将table置于LRU列表的最活跃端,类似于table的cache属?br />

select /*+ full(employees) cache(employees) */ last_name from employees
附录hint表格

Hints for Optimization Approaches and Goals

ALL_ROWS The ALL_ROWS hint explicitly chooses the cost-based approach to optimize a statement block with a goal of best throughput (that is, minimum total resource consumption).
FIRST_ROWS The FIRST_ROWS hint explicitly chooses the cost-based approach to optimize a statement block with a goal of best response time (minimum resource usage to return first row). In newer Oracle version you should give a parameter with this hint: FIRST_ROWS(n) means that the optimizer will determine an executionplan to give a fast response for returning the first n rows.
CHOOSE The CHOOSE hint causes the optimizer to choose between the rule-based approach and the cost-based approach for a SQL statement based on the presence of statistics for the tables accessed by the statement
RULE The RULE hint explicitly chooses rule-based optimization for a statement block. This hint also causes the optimizer to ignore any other hints specified for the statement block. The RULE hint does not work any more in Oracle 10g.

Hints for Access Paths

FULL The FULL hint explicitly chooses a full table scan for the specified table. The syntax of the FULL hint is FULL(table) where table specifies the alias of the table (or table name if alias does not exist) on which the full table scan is to be performed.
ROWID The ROWID hint explicitly chooses a table scan by ROWID for the specified table. The syntax of the ROWID hint is ROWID(table) where table specifies the name or alias of the table on which the table access by ROWID is to be performed. (This hint depricated in Oracle 10g)
CLUSTER The CLUSTER hint explicitly chooses a cluster scan to access the specified table. The syntax of the CLUSTER hint is CLUSTER(table) where table specifies the name or alias of the table to be accessed by a cluster scan.
HASH The HASH hint explicitly chooses a hash scan to access the specified table. The syntax of the HASH hint is HASH(table) where table specifies the name or alias of the table to be accessed by a hash scan.
HASH_AJ The HASH_AJ hint transforms a NOT IN subquery into a hash anti-join to access the specified table. The syntax of the HASH_AJ hint is HASH_AJ(table) where table specifies the name or alias of the table to be accessed.(depricated in Oracle 10g)
INDEX The INDEX hint explicitly chooses an index scan for the specified table. The syntax of the INDEX hint is INDEX(table index) where:table specifies the name or alias of the table associated with the index to be scanned and index specifies an index on which an index scan is to be performed. This hint may optionally specify one or more indexes:
NO_INDEX The NO_INDEX hint explicitly disallows a set of indexes for the specified table. The syntax of the NO_INDEX hint is NO_INDEX(table index)
INDEX_ASC The INDEX_ASC hint explicitly chooses an index scan for the specified table. If the statement uses an index range scan, Oracle scans the index entries in ascending order of their indexed values.
INDEX_COMBINE If no indexes are given as arguments for the INDEX_COMBINE hint, the optimizer will use on the table whatever boolean combination of bitmap indexes has the best cost estimate. If certain indexes are given as arguments, the optimizer will try to use some boolean combination of those particular bitmap indexes. The syntax of INDEX_COMBINE is INDEX_COMBINE(table index).
INDEX_JOIN Explicitly instructs the optimizer to use an index join as an access path. For the hint to have a positive effect, a sufficiently small number of indexes must exist that contain all the columns required to resolve the query.
INDEX_DESC The INDEX_DESC hint explicitly chooses an index scan for the specified table. If the statement uses an index range scan, Oracle scans the index entries in descending order of their indexed values.
INDEX_FFS This hint causes a fast full index scan to be performed rather than a full table.
NO_INDEX_FFS Do not use fast full index scan (from Oracle 10g)
INDEX_SS Exclude range scan from query plan (from Oracle 10g)
INDEX_SS_ASC Exclude range scan from query plan (from Oracle 10g)
INDEX_SS_DESC Exclude range scan from query plan (from Oracle 10g)
NO_INDEX_SS The NO_INDEX_SS hint causes the optimizer to exclude a skip scan of the specified indexes on the specified table. (from Oracle 10g)

Hints for Query Transformations

NO_QUERY_TRANSFORMATION Prevents the optimizer performing query transformations. (from Oracle 10g)
USE_CONCAT The USE_CONCAT hint forces combined OR conditions in the WHERE clause of a query to be transformed into a compound query using the UNION ALL set operator. Normally, this transformation occurs only if the cost of the query using the concatenations is cheaper than the cost without them.
NO_EXPAND The NO_EXPAND hint prevents the optimizer from considering OR-expansion for queries having OR conditions or IN-lists in the WHERE clause. Usually, the optimizer considers using OR expansion and uses this method if it decides that the cost is lower than not using it.
REWRITE The REWRITE hint forces the optimizer to rewrite a query in terms of materialized views, when possible, without cost consideration. Use the REWRITE hint with or without a view list. If you use REWRITE with a view list and the list contains an eligible materialized view, then Oracle uses that view regardless of its cost.
NOREWRITE / NO_REWRITE In Oracle 10g renamed to NO_REWRITE. The NOREWRITE/NO_REWRITE hint disables query rewrite for the query block, overriding the setting of the parameter QUERY_REWRITE_ENABLED.
MERGE The MERGE hint lets you merge views in a query.
NO_MERGE The NO_MERGE hint causes Oracle not to merge mergeable views. This hint is most often used to reduce the number of possible permutations for a query and make optimization faster.
FACT The FACT hint indicated that the table should be considered as a fact table. This is used in the context of the star transformation.
NO_FACT The NO_FACT hint is used in the context of the star transformation to indicate to the transformation that the hinted table should not be considered as a fact table.
STAR_TRANSFORMATION The STAR_TRANSFORMATION hint makes the optimizer use the best plan in which the transformation has been used. Without the hint, the optimizer could make a query optimization decision to use the best plan generated without the transformation, instead of the best plan for the transformed query.
NO_STAR_TRANSFORMATION Do not use star transformation (from Oracle 10g)
UNNEST The UNNEST hint specifies subquery unnesting.
NO_UNNEST Use of the NO_UNNEST hint turns off unnesting for specific subquery blocks.

Hints for Join Orders

LEADING Give this hint to indicate the leading table in a join. This will indicate only 1 table. If you want to specify the whole order of tables, you can use the ORDERED hint. Syntax: LEADING(table)
ORDERED The ORDERED hint causes Oracle to join tables in the order in which they appear in the FROM clause. If you omit the ORDERED hint from a SQL statement performing a join , the optimizer chooses the order in which to join the tables. You may want to use the ORDERED hint to specify a join order if you know something about the number of rows selected from each table that the optimizer does not. Such information would allow you to choose an inner and outer table better than the optimizer could.

Hints for Join Operations

USE_NL The USE_NL hint causes Oracle to join each specified table to another row source with a nested loops join using the specified table as the inner table. The syntax of the USE_NL hint is USE_NL(table table) where table is the name or alias of a table to be used as the inner table of a nested loops join.
NO_USE_NL Do not use nested loop (from Oracle 10g)
USE_NL_WITH_INDEX Specifies a nested loops join. (from Oracle 10g)
USE_MERGE The USE_MERGE hint causes Oracle to join each specified table with another row source with a sort-merge join. The syntax of the USE_MERGE hint is USE_MERGE(table table) where table is a table to be joined to the row source resulting from joining the previous tables in the join order using a sort-merge join.
NO_USE_MERGE Do not use merge (from Oracle 10g)
USE_HASH The USE_HASH hint causes Oracle to join each specified table with another row source with a hash join. The syntax of the USE_HASH hint is USE_HASH(table table) where table is a table to be joined to the row source resulting from joining the previous tables in the join order using a hash join.
NO_USE_HASH Do not use hash (from Oracle 10g)
Hints for Parallel Execution
PARALLEL The PARALLEL hint allows you to specify the desired number of concurrent query servers that can be used for the query. The syntax is PARALLEL(table number number). The PARALLEL hint must use the table alias if an alias is specified in the query. The PARALLEL hint can then take two values separated by commas after the table name. The first value specifies the degree of parallelism for the given table, the second value specifies how the table is to be split among the instances of a parallel server. Specifying DEFAULT or no value signifies the query coordinator should examine the settings of the initialization parameters (described in a later section) to determine the default degree of parallelism.
NOPARALLEL / NO_PARALLEL The NOPARALLEL hint allows you to disable parallel scanning of a table, even if the table was created with a PARALLEL clause. In Oracle 10g this hint was renamed to NO_PARALLEL.
PQ_DISTRIBUTE The PQ_DISTRIBUTE hint improves the performance of parallel join operations. Do this by specifying how rows of joined tables should be distributed among producer and consumer query servers. Using this hint overrides decisions the optimizer would normally make.
NO_PARALLEL_INDEX The NO_PARALLEL_INDEX hint overrides a PARALLEL attribute setting on an index to avoid a parallel index scan operation.
Additional Hints
APPEND When the APPEND hint is used with the INSERT statement, data is appended to the table. Existing free space in the block is not used. If a table or an index is specified with nologging, this hint applied with an insert statement produces a direct path insert which reduces generation of redo.
NOAPPEND Overrides the append mode.
CACHE The CACHE hint specifies that the blocks retrieved for the table in the hint are placed at the most recently used end of the LRU list in the buffer cache when a full table scan is performed. This option is useful for small lookup tables. In the following example, the CACHE hint overrides the table default caching specification.
NOCACHE The NOCACHE hint specifies that the blocks retrieved for this table are placed at the least recently used end of the LRU list in the buffer cache when a full table scan is performed. This is the normal behavior of blocks in the buffer cache.
PUSH_PRED The PUSH_PRED hint forces pushing of a join predicate into the view.
NO_PUSH_PRED The NO_PUSH_PRED hint prevents pushing of a join predicate into the view.
PUSH_SUBQ The PUSH_SUBQ hint causes nonmerged subqueries to be evaluated at the earliest possible place in the execution plan.
NO_PUSH_SUBQ The NO_PUSH_SUBQ hint causes non-merged subqueries to be evaluated as the last step in the execution plan.
QB_NAME Specifies a name for a query block. (from Oracle 10g)
CURSOR_SHARING_EXACT Oracle can replace literals in SQL statements with bind variables, if it is safe to do so. This is controlled with the CURSOR_SHARING startup parameter. The CURSOR_SHARING_EXACT hint causes this behavior to be switched off. In other words, Oracle executes the SQL statement without any attempt to replace literals by bind variables.
DRIVING_SITE The DRIVING_SITE hint forces query execution to be done for the table at a different site than that selected by Oracle
DYNAMIC_SAMPLING The DYNAMIC_SAMPLING hint lets you control dynamic sampling to improve server performance by determining more accurate predicate selectivity and statistics for tables and indexes. You can set the value of DYNAMIC_SAMPLING to a value from 0 to 10. The higher the level, the more effort the compiler puts into dynamic sampling and the more broadly it is applied. Sampling defaults to cursor level unless you specify a table.
SPREAD_MIN_ANALYSIS This hint omits some of the compile time optimizations of the rules, mainly detailed dependency graph analysis, on spreadsheets. Some optimizations such as creating filters to selectively populate spreadsheet access structures and limited rule pruning are still used. (from Oracle 10g)

Hints with unknown status

MERGE_AJ The MERGE_AJ hint transforms a NOT IN subquery into a merge anti-join to access the specified table. The syntax of the MERGE_AJ hint is MERGE_AJ(table) where table specifies the name or alias of the table to be accessed.(depricated in Oracle 10g)
AND_EQUAL The AND_EQUAL hint explicitly chooses an execution plan that uses an access path that merges the scans on several single-column indexes. The syntax of the AND_EQUAL hint is AND_EQUAL(table index index) where table specifies the name or alias of the table associated with the indexes to be merged. and index specifies an index on which an index scan is to be performed. You must specify at least two indexes. You cannot specify more than five. (depricated in Oracle 10g)
STAR The STAR hint forces the large table to be joined last using a nested loops join on the index. The optimizer will consider different permutations of the small tables. (depricated in Oracle 10g)
BITMAP Usage: BITMAP(table_name index_name) Uses a bitmap index to access the table. (depricated ?)
HASH_SJ
Use a Hash Anti-Join to evaluate a NOT IN sub-query. Use this hint in the sub-query, not in the main query. Use this when your high volume NOT IN sub-query is using a FILTER or NESTED LOOPS join. Try MERGE_AJ if HASH_AJ refuses to work.(depricated in Oracle 10g)
NL_SJ Use a Nested Loop in a sub-query. (depricated in Oracle 10g)
NL_AJ Use an anti-join in a sub-query. (depricated in Oracle 10g)
ORDERED_PREDICATES (depricated in Oracle 10g)
EXPAND_GSET_TO_UNION (depricated in Oracle 10g)


参考至:《让Oracle跑得更快》谭怀远著



Rabbit 2013-11-08 14:44 发表评论
]]>
oracle table-lock?种模?/title><link>//www.ot7t.com.cn/rabbit/archive/2013/11/05/406007.html</link><dc:creator>Rabbit</dc:creator><author>Rabbit</author><pubDate>Tue, 05 Nov 2013 06:31:00 GMT</pubDate><guid>//www.ot7t.com.cn/rabbit/archive/2013/11/05/406007.html</guid><wfw:comment>//www.ot7t.com.cn/rabbit/comments/406007.html</wfw:comment><comments>//www.ot7t.com.cn/rabbit/archive/2013/11/05/406007.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.ot7t.com.cn/rabbit/comments/commentRss/406007.html</wfw:commentRss><trackback:ping>//www.ot7t.com.cn/rabbit/services/trackbacks/406007.html</trackback:ping><description><![CDATA[<span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; font-weight: bold;">Oracle中的锁定可以分为几类?/span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">1、DML lock(data lock),</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">2、DDL lock(dictionary lock)</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">3、internal lock/latch?/span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">DML lock又可以分为row lock和table lock。row lock在select.. for update/insert/update/delete时隐式自动产生,而table lock除了隐式产生,也可以调用lock table <table_name> in </table_name> name来显示锁定?/span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">如果不希望别的session lock/insert/update/delete表中任意一行,只允许查询,可以用lock table table_name in exclusive mode?X)这个锁定模式级别最高,并发度最小?/span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">如果允许别的session查询或用select for update锁定记录,不允许insert/update/delete,可以用</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; color: red;">lock table table_name in share row exclusive mode?SRX)</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">如果允许别的session查询或select for update以及lock table table_name in share mode,只是不允许insert/update/delete,可以用</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">lock table table_name in share mode?share mode和share row exclusive mode的区别在于一个是非抢占式的而另一个是抢占式的。进入share row exclusive mode后其他session不能阻止你insert/update/delete,而进入share mode后其他session也同样可以进入share mode,进而阻止你对表的修改?S)</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">还有两种锁定模式,row share(RS)和row exclusive(RX)。他们允许的并发操作更多,一般直接用DML语句自动获得,而不用lock语句?/span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">详细参考concepts文中的"Type Of Locks"?/span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">//download-uk.oracle.com/docs/cd/B10501_01/server.920/a96524/c21cnsis.htm#2937 </span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">-------------------------------------</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="font-weight: bold;">怎么unlock table 解锁</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; font-weight: bold;">方法一、kill session?/span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">SQL> select object_id,session_id from v$locked_object;  //注意session_id 就是上锁?session标志</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">SQL> select username,sid,SERIAL#  from v$session where sid=。?      //这里的SID = session_id </span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">SQL> alter system kill session 'id,serial#';     //杀死该session</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; font-weight: bold;">方法二、rollback/commit 终止事务处理<br /><br /><br /></span><a style="word-wrap: break-word; color: #19599b; font-family: 微软雅黑, 黑体, Verdana; font-size: 20px; background-color: #ffffff;">ORACLE 大表建立索引的一些考虑</a><span style="color: #565656; font-family: 宋体, Arial; font-size: 12px; line-height: 12px; background-color: #ffffff;"> </span><br /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; font-weight: bold;"><br /></span><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">首先?/span><strong style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">应当考虑表空间和磁盘空间是否足够</strong><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">。我们知道索引也是一种数据,在建立索引的时候势必也会占用大量表空间。因此在对一张大表建立索引的时候首先应当考虑的是空间容量问题?/span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">其次,在对建立索引的时候要对表进行加锁,因此应当注?/span><strong style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">操作在业务空闲的时候进?/strong><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">?/span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><strong style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><em style="word-wrap: break-word;">性能调整方法?/em></strong><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><font color="#0000F0" style="word-wrap: break-word; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">首先应考虑IO?物理上,应当尽量把索引与数据分散到不同的磁盘上?逻辑上,数据表空间与索引表空间分开。这是在建索引时应当尊守的基本原?/font><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">?/span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">其次?/span><font color="#0000F0" style="word-wrap: break-word; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">在建立索引的时候要对表进行全表的扫描工?/font><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">,因此,应当考虑调大初始化参?/span><font color="#0000F0" style="word-wrap: break-word; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">db_file_multiblock_read_count的值。一般设置为16或更?/font><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">?/span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">?次,</span><font color="#0000F0" style="word-wrap: break-word; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">建立索引除了要进行全表扫描外同时还要对数据进行大量的排序操作</font><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">,因此,应当调整排序区的大小。在9I之前?可以在SESSION级别上加大sort_area_size 的大小, 比如设置?00M或者更大?I 以后?如果</span><font color="#0000F0" style="word-wrap: break-word; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">初始化参数workarea_size_policy的值为TRUE?则排序区从PGA_AGGREGATE_TARGET里自动分配获?/font><br /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; font-weight: bold;"><br /><br /></span><img src ="//www.ot7t.com.cn/rabbit/aggbug/406007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.ot7t.com.cn/rabbit/" target="_blank">Rabbit</a> 2013-11-05 14:31 <a href="//www.ot7t.com.cn/rabbit/archive/2013/11/05/406007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用 EclEmma 进行覆盖测试 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/rabbit/archive/2013/11/01/405872.htmlRabbitRabbitFri, 01 Nov 2013 01:43:00 GMT//www.ot7t.com.cn/rabbit/archive/2013/11/01/405872.html//www.ot7t.com.cn/rabbit/comments/405872.html//www.ot7t.com.cn/rabbit/archive/2013/11/01/405872.html#Feedback0//www.ot7t.com.cn/rabbit/comments/commentRss/405872.html//www.ot7t.com.cn/rabbit/services/trackbacks/405872.html覆盖测试是衡量测试质量的一个重要指标。在对一个软件产品进行了单元测试、组装测试、集成测试以及接受测试等繁多的测试之后,我们能不能就此对软件的质量产生一定的信心呢?这就需要我们对测试的质量进行考察。如果测试仅覆盖了代码的一小部分,那么不管我们写了多少测试用例,我们也不能相信软件质量是有保证的。相反,如果测试覆盖到了软件的绝大部分代码,我们就能对软件的质量有一个合理的信心。本文将介绍一个优秀的开源软件测试工?EclEmma,它能够对由 Java 语言编写的程序进行覆盖测试,从而对程序运行的结果生成详尽的覆盖测试报告?/p>

介绍

现在 IT 开发人员比以往任何时候都更加关注测试的重要性,没有经过良好测试的代码更容易出问题。在极限编程中,测试驱动开发已经被证明是一种有效提高软件质量的方法。在测试驱动的开发方式中,软件工程师在编写功能代码之前首先编写测试代码,这样能从最开始保证程序代码的正确性,并且能够在程序的每次演进时进行自动的回归测试。测试对于软件产品的成败起着至关重要的作用,在极限编程领域,甚至有人提议任何未经测试的代码都应该自动从发布的产品中删除。作者并不确信这个观点是正确的,但是测试本身的质量确实是一个需要高度关注的问题。测试的覆盖率是测试质量的一个重要指标,我们需要工具来帮助我们进行对软件测试覆盖的考察?/p>

EclEmma 就是这样一个能帮助开发人员考察测试覆盖率的优秀?Eclipse 开源插件。EclEmma 在覆盖测试领域是如此的优秀,以致于它在过去不久?2006 年成为了 Eclipse Community Awards Winners 决赛选手。虽然最?Eclipse Checkstyle Plugin 取得?Best Open Source Eclipse-based Developer tool 的称号,但我们也可以由此看到 EclEmma 对开发人员的帮助是巨大的(Eclipse Community Award 的具体信息可以参?参考资?/a>)?/p>

提到 EclEmma 首先就要说到著名?Java 覆盖测试工具 Emma。Emma 是一个在 SourceForge 上进行的开源项目(参阅 参考资?/a>)。从某种程度上说,EclEmma 可以看作?Emma 的一个图形界面。在本文?a >参考文?/a>中,可以看到专门讲述使用 Emma 的技术文章?/p>

Emma 的作者开?Emma 之初,程序员已经有了各种各样优秀的开?Java 开发工具。举例来说,我们有优秀的集成开发环?Eclipse,有开源的 JDK,有单元测试工具 JUnit,有 Ant 这样的项目管理工具,我们还可以用 CVS ?SubVersion 来进行源代码版本的维护。当时看来,也许唯一缺少的就是一个开源的覆盖测试工具了。Emma 就是为了填补这项空白而生的。现在的情况已经?Emma 诞生的时候不一样的。时至今日,我们已经有了不少的覆盖测试工具。例?Coverlipse 是一个基?Eclipse 的覆盖测试插件。其他还?Cobertura,Quilt ?JCoverage 等。但?Emma 具有一些非常优秀的特性使得它更适合被广泛的使用。和 Coverlipse 等工具比起来,Emma 是开源的,同时它对应用程序执行速度的影响非常小?/p>

EclEmma 的出现弥补了 Emma 用户一个大的遗?---- 缺乏图形界面以及对集成开发环境的支持。将 Eclipse ?Emma 这两个在各自领域最为优秀的工具结合起来,这就?EclEmma 为我们提供的。接下来,我们就要在后续章节中和读者朋友一起看?EclEmma 为开发人员提供了什么?/p>

安装 EclEmma 插件

安装 EclEmma 插件的过程和大部?Eclipse 插件相同,我们既可以通过 Eclipse 标准?Update 机制来远程安?EclEmma 插件?a >?1),也可以从站点(参?参考资?/a>)下?zip 文件并解压到 eclipse 所在的目录中?/p>

?1 添加 EclEmma 更新站点
?1 添加 EclEmma 更新站点

不管采用何种方式来安?EclEmma,安装完成并重新启动 Eclipse 之后,工具栏上应该出现一个新的按钮:

?2 新增的覆盖测试按?/h5>?2 新增的覆盖测试按? src=

使用 EclEmma 测试 Java 程序

为了实验 EclEmma 的特性,我们首先?Eclipse ?Workspace 中建立一个名称为 test.emma 的新 Java 项目。接下来,我们在其中建立一?HelloWorld 类,其代码如下所示:

清单 1 用于测试 EclEmma 的代?/h5>
package test.emma;

public class HelloWorld {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int rand = (int) (Math.random()*100);
		if(rand%2==0){
			System.out.println( "Hello, world! 0");
		}
		else
			System.out.println("Hello, world! 1");
		
		int result = rand%2==0? rand+rand:rand*rand; 
		System.out.println(result);
	}
}

接下来,我们通过 EclEmma 运行 HelloWorld.main() 函数?/p>

?3 ?Java 应用程序进行覆盖测试
?3 ?Java 应用程序进行覆盖测试

执行完毕之后,我们正在编?HelloWorld.java 的窗口将会变成如下所示:

?4 进行覆盖测试的结?/h5>?4 进行覆盖测试的结? src=

?Java 编辑器中,EclEmma 用不同的色彩标示了源代码的测试情况。其中,绿色的行表示该行代码被完整的执行,红色部分表示该行代码根本没有被执行,而黄色的行表明该行代码部分被执行。黄色的行通常出现在单行代码包含分支的情况,例??4 中的 16 行就显示为黄色。由于程序中有一个随机确定的分支,因此读者的窗口可能与这里稍有不同(11 行或?14 行中有且只有一个红色的行)?/p>

除了在源代码编辑窗口直接进行着色之外,EclEmma 还提供了一个单独的视图来统计程序的覆盖测试率?/p>

?5 察看程序的覆盖测试率
?5 察看程序的覆盖测试率

EclEmma 提供?Coverage 视图能够分层的显示代码的覆盖测试率,?5 中的信息表明我们?HelloWorld 的一次运行覆盖了大约 68.6% 的代码?/p>

想在一次运行中覆盖所有的代码通常比较困难,如果能把多次测试的覆盖数据综合起来进行察看,那么我们就能更方便的掌握多次测试的测试效果。EclEmma 提供了这样的功能。现在,让我们重复数次对 HelloWorld 的覆盖测试。我们注意到 Coverage 视图总是显示最新完成的一次覆盖测试。事实上,EclEmma 为我们保存了所有的测试结果。接下来,我们将通过 Coverage 视图的工具按钮来结合多次覆盖测试的结果?/p>

?6 用于结合多次覆盖测试结果的工具栏按钮
?6 用于结合多次覆盖测试结果的工具栏按钮

当我们多次运?Coverage 之后,我们可以单??6 所示工具栏按钮。之后,一个对话框将被弹出以供用户选择需要合并的覆盖测试?/p>

?7 选择需要合并的覆盖测试结果
?7 选择需要合并的覆盖测试结果

在合并完成之后,我们可以观察?Java 编辑器和 Coverage 视图中都显示了合并之后的结果?/p>

?8 察看合并后的覆盖测试结果
?8 察看合并后的覆盖测试结果

?8 中,我们可以看到,通过多次运行覆盖测试,最终我们的代码达到?91.4% 的测试覆盖率。有趣的是,图中第三行代码被标记为红色,而此行代码实际上是不可执行的。奥妙在于,我们没有生成任何 HelloWorld 类的实例,因此缺省构造函数没有被调用,?EclEmma 将这个特殊代码的覆盖状态标记在类声明的第一行?/p>


EclEmma 的高级特?/h2>

如果 EclEmma 只能测试 Java Application 的测试覆盖率,那么它相对命令行版本的 Emma 来说,提供的增强就不多了。相反,EclEmma 提供了很多与 Eclipse 紧密结合的功能。它不仅能测?Java Application,还能计?JUnit 单元测试,对 Eclipse 插件测试的覆盖率。从 ?9 中我们可以看?EclEmma 目前支持四种类型的程序?/p>

?9 EclEmma 的配置页?/h5>?9 EclEmma 的配置页? src=

为了了解 EclEmma 是如何获得覆盖测试数据的,我们需要先?Emma 有初步的了解。通常代码覆盖测试工具都需要对被执行的代码进行修改。?Emma 提供了两种方式来完成这件事?/p>

  1. 预插入模式:对程序进行测量之前,需要采?Emma 提供的工具对 class 文件或?jar 文件进行修改。修改完成之后的代码可以立刻被执行。覆盖测试的结果将会被存放到指定的文件中?/li>
  2. 即时插入模式?/strong>即时插入模式不需要事先对代码进行修改。相反,对代码的修改是通过一?Emma 定制?Class loader(类载入器)进行的。这种方式的优点很明显,我们不需要对 class 或?jar 文件进行任何修改。缺点是我们为了获得测试的结果,需要用 Emma 提供的命?emmarun 来执?Java 应用程序?/li>

使用即时插入模式的优点很明显:class 文件?jar 文件不会被修改。而预插入模式的应用范围更为广泛,对于某些需要嵌入到框架中运行的代码来说(例?EJB),我们只能使用预插入模式。EclEmma 仅仅使用?Emma 的预插入模式来工作,不过 EclEmma 缺省会在临时目录中创?class 文件?jar 文件的副本来进行修改,因此在 workspace ?class ?jar 文件仍然保持原样。虽然听上去很好,但是由于需要修?classpath 来使用修改过?class ?jar 文件,对于不能修?classpath 的应用(例如 Eclipse RCP ?JUnit Plugin Test)来说,我们还是只能选择修改 workspace 中的 class 文件?jar 文件。对?Java Application ?JUnit 类型的覆盖测试,我们可以在配置对话框中选中“In-place instrumentation”项来指定直接修改 Workspace 中的 .class 文件?.jar 文件?/p>



Rabbit 2013-11-01 09:43 发表评论
]]>
基于Xfire SOAP Header的WebService安全验证教程 . - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/rabbit/archive/2013/10/24/405610.htmlRabbitRabbitThu, 24 Oct 2013 08:28:00 GMT//www.ot7t.com.cn/rabbit/archive/2013/10/24/405610.html//www.ot7t.com.cn/rabbit/comments/405610.html//www.ot7t.com.cn/rabbit/archive/2013/10/24/405610.html#Feedback1//www.ot7t.com.cn/rabbit/comments/commentRss/405610.html//www.ot7t.com.cn/rabbit/services/trackbacks/405610.htmlWebSerice是一种开放的web服务,任何人都可以访问,但我们有时候需要考虑只有付费用户才能使用WS,所以,我们就需要对WS加入安全验证机制,当然,可以利用防火墙的IP过滤,web应用的配置从最外层去隔离非法用户,但在内层,我们也可以使用SOAP Header的方式,由客户端发送验证数据,服务端验通过后基WS访问权限

首先根据我的这篇Blog

//blog.csdn.net/daryl715/archive/2007/07/25/1707161.aspx

配置WS Server和WS Client?font color="#ff0000">其中Client端的测试代码类名由Client改为ClientTest,因为我们要用到Xfire的一个名为Client的类 

 

首先我们编写服务端验证类继承AbstractHandler

 

package test;

import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.handler.AbstractHandler;
import org.jdom.Element;

public class AuthenticationHandler extends AbstractHandler {

    
public void invoke(MessageContext cfx) throws Exception {
           
if(cfx.getInMessage().getHeader() == null)
           
{
               
throw new org.codehaus.xfire.fault.XFireFault("请求必须包含验证信息",org.codehaus.xfire.fault.XFireFault.SENDER);
           }

           Element token
=cfx.getInMessage().getHeader().getChild("AuthenticationToken");
           
if (token == null
           

            
throw new org.codehaus.xfire.fault.XFireFault("请求必须包含身份验证信息", org.codehaus.xfire.fault.XFireFault.SENDER); 
           }
 

              String username 
= token.getChild("Username").getValue(); 
              String password 
= token.getChild("Password").getValue(); 
              
try 
              

                  
//进行身份验证 ,只有abcd@1234的用户为授权用户
                 if(username.equals("abcd"&& password.equals("1234"))
                  
//这语句不显示
                  System.out.println("身份验证通过");
                 
else throw new Exception();
              }
 
              
catch (Exception e) 
              

                  
throw new   org.codehaus.xfire.fault.XFireFault("非法的用户名和密?/span>",   org.codehaus.xfire.fault.XFireFault.SENDER); 
              }
 

          }
 



}

 

下面是Client发送授权信?/p>

 

package test;

import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.handler.AbstractHandler;
import org.jdom.Element;

public class ClientAuthenticationHandler extends AbstractHandler {

     
private String username = null

     
private String password = null

     
public ClientAuthenticationHandler() 

     }
 

     
public ClientAuthenticationHandler(String username,String password) 

         
this.username = username; 

         
this.password = password; 
     }
 

     
public void setUsername(String username) 

         
this.username = username; 

     }
 

     
public void setPassword(String password) 

         
this.password = password; 

     }
 

     
public void invoke(MessageContext context) throws Exception 

         
//为SOAP Header构造验证信?/span>
         Element el = new Element("header"); 
         context.getOutMessage().setHeader(el); 
         Element auth 
= new Element("AuthenticationToken"); 
         Element username_el 
= new Element("Username"); 
         username_el.addContent(username); 
         Element password_el 
= new Element("Password"); 
         password_el.addContent(password); 
         auth.addContent(username_el); 
         auth.addContent(password_el); 
         el.addContent(auth); 
     }
 



}

为ClientTest.java加入以下代码

 XFireProxy proxy = (XFireProxy)Proxy.getInvocationHandler(service);
Client client = proxy.getClient();
client.addOutHandler(new ClientAuthenticationHandler("abcd1","1234"));

等等,还没有完,修改Services.xm为WS绑定Handler

  

<?xml version="1.0" encoding="UTF-8"?>


<beans>
<service xmlns="//xfire.codehaus.org/config/1.0">
<name>HelloService</name>
<namespace>//test/HelloService</namespace>
<serviceClass>test.IHelloService</serviceClass>
<implementationClass>test.HelloServiceImpl</implementationClass>
 
<inHandlers> 
 
<handler  handlerClass ="test.AuthenticationHandler" ></handler > 
 
</inHandlers>
</service>
</beans>


这样我们就完成了编码,下面启动tomcat,运行客户端代码,本文为abcd@1234位授权用户,使用abcd@1234,可以正常访问WS,如果用错误帐号,则会有以下异?/font>

 

Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: 非法的用户名和密?br />org.codehaus.xfire.fault.XFireFault: 非法的用户名和密?br />    at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
    at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
    at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
    at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
    at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
    at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
    at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
    at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
    at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
    at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
    at org.codehaus.xfire.client.Client.invoke(Client.java:336)
    at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
    at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
    at $Proxy0.getUser(Unknown Source)
    at test.ClientTest.main(ClientTest.java:39)

 

如果不在CientTest加以下增加Heade则会有以下异?/p>

 XFireProxy proxy = (XFireProxy)Proxy.getInvocationHandler(service);
Client client = proxy.getClient();
 client.addOutHandler(new ClientAuthenticationHandler("abcd1","1234"));

Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: 请求必须包含验证信息
org.codehaus.xfire.fault.XFireFault: 请求必须包含验证信息
    at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
    at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
    at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
    at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
    at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
    at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
    at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
    at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
    at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
    at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
    at org.codehaus.xfire.client.Client.invoke(Client.java:336)
    at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
    at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
    at $Proxy0.getUser(Unknown Source)
    at test.ClientTest.main(ClientTest.java:35)


Rabbit 2013-10-24 16:28 发表评论
]]>java实现简单的单点登录(转载) - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/rabbit/archive/2013/10/18/405392.htmlRabbitRabbitFri, 18 Oct 2013 01:44:00 GMT//www.ot7t.com.cn/rabbit/archive/2013/10/18/405392.html//www.ot7t.com.cn/rabbit/comments/405392.html//www.ot7t.com.cn/rabbit/archive/2013/10/18/405392.html#Feedback0//www.ot7t.com.cn/rabbit/comments/commentRss/405392.html//www.ot7t.com.cn/rabbit/services/trackbacks/405392.html阅读全文

Rabbit 2013-10-18 09:44 发表评论
]]>
解决IE下Iframe的Session丢失 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/rabbit/archive/2013/06/09/400441.htmlRabbitRabbitSun, 09 Jun 2013 07:57:00 GMT//www.ot7t.com.cn/rabbit/archive/2013/06/09/400441.html//www.ot7t.com.cn/rabbit/comments/400441.html//www.ot7t.com.cn/rabbit/archive/2013/06/09/400441.html#Feedback1//www.ot7t.com.cn/rabbit/comments/commentRss/400441.html//www.ot7t.com.cn/rabbit/services/trackbacks/400441.html主界面使用的是Iframe做的 动态内容嵌?需要登?但是每次刷新 session 都失?...

整个应用在FF下是正常的,但是在IE下每次点击下一页的时候都要重新登录。经过调试发现刷新后请求采用了新?sessionId,于是怀疑到了是Iframe的问题。在网上搜了一下,果真是IE的Iframe问题。IE6/IE7支持的P3P(Platform for Privacy Preferences Project (P3P) specification)协议默认阻止第三方无隐私安全声明的cookie,Firefox目前还不支持P3P安全?性,firefox中不存在此问题?br />具体的解决方式是在登录的Action处理方法?/span>加上 
response.setHeader("P3P","CP=CAO PSA OUR IDC DSP COR ADM DEVi TAIi PSD IVAi IVDi CONi HIS IND CNT"); 
问题搞定?/p>

Rabbit 2013-06-09 15:57 发表评论
]]>
struts 2标签 <s:textfield> 样式问题 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/rabbit/archive/2013/06/05/400213.htmlRabbitRabbitWed, 05 Jun 2013 02:29:00 GMT//www.ot7t.com.cn/rabbit/archive/2013/06/05/400213.html//www.ot7t.com.cn/rabbit/comments/400213.html//www.ot7t.com.cn/rabbit/archive/2013/06/05/400213.html#Feedback0//www.ot7t.com.cn/rabbit/comments/commentRss/400213.html//www.ot7t.com.cn/rabbit/services/trackbacks/400213.html初学struts2,在头脑中一直在想一个问题,就是对于struts2 ,当应用其自身的标签时,例如?/p>

<s:form>

   <s:textfield name="a"></s:textfield>

</s:form>

当查看源代码时为?/p>

<form>

<table>

    <tr><td><input type="text" name=a/></td></tr>

</table>

</form>

自动添加的table tr td 标签,但如果?一行显示多列怎么办?

网上查了查,有好多奇怪的解决办法,比如说通过在页面上判断,看什么时候输?lt;tr> 标签,但我认为,struts2这样做,那也太不人道了,后终于查到原因,现总结如下?/p>

原理:在struts2中加入了theme(主题)的概念,通过设置不同的主题,可以让struts的代码输出不同的html代码,你也就相应得到不同的布局效果?/p>

问题一:Struts2有哪些主题?

Struts2提供了三种主题,ajax, simple, xhtml,它默认的是xhtml主题,当然你可以写任意个你自己的主题,我们称之为自定义主题

问题二:Struts2怎么改?

有两种方法可以解?

1.简单的方法(也很实用)

在Struts.xml中,加上下一行代码就可以?/p>

<constant name="struts.ui.theme" value="simple" />

代表所有的页面采用的都?simple主题了,这时它输出的页面,不回添加任何多余的代码,比?table tr td 等,我们就可以像其他编辑页面的方式编辑页面的风格?/p>

或??<s:form 中添?theme

<s:form theme="simple"></s:form>

struts2每个标签都有theme属?/p>

2.在Struts.properties里改?/p>

#设置主题
struts.ui.theme=simple

可见另一篇:struts.properties



Rabbit 2013-06-05 10:29 发表评论
]]>
ORACLE中Like与Instr模糊查询性能大比?/title><link>//www.ot7t.com.cn/rabbit/archive/2013/01/21/394510.html</link><dc:creator>Rabbit</dc:creator><author>Rabbit</author><pubDate>Mon, 21 Jan 2013 07:51:00 GMT</pubDate><guid>//www.ot7t.com.cn/rabbit/archive/2013/01/21/394510.html</guid><wfw:comment>//www.ot7t.com.cn/rabbit/comments/394510.html</wfw:comment><comments>//www.ot7t.com.cn/rabbit/archive/2013/01/21/394510.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>//www.ot7t.com.cn/rabbit/comments/commentRss/394510.html</wfw:commentRss><trackback:ping>//www.ot7t.com.cn/rabbit/services/trackbacks/394510.html</trackback:ping><description><![CDATA[<p align="left" style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><strong class="yibqv"><span verdana","sans-serif";""="" 宋体;color:black;"="">ORACLE</span></strong><strong class="yibqv"><span style="font-family: 宋体; color: black;">?/span></strong><strong class="yibqv"><span verdana","sans-serif";""="" 宋体;color:black;"="">Like</span></strong><strong class="yibqv"><span style="font-family: 宋体; color: black;">?/span></strong><strong class="yibqv"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">Instr</span></strong><strong class="yibqv"><span style="font-family: 宋体; color: black;">模糊查询性能大比?/span></strong><strong class="yibqv"></strong></p><p align="left" style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p align="left" style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:red;""="" 0pt;"="" style="line-height: 28px; font-size: 12pt;">instr(title,'</span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">手册</span><span verdana","sans-serif";="" color:red;"="" style="line-height: 28px; font-size: 12pt;">')>0  </span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">相当?/span><span verdana","sans-serif";="" color:red;""="" 0pt;"="" style="line-height: 28px; font-size: 12pt;">  title like '%</span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">手册</span><span verdana","sans-serif";="" color:red;""="" 0pt;"="" style="line-height: 28px; font-size: 12pt;">%'</span></p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:red;""="" 0pt;"="" style="line-height: 28px; font-size: 12pt;">instr(title,'</span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">手册</span><span verdana","sans-serif";="" color:red;"="" style="line-height: 28px; font-size: 12pt;">')=1  </span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">相当?/span><span verdana","sans-serif";="" color:red;""="" 0pt;"="" style="line-height: 28px; font-size: 12pt;">  title like '</span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">手册</span><span verdana","sans-serif";="" color:red;""="" 0pt;"="" style="line-height: 28px; font-size: 12pt;">%'</span></p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:red;""="" 0pt;"="" style="line-height: 28px; font-size: 12pt;">instr(title,'</span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">手册</span><span verdana","sans-serif";="" color:red;"="" style="line-height: 28px; font-size: 12pt;">')=0  </span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">相当?/span><span verdana","sans-serif";="" color:red;""="" 0pt;"="" style="line-height: 28px; font-size: 12pt;">  title not like '%</span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">手册</span><span verdana","sans-serif";="" color:red;""="" 0pt;"="" style="line-height: 28px; font-size: 12pt;">%'</span></p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p align="left" style="line-height: 25px; margin: 7.5pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">t</span><span style="font-family: 宋体; color: black;">表中将近?/span><span verdana","sans-serif";="" color:black;"="">1100</span><span style="font-family: 宋体; color: black;">万数据,很多时候,我们要进行字符串匹配,在</span><span verdana","sans-serif";="" color:black;"="">SQL</span><span style="font-family: 宋体; color: black;">语句中,我们通常使用</span><span verdana","sans-serif";""="" 宋体;color:black;"="">like</span><span style="font-family: 宋体; color: black;">来达到我们搜索的目标。但经过实际测试发现?/span><span verdana","sans-serif";="" color:black;""="" 0pt;"="">like</span><span style="font-family: 宋体; color: black;">的效率与</span><span verdana","sans-serif";""="" 宋体;color:black;"="">instr</span><span style="font-family: 宋体; color: black;">函数差别相当大。下面是一些测试结果:</span></p><p align="left" style="line-height: 25px; margin: 7.5pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">SQL> set timing on<br />SQL> select count(*) from t where instr(title,'</span><span style="font-family: 宋体; color: black;">手册</span><span verdana","sans-serif";="" color:black;"="">')>0;</span></p><p align="left" style="line-height: 25px; margin: 7.5pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">  COUNT(*)<br />----------<br />     65881</span></p><p align="left" style="line-height: 25px; margin: 7.5pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">Elapsed: 00:00:11.04<br />SQL> select count(*) from t where title like '%</span><span style="font-family: 宋体; color: black;">手册</span><span verdana","sans-serif";="" color:black;"="">%';</span></p><p align="left" style="line-height: 25px; margin: 7.5pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">  COUNT(*)<br />----------<br />     65881</span></p><p align="left" style="line-height: 25px; margin: 7.5pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">Elapsed: 00:00:31.47<br />SQL> select count(*) from t where instr(title,'</span><span style="font-family: 宋体; color: black;">手册</span><span verdana","sans-serif";="" color:black;"="">')=0;</span></p><p align="left" style="line-height: 25px; margin: 7.5pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">  COUNT(*)<br />----------<br />  11554580</span></p><p align="left" style="line-height: 25px; margin: 7.5pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">Elapsed: 00:00:11.31<br />SQL> select count(*) from t where title not like '%</span><span style="font-family: 宋体; color: black;">手册</span><span verdana","sans-serif";="" color:black;"="">%';</span></p><p align="left" style="line-height: 25px; margin: 7.5pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span verdana","sans-serif";="" color:black;""="" 0pt;"="">  COUNT(*)<br />----------<br />  11554580</span></p><p align="left" style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span style="font-family: 宋体; color: black;">另外,我在结另外一?/span><span verdana","sans-serif";""="" 宋体;color:black;"="">2</span><span style="font-family: 宋体; color: black;">亿多的表,使?/span><span verdana","sans-serif";="" color:black;""="" 0pt;"="">8</span><span style="font-family: 宋体; color: black;">个并行,使用</span><span verdana","sans-serif";="" color:black;"="">like</span><span style="font-family: 宋体; color: black;">查询很久都不出来结果,但使用</span><span verdana","sans-serif";""="" 宋体;color:black;"="">instr,4</span><span style="font-family: 宋体; color: black;">分钟即完成查找,性能是相当的好。这些小技巧用好,工作效率提高不少。通过上面的测试说明,</span><span verdana","sans-serif";="" color:black;""="" 0pt;"="">ORACLE</span><span style="font-family: 宋体; color: black;">内建的一些函数,是经过相当程度的优化的?/span></p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span style="color: red;">instr(title,’aaa’)>0 </span><span style="color: red;">相当于like</span></p><p style="line-height: 25px; margin: 11.25pt 0cm; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span style="font-size: 10.5pt; color: red;">instr(title,’aaa’)=0 </span><span style="font-size: 10.5pt; color: red;">相当于not like</span></p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><strong class="yibqv"><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">特殊用法?/span></strong><strong class="yibqv"></strong></p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span style="line-height: 28px; font-size: 12pt; color: red;">select   id, name from users where instr('101914, 104703', id) > 0; <br />  </span><span style="line-height: 28px; font-size: 12pt; font-family: 宋体; color: red;">它等价于</span><span style="line-height: 28px; font-size: 12pt; color: red;"> <br />select   id, name from users where id = 101914 or id = 104703;</span></p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"> </p><p align="left" style="line-height: 22px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: white; word-break: break-all;"><span style="line-height: 25px;"><a rel="nofollow" href="//www.ot7t.com.cn/heyang/archive/2011/07/17/354478.html" style="color: #863417; text-decoration: initial;"><strong class="yibqv"><span style="line-height: 24px; font-size: 11pt; font-family: 宋体; color: #646464;"><span style="line-height: 27px;">使用</span></span></strong><strong class="yibqv"><span verdana","sans-serif";="" color:#646464;"="" style="line-height: 24px; font-size: 11pt;">Oracle</span></strong><strong class="yibqv"><span style="line-height: 24px; font-size: 11pt; font-family: 宋体; color: #646464;"><span style="line-height: 27px;">?/span></span></strong><strong class="yibqv"><span verdana","sans-serif";="" color:#646464;"="" style="line-height: 24px; font-size: 11pt;">instr</span></strong><strong class="yibqv"><span style="line-height: 24px; font-size: 11pt; font-family: 宋体; color: #646464;"><span style="line-height: 27px;">函数与索引配合提高模糊查询的效率</span></span></strong></a></span><strong style="line-height: 25px;"></strong></p><p align="left" style="line-height: 22px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: white; word-break: break-all;"><span style="line-height: 19px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">一般来说,?/span><span verdana","sans-serif";""="" 宋体;color:#4b4b4b;"="" style="line-height: 19px; font-size: 9pt;">Oracle</span><span style="line-height: 19px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">数据库中,我们对</span><span verdana","sans-serif";""="" 宋体;color:#4b4b4b;"="" style="line-height: 19px; font-size: 9pt;">tb</span><span style="line-height: 19px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">表的</span><span verdana","sans-serif";""="" 宋体;color:#4b4b4b;"="" style="line-height: 19px; font-size: 9pt;">name</span><span style="line-height: 19px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">字段进行模糊查询会采用下面两种方式:</span><span verdana","sans-serif";="" color:#4b4b4b;""="" 0pt;"="" style="line-height: 19px; font-size: 9pt;"><br style="line-height: 21px;" />1.select * from tb where name like '%XX%';<br style="line-height: 21px;" />2.select * from tb where instr(name,'XX')>0;<br style="line-height: 21px;" /><br style="line-height: 21px;" /></span><span style="line-height: 19px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">若是?/span><span verdana","sans-serif";""="" 宋体;color:#4b4b4b;"="" style="line-height: 19px; font-size: 9pt;">name</span><span style="line-height: 19px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">字段上没有加索引,两者效率差不多,基本没有区别?/span><span verdana","sans-serif";="" color:#4b4b4b;""="" 0pt;"="" style="line-height: 19px; font-size: 9pt;"><br style="line-height: 21px;" /><br style="line-height: 21px;" /></span><span style="line-height: 19px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">为提高效率,我们?/span><span verdana","sans-serif";""="" 宋体;color:#4b4b4b;"="" style="line-height: 19px; font-size: 9pt;">name</span><span style="line-height: 19px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">字段上可以加上非唯一性索引:</span><span verdana","sans-serif";""="" 宋体;color:#4b4b4b;"="" style="line-height: 19px; font-size: 9pt;"><br style="line-height: 21px;" />create index idx_tb_name on tb(name);<br style="line-height: 21px;" /><br style="line-height: 21px;" /></span><span style="line-height: 19px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">这样,再使用</span><span verdana","sans-serif";""="" 宋体;color:#4b4b4b;"="" style="line-height: 19px; font-size: 9pt;"></span></p><p align="left" style="line-height: 22px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: white; word-break: break-all;"><span verdana","sans-serif";="" color:#4b4b4b;""="" 0pt;"="" style="line-height: 19px; font-size: 9pt;">select * from tb where instr(name,'XX')>0;</span></p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: #4c402b; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #fbf8f4;"><span style="line-height: 21px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">这样的语句查询,效率可以提高不少,表数据量越大时两者差别越大。但也要顾及?/span><span verdana","sans-serif";="" color:#4b4b4b;""="" 0pt;"="" style="line-height: 21px; font-size: 9pt;">name</span><span style="line-height: 21px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">字段加上索引?/span><span verdana","sans-serif";""="" 宋体;color:#4b4b4b;"="" style="line-height: 21px; font-size: 9pt;">DML</span><span style="line-height: 21px; font-size: 9pt; font-family: 宋体; color: #4b4b4b;">语句会使索引数据重新排序的影响?/span></p><img src ="//www.ot7t.com.cn/rabbit/aggbug/394510.html" width = "1" height = "1" /><br><br><div align=right><a href="//www.ot7t.com.cn/" title="四川福利彩票快乐12">四川福利彩票快乐12</a> 2013-01-21 15:51 <a href="//www.ot7t.com.cn/rabbit/archive/2013/01/21/394510.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <script>(function(){ var src = (document.location.protocol == "http:") ? "//js.passport.qihucdn.com/11.0.1.js?f7a6bc378844a5df707c414e6b6fea33":"https://jspassport.ssl.qhimg.com/11.0.1.js?f7a6bc378844a5df707c414e6b6fea33"; document.write('<script src="' + src + '" id="sozz"><\/script>'); })(); </script>