-   Linux - Newbie (
-   -   sqlplus linux (

akmenon 04-14-2013 08:28 AM

sqlplus linux
hi gurus

i have a query which i want to run in linux with a formatted option. The output also i want to store as txt file.

mariostg 04-14-2013 09:41 AM

Most database have a command line front end (CLI) that allows you to execute a query and display the output in some format that you can redirect to a file. What database are you using? Per example Postgresql has a program called psql.

akmenon 04-14-2013 09:50 AM

I am using oracle 11g and using plsql no problems on that.
I know about the format oprtions in the plsql etc.
I want to save the result of a sql i run in the .txt without the query.
I want to know how to save the query in a file on linux.
Then run that query whenever i want.

mariostg 04-14-2013 09:53 AM

Assuming you can run your command that normally display the information on the screen, redirect it to a file with > operator.

YourCommand > query.txt will save in query.txt in the current directory

btmiller 04-14-2013 03:43 PM

It's been agen since I've used sqlplus, but IIRC, you can put your query in a text file (call it foobar.sql) and then run:

sqlplus < foobar.sql > myoutput.txt
The results of the query will be in myoutput.txt.

chrism01 04-14-2013 06:38 PM

You can also use the spool cmd from within SQLPLUS to store the results.

Similarly for PL/SQL

akmenon 04-15-2013 03:08 AM

thanks to all
I could save the file.
all i had to do was in sqlplus def_editor=vi
and then type the sql in that and use the vi commands for saving.
then run the sql at sqlplus using the @filname.sql.
now i think i can redirect the result of this query using >

kooru 04-15-2013 03:52 AM

Using sqlplus, the more correct mode for output is use SPOOL command


rem ******************************************************************
rem ****                                                          ****
rem ****                ORACLE SQL SCRIPT                          ****             
rem ****                                                          ****
rem ******************************************************************

set time on
set timing on
set echo on
set head off

spool myoutput.log

  ID  NUMBER          NOT NULL,
  ID2  NUMBER          NOT NULL,

spool off;

chrism01 04-15-2013 08:44 AM

I think I mentioned that :)

All times are GMT -5. The time now is 05:34 PM.