SQL> select * from aa;NAME
--------
20040501
10002000create or replace procedure wfile
as
type my_cursor is ref cursor;
mycursor my_cursor;
myrecord aa%rowtype;
fileout utl_file.file_type;
begin
fileout := utl_file.fopen('e:\','aa.csv','w');
open mycursor for select * from aa;
loop
fetch mycursor into myrecord;
exit when mycursor%notfound;
utl_file.put_line(fileout,myrecord.name);
end loop;
close mycursor;
utl_file.fclose(fileout);
end;
/过程已创建SQL> exec wfilePL/SQL 过程已成功完成。E:\>more aa.csv
20040501
10002000E:\>
--------
20040501
10002000create or replace procedure wfile
as
type my_cursor is ref cursor;
mycursor my_cursor;
myrecord aa%rowtype;
fileout utl_file.file_type;
begin
fileout := utl_file.fopen('e:\','aa.csv','w');
open mycursor for select * from aa;
loop
fetch mycursor into myrecord;
exit when mycursor%notfound;
utl_file.put_line(fileout,myrecord.name);
end loop;
close mycursor;
utl_file.fclose(fileout);
end;
/过程已创建SQL> exec wfilePL/SQL 过程已成功完成。E:\>more aa.csv
20040501
10002000E:\>
/**************************************************************************
parameter:textContext in varchar2 日志内容
desc: ·写日志,把内容记到服务器指定目录下
·必须配置Utl_file_dir初始化参数,并保证日志路径与Utl_file_dir路径一致或者是其中一个
****************************************************************************/
CREATE OR REPLACE PROCEDURE sp_Write_log(text_context VARCHAR2)
IS
file_handle utl_file.file_type;
Write_content VARCHAR2(1024);
Write_file_name VARCHAR2(50);
BEGIN
--open file
write_file_name := 'db_alert.log';
file_handle := utl_file.fopen('/u01/logs',write_file_name,'a');
write_content := to_char(SYSDATE,'yyyy-mm-dd hh24:mi:ss')||'||'||text_context;
--write file
IF utl_file.is_open(file_handle) THEN
utl_file.put_line(file_handle,write_content);
END IF;
--close file
utl_file.fclose(file_handle);
EXCEPTION
WHEN OTHERS THEN
BEGIN
IF utl_file.is_open(file_handle) THEN
utl_file.fclose(file_handle);
END IF;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END sp_Write_log;
没有这个文件是没有关系的
FOPEN有3种打开模式
'w' 如果没有文件,新建,如果有,覆盖
'a' 如果没有文件,新建,如果有,添加数据
'r' 如果没有文件,不能读,如果有,读文件
fileout utl_file.file_type;
BEGIN
fileout := utl_file.fopen(KEY_FOLDER_PATH,'kaikei.csv','W');
KEY_FOLDER_PATH 是传进来的参数
可以这样写吗?我这样做了,但是还是一到这句后就跳到异常部分
EXCEPTION
WHEN others THEN
………………我在测试的时候,给KEY_FOLDER_PATH 赋值是‘c:\'
UTL_FILE_DIR:=………………
这个参数??