Tuesday, October 14, 2008

Oracle: I/O operations Using UTL_FILE

I/O operations in Oracle Using UTL_FILE
This is easy writing to the alert log is accomplished by using Oracle’s UTL_FILE package. The UTL_FILE package allows Oracle SQL and PL/SQL to read and write directly from flat files on the server.


CREATE DIRECTORY TARGETDIR AS 'DIRECTORY PATH' --- Path should be accessible from Oracle Server.
/

SET serveroutput on

DECLARE
ex BOOLEAN;
flen NUMBER;
bsize NUMBER;
BEGIN
utl_file.fgetattr('TARGETDIR', 'test.txt', ex, flen, bsize);

IF ex THEN
dbms_output.put_line('File Exists');
ELSE
dbms_output.put_line('File Does Not Exist');
END IF;
dbms_output.put_line('File Length: ' || TO_CHAR(flen));
dbms_output.put_line('Block Size: ' || TO_CHAR(bsize));
END fgetattr;
/



For more information regarding UTL_FILE, Click
Here and Here

No comments: