Thursday, January 24, 2008

File Operations with Oracle

How to read a file using PL/SQL


declare
input_buffer varchar2(4000);
successful_output_file utl_file.file_type;
begin
successful_output_file := utl_file.fopen ('/tmp','mytest.txt', 'W');
input_buffer := 'ask'||'|'||'nava';
DBMS_OUTPUT.PUT_LINE(input_buffer);
utl_file.put_line(successful_output_file,input_buffer);
utl_file.fclose(successful_output_file);
end;



How to write to file using PL/SQL


declare
input_buffer varchar2(4000);
input_file utl_file.file_type;
begin
input_file := utl_file.fopen ('/tmp','mytest.txt', 'R');
utl_file.get_line(input_file,input_buffer);
DBMS_OUTPUT.PUT_LINE(input_buffer);
utl_file.fclose(input_file);
end;

No comments: