The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Integrating the Oracle Designer Legacy Table API with Oracle JDeveloper 11g ADF Busin iBot Oracle Updates (RSS) 0 04-06-2008 02:10 AM
First Script: Query every table with column xxx. Iniquity Shell Programming and Scripting 1 02-06-2007 01:15 PM
using the getline to populate an array from a file penfold Shell Programming and Scripting 8 03-02-2005 08:42 AM
How to load comma seperated values file (*.csv) into Oracle table handynas UNIX for Advanced & Expert Users 4 06-24-2002 09:35 AM
How to load comma seperated values file (*.csv) into Oracle table handynas UNIX for Dummies Questions & Answers 5 06-04-2002 08:10 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-16-2006
Registered User
 

Join Date: Aug 2006
Posts: 18
shellscript.query Oracle table..populate in a text file

Hi Guys,
I'm new to this forum as well as to UNIX shell scripting.
I'm looking for a shellscript to query an Oracle database table and populate the result set of the query in a text file.
Could you someone help me out with a sample code?

Thanks,
Bhagat
Reply With Quote
Forum Sponsor
  #2  
Old 08-16-2006
Registered User
 

Join Date: Jun 2006
Posts: 15
Talking orcle query ans

Hi Bhagat,
U can use the following query to make connection to a oracle database and spool the reults
to a text file:--

sqlplus -s username@databse_string/password << EOF
whenever sqlerror exit sql.sqlcode;
whenever oserror exit FAILURE

set define off
set head off
set feedback off
set echo off
set pagesize 0
set pages 0
set linesize 200
set timing off

spool appropriate path/dummy.txt
UR QUERY GOES HERE
spool off

EOF

If u want to make only manipulations to databse without spooling the results to a any fimle,
dont put it with in SPOOL command.

Hope it works for u......
Reply With Quote
  #3  
Old 08-17-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 255
here is the script to query and put output in a file

Code:
X=`sqlplus -s user/pwd@host<<eof
set serveroutput on;
set feedback off;
set linesize 1000;
select * from table where rownum<5;
EXIT;
eof`

echo $X>testing.dat
and check this url where the same question was answered.this
Reply With Quote
  #4  
Old 08-17-2006
Registered User
 

Join Date: Aug 2006
Posts: 18
Thanks both of you!!!
That was very helpful!!
Appreciate your guidance

Regards,
Bhagat
Reply With Quote
  #5  
Old 09-04-2006
Registered User
 

Join Date: Aug 2006
Posts: 18
shellscript.query Oracle table..populate in a text file

Hi Guys,
I'm looking for a slightly modified script this time...
ie.Query Oracle database table and populate the result set of the query in a text file.The column values should be seperat
I also want the count of records returned by the Oracle query.
Could you someone help me out with a sample code?

Thanks,
Bhagat
Reply With Quote
  #6  
Old 09-04-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 255
Hi Bhagat
There is small change and i guess will be pretty simple.Give path and filename in spool command where it will store the output.In select statement give column names you want to be in the output and here '|' is used as a delimiter you can use any char you want to.
Code:
sqlplus -s user/pwd@host<<eof
set heading off;
set linesize 1000;
spool /dirpath/filename;
select col1||'|'||col2||'|'||col3.......... from table where condition;
spool off;
EXIT;
eof
and counting for no of rows you can chack with a command to spooled file
x=`wc -l /path/filename | awk '{print $1}'`
echo "no of records \c $x"
Reply With Quote
  #7  
Old 09-04-2006
Registered User
 

Join Date: Sep 2005
Location: india
Posts: 78
sqlplus -s user/pwd@host<<eof>urfile
set serveroutput on feedback off linesize 1000 pagesize 0;
select * from table where rownum<5;
EXIT;
eof
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0