输入的查询条件例如是  :(Delphi 数据库相关)
怎样从表的字段中查询含有输入条件的任一字符,使之可以按(delphi)查询
也可按照(数据库)查询 也可查询包含"相关"

解决方案 »

  1.   

    还是我自己顶下把
    用substring可以吗?
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var selectstr,sql:string;  //////////按空格分词
        strlist:tstrings;
        position:integer;
    begin
       selectstr:='  数据库 delphi 中国  ';
       strlist:=TStringList.create();
       while pos(' ',selectstr)>0 do
         begin
            position:=pos(' ',selectstr);
            if position=1 then selectstr:=copy(selectstr,2,length(selectstr)-1)
                          else
                            begin
                              strlist.Add(copy(selectstr,1,position));
                              selectstr:=copy(selectstr,position,length(selectstr)-position);
                              showmessage(selectstr);
                            end;
         end;
       //分词完成,词放在strlist中,下面为sql语句
       sql:='select * from 表名 where (字段名 like %delphi%) or (字段名 like %数据库%')
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var selectstr,sql:string;  //////////按空格分词
        strlist:tstrings;
        position,i:integer;
    begin
       selectstr:='  数据库 delphi 中国  ';
       strlist:=TStringList.create();
       while pos(' ',selectstr)>0 do
         begin
            position:=pos(' ',selectstr);
            if position=1 then selectstr:=copy(selectstr,2,length(selectstr)-1)
                          else
                            begin
                              strlist.Add(copy(selectstr,1,position));
                              selectstr:=copy(selectstr,position,length(selectstr)-position);
                              showmessage(selectstr);
                            end;
         end;
       //分词完成,词放在strlist中,下面为sql语句    sql:='select * from 表名 where ';
       for i:=0 to strlist.Count-1 do
         if i=strlist.Count-1 then sql:=sql+'(字段名 like ''%'+strlist.Strings[i]+'%'')'
                             else sql:=sql+'(字段名 like ''%'+strlist.Strings[i]+'%'') or';
       sql:=sql+')';
       showmessage(sql);
    end;
      

  4.   

    完全实现你的要求很难:对于英文来说,单词是有空格的,而对于汉字的词间是没有空格的,如数据库相关,可以分为数据库和相关,也可以分为数据、库和相关,没有一定的标准。所以只能先区分是英文还是汉字,用ascii码区分,然后对于英文用空格分开单词,而对于汉字,则只能拆成一个个的汉字,没有办法拆成词,除非你自己编写或从网上查找一个词库。
      

  5.   

    按照 guolvguolv(盲鹰) ( ) 的
    我出现了参数不足,期待为一的错误,
    怎么改都不行