sql server 中文模糊查询,
比如:我数据库里存的是“北京百度在线网络技术有限公司”
查询:“百度”“百度网络”“北京百度”“百度公司”关键字
结果:都能得到“北京百度在线网络技术有限公司”以及表中其它字段的内容。
谢谢!

解决方案 »

  1.   

    我这有个比较笨的方法:
    String str = "百度公司";
    StringBuffer strBuffer = new StringBuffer();
    strBuffer.append("%");
    int len = str.length();
    for (int i = 0; i < len; i++) {
    strBuffer.append(str.charAt(i));
    strBuffer.append("%");
    }
    String sql = "SELECT * FROM TABLE WHERE COL1 LIKE " + strBuffer.toString();
      

  2.   

    like %百%度%网%络%
    把需要查询的汉字拆分,然后在每个汉字前后加上%,效率不怎么高
      

  3.   

    像“百度网络”这样不连续的,用sql是不能实现模糊搜索的。用lucene。
      

  4.   

    Dim S_Key,RST,StrSQL
    t = timer
    S_Key = Trim(Request("key")) '得到搜索关键字的值 
    If S_Key <>"" then 
    Set RST=Server.CreateObject("ADODB.RecordSet") 
    'StrSQL=AutoKey(S_Key) '此处使用自定义函数 AutoKey(),该函数为实现智能搜索的核心
    RST.Open StrSQL,CNN,3,2 '得到搜索后的记录
    If RST.BOF And RST.EOF Then 
    %>
            <font color="#FF0000">未找到任何结果!!!</font>
            <% 
    Else 
    %>
    <% 
    While Not RST.EOF '遍历整个记录集,显示搜索到的信息并设置链接  %>
              <!-- 此处可设所需要的链接目标 -->
              
              <img src="images/file.jpg" width="32" height="32"><font style="font: 12pt 宋体"><a href="<%= RST("DocPath")%>" target="_blank"><%response.Write(Str1)%>
              </a></font><br>
              <!-- 显示部分详细内容 -->
              <font style="font: 10pt 宋体"><%= Left(Str2,500) %></font>
            <p align="left">
              <% 
    RST.MoveNext 
    Wend 
    RST.Close 
    Set RST=Nothing 
    End If 
    End If 
     
    'Function AutoKey(strKey) 
    'CONST lngSubKey=2 
    'Dim lngLenKey, strNew1, strNew2, i, strSubKey '检测字符串的合法性,若不合法则转到出错页。出错页根据需要进行设定。 
    'if InStr(strKey,"=")<>0 or InStr(strKey,"`")<>0 or InStr(strKey,"'")<>0 or InStr(strKey," ")<>0 or InStr(strKey," ")<>0 or InStr(strKey,"'")<>0 or InStr(strKey,chr(34))<>0 or InStr(strKey,"\")<>0 or InStr(strKey,",")<>0 or InStr(strKey,"<")<>0 or InStr(strKey,">")<>0 then 
    'Response.Redirect "error.htm" 
    'End If 'lngLenKey=Len(strKey) 
    'Select Case lngLenKey 
    'Case 0 '若为空串,转到出错页 
    'Response.Redirect "error.htm" 
    'Case 1 '若长度为1,则不设任何值 
    'strNew1="" 
    'strNew2="" 
    'Case Else '若长度大于1,则从字符串首字符开始,循环取长度为2的子字符串作为查询条件 
    'For i=1 To lngLenKey-(lngSubKey-1) 
    'strSubKey=Mid(strKey,i,lngSubKey) 
    'strNew1=strNew1 & " or 字段 like '%" & strSubKey & "%'" 
    'strNew2=strNew2 & " or 字段 like '%" & strSubKey & "%'" 
    'Next 
    'End Select '得到完整的SQL语句 
    'AutoKey="Select * from table where 字段 like '%" & strKey & "%' or 字段 like '%" & strKey & "%'" & strNew1 & strNew2 
    'AutoKey="Select * from table where 字段 like '%" & strKey & "%'" & strNew1'End Function
    CNN.Close 
    Set CNN=Nothing 
    %>
    一段基本实现模糊查询的函数,自己看看吧
      

  5.   

    " 百度 " 的前后加 "%" ,还要用like ,即:like '%百度%'
      

  6.   

    还有一个问题 
    String str = "00180019SO200806160001"; 
    String s = str.substring(8,10); 
    结果:SO 
    可是在sql server 中 
    where substring(dbBillCode,8,10) = 'SO' order  by  (dbBillCode)  desc 
    库里,有数据,但是为空。
      

  7.   

    1. 对查询条件作分词处理,即把查询条件按语义由“北京百度”拆分成 “北京”“百度”两个关键词。
    2. 使用1中分词结果构建类似下面的查询语句 SELECT * FROM table WHERE name LIKE "%北京%百度%"关键技术是如何正确的分词,这也是许多搜索引擎设计的一个关键技术,分词是否准确决定了搜索结果的精确度。
      

  8.   

    查查你使用的数据库手册,substring 是Java中的方法,数据库中有相似功能的函数,不能弄混了。