Question: I want to be able to read and write to a PC client using text_io. I cannot use utl_file because I do not have Oracle database installed on the remote client. How do I invoke text_io?
Answer: The Oracle text_io package can write to the local machine rather than server side (such as utl_file).
Here is an example of using the text_io utility to write across platforms. This is invoked from the Oracle server and writes to the connected remote PC client:
declare
l_out_file text_io.file_type;
begin
l_out_file := text_io.fopen( 'c:\text.txt', 'w' ); -- w is write, r is read
text_io.put (l_out_file, 'New text' );
text_io.new_line( l_out_file, 1 ); -- 1 new line
text_io.fclose( l_out_file );
end;/
Here is an example of using the text_io utility to read across platforms.
declare
l_out_file text_io.file_type;
linelog varchar2(32767);
begin
l_out_file := text_io.fopen( 'c:\text.txt', 'r' ); -- w is write, r is read
Loop
text_io.get_line( l_out_file, linelog ); -- get line
Insert into tmptable(linelog);
End Loop;
text_io.fclose( l_out_file );
Commit;
end;/
Answer: The Oracle text_io package can write to the local machine rather than server side (such as utl_file).
Here is an example of using the text_io utility to write across platforms. This is invoked from the Oracle server and writes to the connected remote PC client:
declare
l_out_file text_io.file_type;
begin
l_out_file := text_io.fopen( 'c:\text.txt', 'w' ); -- w is write, r is read
text_io.put (l_out_file, 'New text' );
text_io.new_line( l_out_file, 1 ); -- 1 new line
text_io.fclose( l_out_file );
end;/
Here is an example of using the text_io utility to read across platforms.
declare
l_out_file text_io.file_type;
linelog varchar2(32767);
begin
l_out_file := text_io.fopen( 'c:\text.txt', 'r' ); -- w is write, r is read
Loop
text_io.get_line( l_out_file, linelog ); -- get line
Insert into tmptable(linelog);
End Loop;
text_io.fclose( l_out_file );
Commit;
end;/
3 comments:
GOOD
Please, how can i open a file to overwrite the file?
Use 'a' to append an exsiting file
Post a Comment