select a column and create a text file

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
nclark
Posts: 19
Joined: Wed 10 Oct 2007 11:45
Location: Norway

select a column and create a text file

Post by nclark » Thu 24 Jan 2008 16:24

Hi,

I am new to Delphi /Odac so forgive me.

I have a column in an oracle table that I would like sorted and dumped to a text file. Each row being a new line. Approximately 1000 rows in the table.

What is the best method for doing this?
I would very much appreciate explicit code in your reply please.

I would assume:
define a query in OraQuery component with order by included
assign and rewrite (text) file giving filevariable fv.
fetch first row
while not eof do
begin
Writeln (fv, "fetched row")
fetch
end
close (fv);

To be honest it is the fetch that I am unfamilar with. How is this done?
Also I was wondering of the select and save at text file could be done in two statements.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 25 Jan 2008 12:37

You should use a code like the following

Code: Select all

  AssignFile(fv, 'myfile');
  Rewrite(fv);
  OraQuery.Open;
  while not OraQuery.Eof do begin
    WriteLn(fv, OraQuery.FieldByName('MY_FIELD').AsString);
    OraQuery.Next;
  end;
  OraQuery.Close;
  CloseFile(fv);

nclark
Posts: 19
Joined: Wed 10 Oct 2007 11:45
Location: Norway

Post by nclark » Fri 25 Jan 2008 14:14

This worked fine. Thank you

Post Reply