首页 > 数据库 > Oracle > oracle utl_file
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;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9907339/viewspace-1045203/ ,如需转载,请注明出处,否则将追究法律责任。