I have a procedure to write a report in Xls file using utl_file
.
This procedure works correctly but my question is: is it possible to open this file directly in Excel after executed? I ask it because, when it's executing now, I must open the folder path then open Xls file.
My Edit Code:
create or replace procedure write_file_daily(emp_id in number,Start_date in date,End_date in date, Job_Name in varchar2 ) is
file_handle UTL_FILE.file_type;
begin
file_handle := utl_file.fopen('CSV_DIR', 'REP.xls', 'W');
utl_file.put_line(file_handle, 'id'|| CHR(9) || 'name' || CHR(9) || 'department' || CHR(9) || 'unit' || CHR(9) || 'position' || CHR(9) || 'job'
);
for rws in (
select ID,
NAME,
DEPARTMENT,
UNIT,
POSITION,
JOB
from (select t.ID1 as ID,
t.NAME as Name,
(select d.divname from compdivs d where d.divid = t.COMP_id2) as DEPARTMENT,
decode((select d.parent1name from compdivs d where d.divid = t.COMP),
'XXX',
(select d.divname from compdivs d where d.divid = t.COMP),
(select d.parent1name from compdivs d where d.divid = t.COMP)) as UNIT,
(select d.dname from const_dt d where d.mid = 3 and d.no = t.WORKK) as Position,
(select d.dname from const_dt d where d.mid = 8 and d.no = t.EDUCATION_ID) as Job,
from th1 t
)
WHERE ( ID = emp_id or emp_id = -1)
and (Day_date between Start_date and End_date )
and( NVL(lower(JOB),' ') like NVL(lower('%'|| Job_Name ||'%'),NVL(lower(JOB),' ')))
)
loop
utl_file.put_line(file_handle, rws.id || CHR(9) || rws.name || CHR(9) || rws.department || CHR(9) || rws.unit || CHR(9) || rws.position || CHR(9) || rws.job
);
end loop;
utl_file.fclose(file_handle);
end write_file_daily;