LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 09-15-2010, 12:54 AM   #1
saurabhmehan
Member
 
Registered: Jul 2010
Posts: 44

Rep: Reputation: 0
Question Want to learn/use SQLPLUS in shell script


Hi All,

How i will use sqlplus in shell script?
Can any one provide sample code which explain following:
1. Connect to oracle DB
2. Exceute select * from tablename
3. Release connection to the DB
4. Append output in file everytime when query executes.

Thanks in advance
 
Old 09-15-2010, 02:08 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You can use a HERE-DOCUMENT in a bash script:
Code:
#!/bin/bash

sqlplus -silent <<SQLScript
USER/PWD
set linesize 122
set pagesize  0
set heading off

spool /path/to/output.file

select * from tablename

spool off
exit 0
SQLScript
Also have a look at these links:
- http://www.dbsnaps.com/oracle/oracle...-bash-scripts/
- An Introduction to Linux Shell Scripting for DBAs

Hope this helps.
 
  


Reply

Tags
asap



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 using shell script arfal Programming 3 02-08-2010 08:52 PM
What are some good sites to learn shell script redlinuxxx Programming 7 10-02-2009 12:57 AM
execute oracle procedure from linux script and sqlplus Stilltray Linux - Newbie 3 11-14-2008 10:35 AM
LXer: Zero to Z-Shell: Learn what all the fuss is about with Z-Shell LXer Syndicated Linux News 0 10-11-2007 07:41 PM
sqlplus command from script Grassie Coetzee LinuxQuestions.org Member Intro 2 03-13-2005 12:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:51 AM.

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
Open Source Consulting | Domain Registration