create or replace directory UTL_FILE_DIR as '/home/websms/utl_file'; --该目录所属组必须为:oracle:dba
grant read, write on directory exp_dir to eygle; --赋予读写的权限
CREATE OR REPLACE PROCEDURE emp2file
IS
fileID utl_file.file_type;
BEGIN
fileID := utl_file.fopen('UTL_FILE_DIR', 'example.txt', 'a'); --w 写模式,r 只读 a 表示追加
for corp in ( select * from corpinfo)
loop
utl_file.put_line(fileID , corp.corpid ||','||corp.corpname);
end loop;
utl_file.fclose(fileID);
if utl_file.is_open(fileID) then
UTL_FILE.FCLOSE (fileID);
end if;
END;
grant read, write on directory exp_dir to eygle; --赋予读写的权限
CREATE OR REPLACE PROCEDURE emp2file
IS
fileID utl_file.file_type;
BEGIN
fileID := utl_file.fopen('UTL_FILE_DIR', 'example.txt', 'a'); --w 写模式,r 只读 a 表示追加
for corp in ( select * from corpinfo)
loop
utl_file.put_line(fileID , corp.corpid ||','||corp.corpname);
end loop;
utl_file.fclose(fileID);
if utl_file.is_open(fileID) then
UTL_FILE.FCLOSE (fileID);
end if;
END;