Home » SQL & PL/SQL » SQL & PL/SQL » to sql query output into text file (windows xp)
to sql query output into text file [message #498325] Wed, 09 March 2011 11:16 Go to next message
swapnabpnn
Messages: 96
Registered: December 2010
Member

Hi ALL,
I am trying to get query output into textfile.The following procedure is working fine by creating directory as follows in sys user.The output is getting onto text file and it seen on server machine even.My question is I want to see the text file on local machine also instead of everytime connecting to server machine drive.How can I perform that?

create or replace directory INFO_DIR as 'D:\Swapna';
grant read, write on directory INFO_DIR to fairpoint;


CREATE OR REPLACE PROCEDURE FAIRPOINT.utl_file_test_write_xls(filename in VARCHAR2 )
IS
output_file		utl_file.file_type;
v_path			VARCHAR2(500);
v_string		VARCHAR2(4000);
v_sqlstr		VARCHAR2(2000);
BEGIN
	BEGIN

 output_file := UTL_FILE.FOPEN(location  => 'INFO_DIR',
			       filename     => filename,
			       open_mode    => 'w',
			       max_linesize => 32767);
						utl_file.put_line (output_file, 'XLS_NAMES');
	FOR i IN (SELECT COPPER_CABLE_ID from COPPER_CABLE)	LOOP
		v_string := i.COPPER_CABLE_ID;
		utl_file.put_line (output_file, v_string);
	END LOOP ;
UTL_FILE.FCLOSE_ALL;
UTL_FILE.FCLOSE_ALL;
END utl_file_test_write_xls;
/

exec utl_file_test_write_xls('SP.txt');


Thanks........
Re: to sql query output into text file [message #498327 is a reply to message #498325] Wed, 09 March 2011 11:22 Go to previous messageGo to next message
Michel Cadot
Messages: 68774
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
spool myfile
select ....
spool off

Regards
Michel
Re: to sql query output into text file [message #498436 is a reply to message #498327] Thu, 10 March 2011 00:20 Go to previous messageGo to next message
swapnabpnn
Messages: 96
Registered: December 2010
Member
Hi,
Everytime client need to use spool stmt for every query.Since they dont know about sql stmts,they just need script where if they run directly output need to be populated in the local machine instead of server.

So is it like spool is the only option or rather any other option can be implemented in the script which i posted before.


Thanks..
Re: to sql query output into text file [message #498438 is a reply to message #498436] Thu, 10 March 2011 00:27 Go to previous messageGo to next message
xpact83
Messages: 225
Registered: October 2008
Location: philippines
Senior Member
if you use directories created in oracle the output will be on the server.

just put these codes in you script just like michel said.

spool thefilename
your select
spool off

Re: to sql query output into text file [message #498488 is a reply to message #498438] Thu, 10 March 2011 02:54 Go to previous messageGo to next message
sethumurugan
Messages: 61
Registered: June 2010
Location: Chennai
Member
Hi swapna,

Hope you mean that the user should be able to take a print in a click without knowing anything about what is happening at the back. If that is the case please follow the following steps.

Create a sql file as follows [ print_test.sql ] in a folder

spool test.txt
select * from employee;
spool off
exit


Then create a batch file as follows [ print_test.bat ]

sqlplus -s ears/ears@td1 @print_test.sql 
print test.txt
exit


Now create a shortcut for the batch file in your OS. So when the user clicks the short cut, automatically the sql output will be sent to the default printer. If you like to have formats, you can achive the same thru sql statement.

Hope this helps to what you want. Pls buzz us if you have any clarification.


Sethu Murugan
Re: to sql query output into text file [message #499079 is a reply to message #498488] Sun, 13 March 2011 07:41 Go to previous message
sethumurugan
Messages: 61
Registered: June 2010
Location: Chennai
Member
Hi Swapna,

Did u tried the above thing? you able to solve your problem ?

Sethu
Previous Topic: DBMS_SCHEDULER
Next Topic: public synonym
Goto Forum:
  


Current Time: Sat Jan 17 04:57:44 CST 2026