LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 01: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, 03:08 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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


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 using shell script arfal Programming 3 02-08-2010 09:52 PM
What are some good sites to learn shell script redlinuxxx Programming 7 10-02-2009 01:57 AM
execute oracle procedure from linux script and sqlplus Stilltray Linux - Newbie 3 11-14-2008 11: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 08:41 PM
sqlplus command from script Grassie Coetzee LinuxQuestions.org Member Intro 2 03-13-2005 01:01 PM


All times are GMT -5. The time now is 10:30 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