Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

overwrite filename on UTL_FILE

598866Jul 28 2008 — edited Jul 28 2008
I have a procedure that gets the ID from emp, use the ID and last name as the filename, and extracts all the record for each emp and dump to file.

here how it looks like:
CURSOR c1 IS
SELECT distinct emp_id FROM EMP; --gets the distinct id

CURSOR c2 IS
SELECT * FROM EMP WHERE EMP_ID = v_emp_id; --gets the record for each emp


FOR r1 IN c1 LOOP
l_id := r1._id;
l_filename := r1.id||'_'||r1.last_name||'.csv';
l_fileID := UTL_FILE.FOPEN ('DIRECTORY', l_filename, 'W');

FOR r2 IN c2 LOOP
l_file_line := /**** data section***/

UTL_FILE.PUT_LINE (l_fileid, l_file_line);
END LOOP;
UTL_FILE.FCLOSE (l_fileID);
--CALLS ANOTHER PROCEDURE
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
END LOOP;


Since I have more than 1K distinct record, tihs procedure also creates 1K file, I just want to overwrite l_filename, so I am just maintaing 1 file.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2008
Added on Jul 28 2008
7 comments
1,612 views