delphi中查询字符长度为4的数据 奖励50分

来源:百度知道 编辑:UC知道 时间:2024/06/11 10:43:06
delphi中查询字符长度为4的数据,就是有个product表,想把pname
中字符长度为4的数据给查询出来,为什么提示不正常的数据定义呢?

ADOQuery1.Close;
ADOQuery1.SQL.Clear;ADOQuery1.SQL.Add('select * from product');
ADOQuery1.SQL.Add('select * from product where length(pname):=4');
ADOQuery1.Open;//执行新的SQL语句
if ADOQuery1.RecordCount = 0 then
ShowMessage('没有这条记录');
复制错了一点 select是没有重复的 就是第二句后面是没有的

下面这样就可以:
ADOQuery1.SQL.Add('select * from product where length(pname)=4');

注意:条件判断使用=,不要使用赋值号:=

Delphi 在使用SQL语句加条件时 = 前不用加:号,你记住!