Try to output some results into windows folder “c:\temp”. Compile and run my procedure without any issue, but I cannot find my output file “c:\temp\foo.log”. Here is my code:
CREATE OR REPLACE DIRECTORY tmp AS 'c:\temp\';
CREATE OR REPLACE PROCEDURE write_log
AS
CURSOR cur
IS
SELECT firstname,
lastname
FROM MEMBER
WHERE memberid BETWEEN 2 AND 5; -- only test 3 rows.
fname MEMBER.firstname%TYPE;
lname MEMBER.lastname%TYPE;
outputrecord VARCHAR2 ( 255 );
outputfile UTL_FILE.file_type;
BEGIN
OPEN cur;
FETCH cur
INTO fname,
lname;
outputfile := UTL_FILE.fopen ( UPPER ( 'tmp' ),
'foo.log',
'W',
32767
);
WHILE cur%FOUND
LOOP
outputrecord := fname || ',' || lname;
UTL_FILE.put ( outputfile, outputrecord );
UTL_FILE.new_line ( outputfile );
FETCH cur
INTO fname,
lname;
END LOOP;
CLOSE cur;
UTL_FILE.fclose ( outputfile );
END write_log;
/
BEGIN
write_log;
END;
/
Did I do something wrong here?
Thanks!
UTL_FILEmanipulates files on the database server, not on your client machine. You can only read and write files on the database server. Assuming that this code runs successfully, it would create a file on the database server namedc:\temp\foo.log.