![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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...... |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
Thanks both of you!!!
That was very helpful!! Appreciate your guidance Regards, Bhagat |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
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 x=`wc -l /path/filename | awk '{print $1}'` echo "no of records \c $x" |
|
#7
|
|||
|
|||
|
sqlplus -s user/pwd@host<<eof>urfile
set serveroutput on feedback off linesize 1000 pagesize 0; select * from table where rownum<5; EXIT; eof |
|||
| Google The UNIX and Linux Forums |