Skip to Main Content
  • Questions
  • In APEX, I am trying to write an output text file.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Wayne.

Asked: March 01, 2017 - 2:32 pm UTC

Last updated: March 02, 2017 - 6:04 am UTC

Version: 11g

Viewed 1000+ times

You Asked

In APEX, I am trying to write an output text file. I keep getting ORA-29280 Invalid directory path even though I specify paths where I do have write access. *Maybe* I need to have a file browse to find the output directory. Is there a file browse that will specify output directory?
Thanks!!
My code:
Declare
v_input_record varchar2(600);
p_dir varchar2(200);
p_file varchar2(50);
l_output utl_file.file_type;
l_amt number default 32000;

cursor cur_go_thru_AD_INPUT
is select COUNTY_INPUT_RECORD
from ad_county_input_file
order by county_input_file_id_seq;

begin
p_dir := 'U:\PRG_DEVL\Adr\Work\';

p_file := 'SoS-Output.asc';
l_output := utl_file.fopen(p_dir, p_file, 'w', 32767);

open cur_go_thru_AD_INPUT;
LOOP
FETCH cur_go_thru_AD_INPUT
INTO v_input_record;
EXIT WHEN cur_go_thru_AD_INPUT%NOTFOUND;

utl_file.put(l_output, v_input_record );
utl_file.fflush(l_output);

END LOOP;

utl_file.new_line(l_output);
utl_file.fclose(l_output);

end;

and Connor said...

You dont use a full directory path for UTL_FILE, you should use a directory object.

For example

SQL> create directory TEMP as '/tmp';

Directory created.

SQL> grant read, write on directory TEMP to ...

Grant succeeded.



and then use the object name in your UTL_FILE calls.

p_dir := 'TEMP';

Hope this helps.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Thanks for the answer

Wayne McKinstry, March 02, 2017 - 2:00 pm UTC

I was hoping to create a file on the client machine. Not possible with this approach.

Actually I found that I could make an interactive report, and let the user download that onto their PC.

Thanks.