LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-14-2013, 08:28 AM   #1
akmenon
LQ Newbie
 
Registered: Apr 2013
Posts: 5

Rep: Reputation: Disabled
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.
 
Old 04-14-2013, 09:41 AM   #2
mariostg
Member
 
Registered: Apr 2011
Location: Gatineau, Quebec
Distribution: OpenBSD
Posts: 80

Rep: Reputation: 5
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.
 
Old 04-14-2013, 09:50 AM   #3
akmenon
LQ Newbie
 
Registered: Apr 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-14-2013, 09:53 AM   #4
mariostg
Member
 
Registered: Apr 2011
Location: Gatineau, Quebec
Distribution: OpenBSD
Posts: 80

Rep: Reputation: 5
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
 
Old 04-14-2013, 03:43 PM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,275

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
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.
 
Old 04-14-2013, 06:38 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
You can also use the spool cmd from within SQLPLUS to store the results.
http://stackoverflow.com/questions/8...rpt-spool-file

Similarly for PL/SQL http://www.dbforums.com/oracle/80566...put-files.html
 
Old 04-15-2013, 03:08 AM   #7
akmenon
LQ Newbie
 
Registered: Apr 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thumbs up

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 >
 
Old 04-15-2013, 03:52 AM   #8
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 273Reputation: 273Reputation: 273
Using sqlplus, the more correct mode for output is use SPOOL command

Code:
rem ******************************************************************
rem ****                                                          ****
rem ****                 ORACLE SQL SCRIPT			  ****               
rem ****                                                          ****
rem ******************************************************************

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

spool myoutput.log

CREATE TABLE BLABLA
(
  ID   NUMBER          NOT NULL,
  ID2  NUMBER          NOT NULL,
);

spool off;
 
Old 04-15-2013, 08:44 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
I think I mentioned that
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sqlplus osaka Linux - Newbie 2 11-28-2011 09:23 AM
A question about using SQLPLUS thomas2004ch Linux - Software 2 07-15-2010 05:38 AM
execute oracle procedure from linux script and sqlplus Stilltray Linux - Newbie 3 11-14-2008 11:35 AM
Error with Oracle10g on Linux FC6 in SQLPlus... Joncamp Linux - Software 1 01-16-2007 04:14 AM
Sqlplus mikeshn Programming 1 07-16-2002 11:13 PM


All times are GMT -5. The time now is 03:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration