oracle UTL_FILE包如何实现追加文件内容
L_OUTPUT := UTL_FILE.FOPEN(V_P_DIR, P_FILENAME, 'W', P_MAX_LINESIZE);
EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD HH24:MI:SS''';
--打开游标往文件里写入数据
DBMS_SQL.PARSE(L_THECURSOR, P_QUERY || CHR(10), DBMS_SQL.NATIVE);
DBMS_SQL.DESCRIBE_COLUMNS(L_THECURSOR, L_COLCNT, L_DESCTBL);
FOR I IN 1 .. L_COLCNT LOOP
DBMS_SQL.DEFINE_COLUMN(L_THECURSOR, I, L_COLUMNVALUE, 4000);
L_SEPARATOR := P_SEPARATOR;
END LOOP;
L_STATUS := DBMS_SQL.EXECUTE(L_THECURSOR);
WHILE (DBMS_SQL.FETCH_ROWS(L_THECURSOR) > 0) LOOP
L_SEPARATOR := '';
FOR I IN 1 .. L_COLCNT LOOP
DBMS_SQL.COLUMN_VALUE(L_THECURSOR, I, L_COLUMNVALUE);
UTL_FILE.PUT(L_OUTPUT,
L_SEPARATOR || REPLACE(L_COLUMNVALUE, '"', '""'));
L_SEPARATOR := P_SEPARATOR;
END LOOP;
UTL_FILE.PUT(L_OUTPUT,chr(13));
UTL_FILE.NEW_LINE(L_OUTPUT);
END LOOP;
每次把上次写入的内容覆盖了,如何实现追加内容?
------解决方案--------------------以追加的方式打开:
UTL_FILE.FOPEN(V_P_DIR, P_FILENAME, 'W', P_MAX_LINESIZE);改为:
UTL_FILE.FOPEN(V_P_DIR, P_FILENAME, 'A', P_MAX_LINESIZE)