<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!-- [if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --> <!-- [endif]-->
搜索关键字,按空格分开,结果要按精确度从高到低显示,比如:
查找的关键字 ---> ASP JAVA PHP FLEX
数据库记录集 --->
ID CONTENT
1 JAVA 是面对对象的语言
2 PHP 学起来比 JAVA 要容易点
3 ASP 比 PHP 用起来简单, PHP 比 JAVA 用起来简单
4 FLEX 做出来的界面好漂亮,而且可以和 ASP,PHP,JAVA 结合使用
5 ASP , PHP 用来做网页都不错
那么搜索的结果排序应该是
ID
4 --> 出现了 4 个关键字
3 --> 出现了 3 个关键字
2 --> 出现了 2 个关键字
5 --> 出现了 2 个关键字
1 --> 出现了 1 个关键字
方法:
with a as( select 1 id,'JAVA是面对对象的语言' content from dual union all select 2 id,'PHP学起来比JAVA要容易点 ' content from dual union all select 3 id,'ASP比PHP用起来简单,PHP比JAVA用起来简单' content from dual union all select 4 id,'FLEX做出来的界面好漂亮,而且可以和ASP,PHP,JAVA结合使用' content from dual union all select 5 id,'ASP,PHP用来做网页都不错' content from dual ), b as(--这个b表就是存放关键字的表 select 'JAVA' content from dual union all select 'PHP' from dual union all select 'ASP' from dual union all select 'FLEX' from dual) select id || '-->' || '出现了' ||cnt||'个关键字' name from(select id,sum((case when instr(a.content,b.content)>0 then 1 else 0 end)) cnt from a,b group by a.id) order by cnt desc; NAME -------------------------------------------------------------------------------- 4-->出现了4个关键字 3-->出现了3个关键字 2-->出现了2个关键字 5-->出现了2个关键字 1-->出现了1个关键字
<!-- [endif]-->提供个类似 分割关键字 存储到表中的函数
函数的功能 将传入的字符串 (a,bdc,fde,23,rd,sasp) 拆分放到一个表 a 里
create or replace procedure testpro(v_str varchar2) as sqlstr varchar2(4000 ); v_sqlstr varchar2(4000 ); begin v_sqlstr:=','||v_str||','; sqlstr:='insert into a select substr('''||v_sqlstr||''',instr('''||v_sqlstr||''','','',1,rownum)+1, instr('''||v_sqlstr||''','','',1,rownum+1)- instr('''||v_sqlstr||''','','',1,rownum)-1) newid from dual connect by rownum <= length('''||v_sqlstr||''') - length(replace('''||v_sqlstr||''', '','', ''''))-1'; execute immediate sqlstr; --dbms_output.put_line(sqlstr); end;
原帖: http://topic.youkuaiyun.com/u/20110313/13/3f5161fb-f3af-4ae1-801c-0f713c5dcb4e.html?9333
2412

被折叠的 条评论
为什么被折叠?



