query:="SELECT TO_CHAR(SYSDATE,'MM/DD/YYYY')||' 07:00:00' AS Data_Time ,X.FLOW AS Flow,'HWSC' AS Site,";碰到SQL语句里面有单引号,怎么处理?

解决方案 »

  1.   

    在Delphi中 '号以''来表示 如果 name='aaa' 那么要这样写 '''aaa'''
      

  2.   

    我在盒子(bbs.2ccc.com)中有个针对这个问题的贴子自己去查找.
      

  3.   

    原贴出在 http://bbs.2ccc.com/topic.asp?topicid=142013
    要用到 StringReplace,请uses strUtils.const
     OldPattern='''';
     NewPattern='''''';
    var
      txtFile:TextFile;
      strTxt:string;
      strErrHandle,strHelpRes,strS:string;
      intLen,intAtSignPos:Integer;
    begin
      if dlgOpen1.Execute then
      begin
        AssignFile(txtFile,dlgOpen1.FileName);
        Reset(txtFile);
        redt1.Font.Size:=10;
        redt1.Clear;
        while not Eof(txtFile) do
        begin
          Readln(txtfile,strtxt);
          strS:=StringReplace(strTxt,OldPattern,NewPattern,[rfReplaceAll]);
          intLen:=Length(strS);
          intAtSignPos:=pos('@',strS);
          strErrHandle:=LeftBStr(strS,intAtSignPos-1);
          strHelpRes:=RightBStr(strS,intLen-intAtSignPos);
          with qry1 do
            begin
              Close;
              SQL.Clear;
              SQL.Add('INSERT INTO TEST1 (DESR,TEST) VALUES ');
              SQL.Add('('''+ strErrHandle +''',''' + strHelpRes+''')');
              ExecSQL;
              //ShowMessage(SQL.Text);
            end;
          //ShowMessage(strErrHandle);
          //ShowMessage(strHelpRes);
        end;
        CloseFile(txtFile);
      end;
    end;
      

  4.   

    有一個函數QuotedStr你應該可以用
      

  5.   

    QuotedStr不行!
    只有用替换的方法,把'替换为:''
      

  6.   

    'select * from a where 字段1='''+edit1.text+''''
      

  7.   

    这个问题光讲也不太好讲清楚,简单的办法,把SQL.TEXT SHOW出来看看不就知道了么.