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

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
natal
Posts: 5
Joined: Mon 08 Aug 2005 16:23

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

Post by natal » Thu 13 Oct 2005 14:58

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

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Fri 14 Oct 2005 13:45

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;
....

natal
Posts: 5
Joined: Mon 08 Aug 2005 16:23

Post by natal » Sat 15 Oct 2005 12:16

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;

Post Reply