DELPHi 中 varchar转换为numeric
procedure TForm1.Button1Click(Sender: TObject); var temp :double; str:String;begin with adoquery1 do begin close; sql.Clear; sql.Add('select * from table1 where ID='''+edit1.Text+''''); open; temp:=fieldByName('colA').AsFloat; str:=floattostr(temp); showmessage('取出来的值='+floattostr(temp)); end; with ADOCommand1 do begin adocommand1.CommandText:='insert table2 values (cast('''+str+''' as decimal(18,5)))'; //adocommand1.CommandText:='insert table2 values (''+temp+'')'; Execute; end;end;如果想像Java一样直接写到拼接到sql语句中不可取,现在实验得到的办法就是先转换为String类型,然后使用数据库的函数cast()来处理。
例子:select cast('20.37554' as decimal(18,5))