--读文件
set serveroutput on;
declare
l_dir varchar2(100);
l_file_name varchar2(100);
l_mod varchar2(10);
l_file utl_file.file_type;
l_len number;
l_exist boolean;
l_buffer varchar2(1024);
l_blocksize number;
l_cur_pos number := 0;
begin
l_dir := 'MARCUS_DUMP_DIR';
l_file_name := 'data01.csv';
l_mod := 'r';
utl_file.fgetattr(l_dir, l_file_name, l_exist, l_len, l_blocksize);
if (l_exist) then
l_file := utl_file.fopen(l_dir, l_file_name, l_mod);
while(l_cur_pos < l_len) loop
utl_file.get_line(l_file, l_buffer);
dbms_output.put_line(l_buffer);
l_cur_pos := utl_file.fgetpos(l_file);
end loop;
utl_file.fclose(l_file);
end if;
end;
/
--写文件
declare
l_dir varchar2(100);
l_file_name varchar2(100);
l_mod varchar2(10);
l_file utl_file.file_type;
l_buffer varchar2(1024);
begin
l_dir := 'MARCUS_DUMP_DIR';
l_file_name := 'data03.csv';
l_mod := 'w';
l_file := utl_file.fopen(l_dir, l_file_name, l_mod);
for col_info in (select table_name, column_name, data_type
from user_tab_columns
order by table_name, column_name, data_type) loop
l_buffer := col_info.table_name || ', ' || col_info.column_name || ', ' || col_info.data_type;
utl_file.put_line(l_file, l_buffer);
end loop;
-- utl_file.fflush(l_file);
utl_file.fclose(l_file);
end;
/
set serveroutput on;
declare
l_dir varchar2(100);
l_file_name varchar2(100);
l_mod varchar2(10);
l_file utl_file.file_type;
l_len number;
l_exist boolean;
l_buffer varchar2(1024);
l_blocksize number;
l_cur_pos number := 0;
begin
l_dir := 'MARCUS_DUMP_DIR';
l_file_name := 'data01.csv';
l_mod := 'r';
utl_file.fgetattr(l_dir, l_file_name, l_exist, l_len, l_blocksize);
if (l_exist) then
l_file := utl_file.fopen(l_dir, l_file_name, l_mod);
while(l_cur_pos < l_len) loop
utl_file.get_line(l_file, l_buffer);
dbms_output.put_line(l_buffer);
l_cur_pos := utl_file.fgetpos(l_file);
end loop;
utl_file.fclose(l_file);
end if;
end;
/
--写文件
declare
l_dir varchar2(100);
l_file_name varchar2(100);
l_mod varchar2(10);
l_file utl_file.file_type;
l_buffer varchar2(1024);
begin
l_dir := 'MARCUS_DUMP_DIR';
l_file_name := 'data03.csv';
l_mod := 'w';
l_file := utl_file.fopen(l_dir, l_file_name, l_mod);
for col_info in (select table_name, column_name, data_type
from user_tab_columns
order by table_name, column_name, data_type) loop
l_buffer := col_info.table_name || ', ' || col_info.column_name || ', ' || col_info.data_type;
utl_file.put_line(l_file, l_buffer);
end loop;
-- utl_file.fflush(l_file);
utl_file.fclose(l_file);
end;
/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7417681/viewspace-710206/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7417681/viewspace-710206/