Home » SQL & PL/SQL » SQL & PL/SQL » Read/Write text files
Read/Write text files [message #300578] Sat, 16 February 2008 04:53 Go to next message
ix27
Messages: 4
Registered: February 2008
Junior Member
Gurus,
I'm a using oracle 8i enterprise and I need to write this program:
It should read a text file located on my desktop and and search for a specific string. If it finds it, it should open a new text file (on my desktop) and start writing to it.

I was reading about utl_file, but it didn't work for me. Can utl_file be used in oracle 8i?

I wrote a simple program to read first line but I got unhandled exception:
declare
f utl_file.file_type;
s varchar2(200);
begin
f := utl_file.fopen('SAMPLEDATA','sample1.txt','R');
utl_file.get_line(f,s);
utl_file.fclose(f);
dbms_output.put_line(s);
end;
/

Please advise how to implement this requirement...

Thanks in advance.
Re: Read/Write text files [message #300579 is a reply to message #300578] Sat, 16 February 2008 04:59 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
Quote:
I wrote a simple program to read first line but I got unhandled exception:

can you post the error what you got?

and do remember to format your code.read the first post with a yellow band.

regards,

[Updated on: Sat, 16 February 2008 05:01]

Report message to a moderator

Re: Read/Write text files [message #300581 is a reply to message #300579] Sat, 16 February 2008 05:05 Go to previous messageGo to next message
ix27
Messages: 4
Registered: February 2008
Junior Member
dhananjay,
This is the code & error:

SQL> declare
2 f utl_file.file_type;
3 s varchar2(200);
4 begin
5 f := utl_file.fopen('test','mytext','R');
6 utl_file.fclose(f);
7 dbms_output.put_line(s);
8 end;
9 /
declare
*
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "SYS.UTL_FILE", line 98
ORA-06512: at "SYS.UTL_FILE", line 157
ORA-06512: at line 5
Re: Read/Write text files [message #300585 is a reply to message #300581] Sat, 16 February 2008 05:21 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
Quote:
and do remember to format your code.read the first post with a yellow band.

i bet you didn't read the ORAFAQ FORUM GUIDE.

ok. have you taken the necessary steps before using UTL_FILE.if not, then go to the ORACLE doc or google for UTL_FILE.you will have to edit the init.ora file and include the path of your directory in the parameter UTL_FILE_DIR.



regards,
Re: Read/Write text files [message #300586 is a reply to message #300585] Sat, 16 February 2008 05:25 Go to previous messageGo to next message
ix27
Messages: 4
Registered: February 2008
Junior Member
It's either to edit init.ora or use create directory statement.
I used create directory statement to point to my directory.
Re: Read/Write text files [message #300588 is a reply to message #300586] Sat, 16 February 2008 05:32 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
i doubt creating directory was avaliable in oracle 8i.as far as i know it was available from 9i.you can check this link.

UTL_FILE

or

Another LINK




regards,

[Updated on: Sat, 16 February 2008 05:34]

Report message to a moderator

Re: Read/Write text files [message #300589 is a reply to message #300588] Sat, 16 February 2008 05:34 Go to previous messageGo to next message
ix27
Messages: 4
Registered: February 2008
Junior Member
I did create a directory called test and grant read access to it.
Re: Read/Write text files [message #300598 is a reply to message #300578] Sat, 16 February 2008 09:21 Go to previous message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
PL/SQL read SERVER file not CLIENT one.

Is UTL_FILE_DIR parameter set?
UTL_FILE does not use Oracle directory in 8i.

Regards
Michel
Previous Topic: Grant
Next Topic: why i cannot do it;PLS-00231" Function 'my_fun' cannot be used in this SQL"
Goto Forum:
  


Current Time: Sat Dec 10 13:03:45 CST 2016

Total time taken to generate the page: 0.04314 seconds