Delphi使用ADO执行SQL时报错:ORA-00937: not a single-group group function
Delphi使用ADO进行数据库编程时,执行SQL会报错,下面是详细的说明
有三种方式拼接SQL
**方式1会报错**:ORA-00937: not a single-group group function
adoquery.Close;
adoquery.SQL.Text := 'select count(*) icount from testtable where testno = :no and testname = :name ';
adoquery.Parameters.ParamByName('no').Value := Number;
adoquery.Parameters.ParamByName('name').Value := Name;
adoquery.Open;
adoquery.First;
Result := adoquery.FieldByName('icount').AsInteger ;
**方式2可以执行**
adoquery.Close;
adoquery.SQL.Text := Format('select count(*) icount from testtable where testno = ''%s'' and testname = ''%s'' ', [Number, Name]);
adoquery.Open;
adoquery.First;
Result := adoquery.FieldByName('icount').AsInteger ;
**方式3可以执行**
adoquery.Close;
adoquery.SQL.Text := 'select * from ( select count(*) from testtable where testno = :no and testname = :name )';
adoquery.Parameters.ParamByName('no').Value := Number;
adoquery.Parameters.ParamByName('name').Value := Name;
adoquery.Open;
adoquery.First;
Result := adoquery.Fields[0].AsVariant
补充说明:
第一种报错的SQL方式是在MSDAORA.1驱动下报错,但是使用OraOLEDB.Oracle.1驱动可以
到底是为什么