Delphi使用ADO进行数据库编程时,执行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驱动可以
http://blog.csdn.net/eagletian/article/details/18621
你的sql没有什么问题,应该是驱动的问题。
sqlserver 链接oracle可以通过两个访问接口:“MSDAORA” 和“OraOLEDB.Oracle”
1、“MSDAORA”访问接口是由Microsoft OLE DB Provider for Oracle提供的。通过该访问接口建立的链接服务器在进行查询oracle表(带数据类型CLOB、BLOB字段)时会报错。
2、“OraOLEDB.Oracle” 访问接口是由oracle 的Oracle Probider for OLE DB 驱动提供的。它解决了两个数据库类型不一致的的问题。而且如果需要使用分布式事务,必须使用它来创建链接服务器。
二者在使用上,有些语法不一样。建议使用oracle厂商的原版驱动吧。