Page 1 of 1

As To obtain I number of registries that a table has.

Posted: Thu 13 Oct 2005 14:58
by natal
Work with Delphi 6, component 4.50.3.24 ODACnet and Oracle 9i. My question is as to pass the result of the following consultation to a variable:

Code: Select all

 
   fdm.OraSQL_liq.SQL.Clear;
   fdm.OraSQL_liq.SQL.Text := 'select count(*) as REG from desarrollo.ta_liquidaciones';
   fdm.OraSQL_liq.execute;
   
   numreg.value:= ?????? 
Thanks and a greeting to all.
Jose Manuel

Posted: Fri 14 Oct 2005 13:45
by Alex
The TOraSQL doesn't return resultset, to perform your task you should use the following approach:

Code: Select all

Value : integer;
...
OraSQL1.SQL.Text := 'begin select count(*) INTO :Result from emp; end;';
OraSQL1.Params[0].ParamType := ptOutput;
OraSQL1.Params[0].DataType := dtInteger;
OraSQL1.Execute;
Value :=  OraSQL1.ParmByName('Result').AsInteger;
....

Posted: Sat 15 Oct 2005 12:16
by natal
Thanks for the answer, the correct solution I have found it in the DEMO of ODAC, concretely in example "SQL". Greetings for all.

Code: Select all

procedure TfInformacion.Btn_iniciarClick(Sender: TObject);
begin
   OraSQL1.SQL.Clear;
   OraSQL1.SQL.Text := 'Declare'+#13+
                       ' c Integer;'+#13+
                       'begin'+#13+
                       '  SELECT Count(*)'+#13+
                       '    INTO :c'+#13+
                       '    FROM desarrollo.personal;'+#13+
                       'end;';
   OraSQL1.Params[0].DataType := ftInteger;
   OraSQL1.Execute;
end;

Code: Select all

procedure TfInformacion.OraSQL1AfterExecute(Sender: TObject; Result: Boolean);
begin
      memo1.Lines.Add('NÂș de Registros = ' + formatfloat('#,##0',OraSQL1.Params[0].AsInteger));
end;