在PL/SQL中導出大量CSV文件可以通過以下步驟來實現:
CREATE OR REPLACE PROCEDURE export_to_csv (file_path IN VARCHAR2) IS
file_handle UTL_FILE.FILE_TYPE;
cursor_data SYS_REFCURSOR;
record_table YOUR_TABLE%ROWTYPE;
BEGIN
file_handle := UTL_FILE.FOPEN('YOUR_DIRECTORY', file_path, 'W');
OPEN cursor_data FOR
SELECT * FROM YOUR_TABLE;
LOOP
FETCH cursor_data INTO record_table;
EXIT WHEN cursor_data%NOTFOUND;
UTL_FILE.PUT_LINE(file_handle, record_table.column1 || ',' || record_table.column2 || ',' || ...);
END LOOP;
UTL_FILE.FCLOSE(file_handle);
CLOSE cursor_data;
END;
/
BEGIN
export_to_csv('file1.csv');
export_to_csv('file2.csv');
-- 繼續導出其他文件
END;
/
通過以上步驟,您可以在PL/SQL中導出大量CSV文件。請確保在存儲過程中指定正確的表名、目錄和字段,以及適當的文件路徑和文件名。