oracle utl_file

maojinyu發表於2011-01-26

create or replace directory gp
as 'c:gp';

grant read, write on directory gp to mao

declare
f utl_file.file_type;
begin
f := utl_file.fopen('GP', 'something.txt', 'w');
for i in 1..100 loop
utl_file.put_line(f, 'line one: some text');
utl_file.put_line(f, 'line two: more text');
end loop;
utl_file.fclose(f);
end;

declare
f utl_file.file_type;
buf VARCHAR2(200);
v_id varchar2(20);
BEGIN
f := utl_file.fopen('GP', 'test.txt', 'R');
LOOP
utl_file.get_line(f, buf);
v_id := substr(buf, 1, 5);
dbms_output.put_line(v_id);
END LOOP;
utl_file.fclose(f);
exception
when others then
null;
END;

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9907339/viewspace-1045203/,如需轉載,請註明出處,否則將追究法律責任。

相關文章