Get SQL query result to file in putty

How to Get SQL query result to file in putty?

I have one SQL query and I want that query output to be redirected to the file.

 uname -a
SunOS XXX 5.8 Generic_117350-58 sun4u sparc SUNW,Sun-Fire-480R

Please suggest.

Through what database you run your SQL Query ?.

In mySQL:

SELECT * FROM TABLE INTO OUTFILE '/your_location/filename';

In postgresql:

\o /your_location/filename/
SELECT * FROM TABLE;
\o

try

sqlplus -s ${DB_LOGON} <<EOSQL
WHENEVER SQLERROR EXIT FAILURE;
WHENEVER OSERROR EXIT FAILURE;
spool output.file
select * from dual;
spool off
EOSQL

Thanks for the quick answers.

but how we can do it for isql ?

iirc, isql supports -o <output file> .

At the risk of being pedantic, but to clarify what may be some fuzzy thinking, putty is just a terminal program - one of several that do exactly the same thing. All it does is take keystrokes from your keyboard and send them to a remote system to be processed, then receive and display whatever character strings the remote system produces in response. It has nothing in particular to do with getting SQL query result into a file.

As others are pointing out, how to get the query result into a file is a function of whatever program is actually processing your query - the client program to whatever your rdbms system is.

Also, be aware that however that file is created (like oracle's sqlplus SPOOL command) it will be created on that remote system. If you need to get the file from the remote system to your desktop where you are running putty, that is a different question.

Please clarify your exact requirement.

1 Like

Yes agreed, But many times we don't have many options.
I have only putty to access this DB and I want to validate there itself. You should understand that there are many things which are not in our hand in actual world.(basically in any bank)
Then we have to try within our boundaries itself. Don't have any options :confused:.
I have tried all the inputs given in this post but nothing is working for me.
Please suggest how I can achieve this.

Thanks,
Pamu

I wasn't suggesting you do anything any differently, anything that would be outside of your control. Your subject and question simply suggested that you don't have a clear understanding of the relationship of putty to your actual problem, and I was trying to clarify that for you. Perhaps I was reading too much between the lines, but I see a LOT of people who don't have a clear understanding of what processes are happening on their own workstation vs. what is actually happening on a server they are connected to.

I can't suggest "how to achive this" because I don't know where you want this file to end up and what you want to do with it when you get it.

The phrase "nothing is working for me" contains no useful, actionable information. What rdbms product are you issuing the sql statement to? What command line utility are you using to connect to that database and issue the SQL statement? What output ARE you getting? Error messages? A file with something other than what you expect? A file located somewhere other than where you expect?