Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Oracle: write a file to to a client PC

Oracle Database Tips by Donald BurlesonAugust 4, 2015

Question: What are the choices for writing data from my Oracle server to my client PC?  I want to write alert log entries to my PC from the server.
 
Answer: Most folks use Javascript (or another client-side applet) for writing files to a client, and some people use Oracle's Javascript API for writing PC files.
 
If you want to use PL/SQL to write to client files Franck Pachot has this utility for writing trace files to a client PC:
 
column trace_name new_value trace_name heading "Following file is spooled in the current directory:"
select
 (select lower(instance_name) from v$instance)||'_ora_'||spid
   ||(select decode(value,null,'','_'||value) from v$parameter where name='tracefile_identifier')
   || '.trc'
   trace_name
 from v$process join v$session on (v$process.addr=v$session.paddr) join v$mystat using (sid) where rownum=1
;
 
set serveroutput on feedback off verify off termout off linesize 1024 trimspool on
 
spool &trace_name
 
declare
 fd utl_file.file_type;
 line varchar2(1024);
 l_tracename VARCHAR2(512):='&trace_name';
 l_directory_path all_directories.directory_path%TYPE;
 l_directory_name all_directories.directory_name%TYPE;
 procedure t (msg in varchar2) is begin dbms_output.put_line(msg); end;
begin
 /* use old parameter _cached_open_cursors to close all open cursors */
 for r in (select 1 from v$session_cursor_cache where count>0) loop
 dbms_session.set_close_cached_open_cursors(true);
 rollback;
 commit;
 dbms_session.set_close_cached_open_cursors(false);
 end loop;
 /* get trace directory */
 select value into l_directory_path from v$parameter where name='user_dump_dest';
 /* get diretory name for it, or try to create it */
 begin
 select directory_name into l_directory_name from all_directories where directory_path = l_directory_path;
 exception
 when no_data_found then
   begin
    l_directory_name:='UDUMP';
    execute immediate 'create directory '||l_directory_name||' as '''||l_directory_path||'''';
   exception when others then
    raise_application_error(-20000,'You must CREATE DIRECTORY '||l_directory_name||' as ''' ||l_directory_path||'''; or be granted CREATE DIRECTORY.');
   end;
 end;
 /* opens the trace file */
 begin
 fd:=utl_file.fopen(l_directory_name,l_tracename,'R');
 exception when others then
    raise_application_error(-20001,'Impossible to open file: '||l_tracename||' in '||l_directory_name||' ( '||l_directory_path||' )');
 end;
 /* read the trace file and prints it */
 begin
 loop
   begin
    utl_file.get_line(fd,line);
    dbms_output.put_line(line);
   exception
    when no_data_found then exit;
    when others then
     dbms_output.put_line('!!! error while reading file '||l_tracename||' in '||l_directory_name||' ( '||l_directory_path||' )');
   end;
 end loop;
 /* close and remove the file from the server */
 utl_file.fclose(fd);
 utl_file.fremove(l_directory_name,l_tracename);
 exception
 when others then
   raise_application_error(-20002,'Impossible to remove: '||l_tracename||' in '||l_directory_name||' ( '||l_directory_path||' )');
 end;
end;
/
 
spool off
 
/* run tkprof */
host tkprof &trace_name &trace_name..txt
 
exit
 


 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.