Home » SQL & PL/SQL » SQL & PL/SQL » TEXT_IO
TEXT_IO [message #388217] Mon, 23 February 2009 22:12 Go to next message
blood98
Messages: 14
Registered: January 2009
Location: Thai
Junior Member

I WANT TO QUERY DATA IN TABLE TO TEXT_FILE

DECLARE
Cursor c1 'select * from my table '
BEGIN
for txt in c1
text_io(outfile,txt.name,',');

END;

but I don't like to write a name of my fild in my table

i have more table to write it
Re: TEXT_IO [message #388661 is a reply to message #388217] Wed, 25 February 2009 21:03 Go to previous messageGo to next message
Kevin Meade
Messages: 2101
Registered: December 1999
Location: Connecticut USA
Senior Member
I do not understand your question.

There are syntax errors in your plsql. You will find one thing that really ticks people off on this site is the posting of "fake" code. Make sure if you post anything, that it works (at least the parts that are real anyway).

I hazard a guess and think your comment that you don't want to hard code your column name, means you might wish to look at DBMS_SQL and EXECUTE IMMEDIATE. Both are forms of dynamic sql. Google and do some reading about it. However, in the end you must reference something with data you have to work with a column name somewhere.

Good luck, Kevin
Re: TEXT_IO [message #388666 is a reply to message #388217] Wed, 25 February 2009 21:40 Go to previous messageGo to next message
blood98
Messages: 14
Registered: January 2009
Location: Thai
Junior Member

Can you see this code
declare

out_file TEXT_IO.File_Type;

cursor c1 is <---
select a,b,c,d,e,f,g from data ;

begin
out_file := TEXT_IO.Fopen('C:txt.txt','w');
for r in ci
TEXT_IO.PUT(out_file,r.a||','); <---
TEXT_IO.PUT(out_file,r.b||','); <---
TEXT_IO.PUT(out_file,r.c||','); <---
TEXT_IO.PUT(out_file,r.d||','); <---
TEXT_IO.PUT(out_file,r.e||','); <---
TEXT_IO.PUT(out_file,r.f||','); <---
TEXT_IO.PUT(out_file,r.g); <---

TEXT_IO.NEW_LINE(out_file,1);
end loop;
TEXT_IO.Put_Line('Closing the file...');
TEXT_IO.FCLOSE (out_file);
end;

if i have another tabel in my database
I write this code again and in put my fild to

You have another change to write a new code or fix it to short

or write report.rdf to text file
my text file come for report.rdf



Re: TEXT_IO [message #388672 is a reply to message #388217] Wed, 25 February 2009 22:00 Go to previous message
Kevin Meade
Messages: 2101
Registered: December 1999
Location: Connecticut USA
Senior Member
If I understand, then you might try using refcursors from a package to select the query you want to execute. Then the cursor will not be in your forms code below, just a call to procedure. You will have to pass enough information to figure out which cursor to open etc.

Alternatively you could try writing some kind of union all view that combined queries together and then construct you where clauses such that only one of the selects in your union all view would actually get executed depending upon how you query the view.

The textio line however, you are pretty much stuck with I think. Thus you need to make all your queries have the same column names. Thus the suggestions above for use of refcursor or manually partitioned view.

good luck, Kevin
Previous Topic: please help me in SQL statement
Next Topic: plsql concatenate how i do that
Goto Forum:
  


Current Time: Mon Dec 05 13:09:35 CST 2016

Total time taken to generate the page: 0.05962 seconds