with ADOQuery1 do begin SQL.Text := 'Select Count(*) reccount From CS_Mst'; Open; showMessage(FieldByName('reccount').AsVariant); end;
var iReccount:Integer; begin with ADOQuery1 do begin if Active then Close; SQL.Clear; SQL.Add('Select Count(*) reccount From CS_Mst'); Open; iReccount:=FieldByName('reccount').AsInteger; end; end;
delphi的帮助: Unlike TADOQuery components, which use different methods to execute depending on whether they return a result set, TADOCommand always uses the Execute command to execute the command, regardless of whether it returns a result set. When the command returns a result set, Execute returns an interface to the ADO _RecordSet interface.The most convenient way to work with this interface is to assign it to the RecordSet property of an ADO dataset.For example, the following code uses TADOCommand (ADOCommand1) to execute a SELECT query, which returns a result set. This result set is then assigned to the RecordSet property of a TADODataSet component (ADODataSet1).with ADOCommand1 do begin CommandText := 'SELECT Company, State ' + 'FROM customer ' + 'WHERE State = :StateParam'; CommandType := cmdText; Parameters.ParamByName('StateParam').Value := 'HI'; ADODataSet1.Recordset := Execute; end;As soon as the result set is assigned to the ADO dataset's Recordset property, the dataset is automatically activated and the data is available. 我懒得写代码啦,贴点帮助,对于存储过程,取返回值也是一样的原理,你加个跟踪,检查一下返回结果就明白了(OleVariant)。
我想楼上2位误会了我的意思,我再把上面的代码加长点吧。 在Oracle里如: declare reccount number(6); Rstr varchar2(10); begin Select Count(*) into reccount From MyTable; if reccount=0 then .... Rstr='Not Record'; else .... Rstr='Find Record'; endif; end;问:在Delphi中如何读取RStr的值?
楼主:尽管把上面的代码加长了、但関鍵的定義部分還是没有給出来呀。 俺写出一個、提供参考。---- Oracle Function -------------------------------- CREATE FUNCTION myFun(a IN VARCHAR2, b IN VARCHAR2) RETURN NUMBER IS BEGIN RETURN To_Number(a) + To_Number(b); END;---- Delphi ------------------------------------------ with ADOQuery1 do begin SQL.Text := 'select myFun(''5'',''6'') myValues from dual'; Open; showMessage(FieldByName('myValues').AsVariant); end;
SQL.Text := 'Select Count(*) reccount From CS_Mst';
Open;
showMessage(FieldByName('reccount').AsVariant);
end;
iReccount:Integer;
begin
with ADOQuery1 do
begin
if Active then
Close;
SQL.Clear;
SQL.Add('Select Count(*) reccount From CS_Mst');
Open;
iReccount:=FieldByName('reccount').AsInteger;
end;
end;
Unlike TADOQuery components, which use different methods to execute depending on whether they return a result set, TADOCommand always uses the Execute command to execute the command, regardless of whether it returns a result set. When the command returns a result set, Execute returns an interface to the ADO _RecordSet interface.The most convenient way to work with this interface is to assign it to the RecordSet property of an ADO dataset.For example, the following code uses TADOCommand (ADOCommand1) to execute a SELECT query, which returns a result set. This result set is then assigned to the RecordSet property of a TADODataSet component (ADODataSet1).with ADOCommand1 do begin
CommandText := 'SELECT Company, State ' +
'FROM customer ' +
'WHERE State = :StateParam';
CommandType := cmdText;
Parameters.ParamByName('StateParam').Value := 'HI';
ADODataSet1.Recordset := Execute;
end;As soon as the result set is assigned to the ADO dataset's Recordset property, the dataset is automatically activated and the data is available. 我懒得写代码啦,贴点帮助,对于存储过程,取返回值也是一样的原理,你加个跟踪,检查一下返回结果就明白了(OleVariant)。
在Oracle里如:
declare
reccount number(6);
Rstr varchar2(10);
begin
Select Count(*) into reccount From MyTable;
if reccount=0 then
....
Rstr='Not Record';
else
....
Rstr='Find Record';
endif;
end;问:在Delphi中如何读取RStr的值?
俺写出一個、提供参考。---- Oracle Function --------------------------------
CREATE FUNCTION myFun(a IN VARCHAR2, b IN VARCHAR2)
RETURN NUMBER
IS
BEGIN
RETURN To_Number(a) + To_Number(b);
END;---- Delphi ------------------------------------------
with ADOQuery1 do begin
SQL.Text := 'select myFun(''5'',''6'') myValues from dual';
Open;
showMessage(FieldByName('myValues').AsVariant);
end;