create a new file [message #36984] |
Wed, 09 January 2002 00:00 |
fionan
Messages: 5 Registered: January 2002
|
Junior Member |
|
|
hi
i was wondering does anyone know of a procedure in pl/sql that will create a new file of any type i specify on say for example my harddrive.i have seen code were you can open a file but i want to create one
any ideas or suggestions appreciated
fk
|
|
|
Re: create a new file [message #36986 is a reply to message #36984] |
Wed, 09 January 2002 01:18 |
tinel
Messages: 42 Registered: November 2001
|
Member |
|
|
Hi
Here is a exemple of how you can write in a file. If you try to open a file in W mode and the file does not exist, then it's create by the pl/sql.
To use this code you have to set the utl_file_dir parameter in your init<sid>.ora file.
DECLARE
f_id1 utl_file.file_type;
arg1 VARCHAR2(20);
arg2 VARCHAR2(20);
arg3 VARCHAR2(20);
BEGIN
arg1 := 'test';
arg2 := 'testing';
arg3 := 'and testing';
f_id1 := utl_file.fopen('C:Test','test.doc','w');
IF (utl_file.is_open(f_id1)) THEN
dbms_output.put_line('working!');
ELSE
dbms_output.put_line('not working!');
END IF;
utl_file.put_line(f_id1, arg1);
utl_file.put_line(f_id1, arg2);
utl_file.put_line(f_id1, arg3);
utl_file.fclose(f_id1);
EXCEPTION
WHEN utl_file.invalid_path THEN
dbms_output.put_line('Wrong way!');
WHEN utl_file.INVALID_MODE THEN
dbms_output.put_line('Invalid mode!');
WHEN utl_file.INVALID_operation THEN
dbms_output.put_line('Invalid operation!');
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('No data found!');
WHEN utl_file.invalid_filehandle THEN
dbms_output.put_line('Wrong file');
WHEN utl_file.write_error THEN
dbms_output.put_line('Write error!');
WHEN utl_file.read_error THEN
dbms_output.put_line('Read erro!');
WHEN utl_file.internal_error THEN
dbms_output.put_line('Pl/sql error!');
END;
Hope this will help you.
|
|
|
|