Shell scripting+connect to oracle database+spooling


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell scripting+connect to oracle database+spooling
# 8  
Old 05-13-2009
Ahhh okay, I thought you weren't getting output to the spoolfile at all.

Well, you'll have to change your select statement and not use ' select * '. You'll have to name each field individually in the select statement and use the concatination mechanism to add commas after each field like so ...

Code:
spool outputfile.csv
select field1 || "," || field2 || "," || field3
from dba_tablespaces
where tablespace_name not in ("TEMP");
spool off
exit

# 9  
Old 05-13-2009
Thanx for your reply...

Do you mean sumthin like diz?

select st.description|| "," ||fr.businessname|| "," ||fr.comments|| "," || fr.customernumber|| "," || fr.progress|| "," || fr.reportdate|| ",
" || fd.description|| "," || ft.description|| "," || cd.contactperson|| "," || cd.fname|| "," ||cd.sname|| "," || cm.contactmethods|| "," ||c
ond.cellularnumber|| "," ||cond.email


I have tried it but its not working.
# 10  
Old 05-13-2009
> I have tried it but its not working.

Can you post the exact select statement like that, that is not working?
# 11  
Old 05-13-2009
Thnx for your quick responce...this is what I have

SET TERMOUT OFF
SPOOL /app/oracle/dummy.csv

SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET MARKUP HTML OFF

select st.description|| "," ||fr.businessname|| "," ||fr.comments|| "," || fr.customernumber|| "," || fr.progress|| "," || fr.reportdate|| "," || fd.description|| "," || ft.description|| "," || cd.contactperson|| "," || cd.fname|| "," ||cd.sname|| "," || cm.contactmethods|| "," ||cond.cellularnumber|| "," ||cond.email
from olf_faultreport fr,
olf_servicetype st,
olf_contactmethods cm,
olf_contactdetails cond,
olf_faultdesc fd,
olf_customerdetails cd,
olf_faulttype ft
where FR.FDID=FD.FDID
and FT.FTID=FD.FDID
and CD.CUSTOMERNUMBER=FR.CUSTOMERNUMBER
and cm.cmid=cd.CMID
and COND.CUSTOMERNUMBER=FR.CUSTOMERNUMBER
and FR.STID=ST.STID
order by ST.DESCRIPTION, reportdate desc;



exit
SPOOL OFF
# 12  
Old 05-13-2009
Syntax-wise the use of the ' || "," || ' is correct, and should not be the problem here.

However, that is one big select statement. w/o knowing the table structures and data, I couldn't begin to tell you what might be wrong with the statement, but if your not getting data, I can say that it's most likely because your select statement isn't behaving as you expect it to.

When I get a select statement like this, and it's not doing what I expect it to, I start to simply things. In your case, I'd narrow it down as follows:

Start by selecting only the fields from the ' fr ' and ' fd ' tables joined by the ' FDID ' column. If it doesn't work, you may have found the source of the problem, depending upon what if any errors get reported. If it does work, then add the next table ' ft ' and it's columns and join conditions to the statement, and keep doing this until your statement fails.

When it fails, if you get an error message that might help solve the problem. If no error message, than it's possible that the join condition for the table just added is wrong, or the data it contains is not what you expect. You'll have to play with it to figure it out.

That's the best I can do for you on this.
# 13  
Old 05-13-2009
thanx...I will play around with the select statement and let know.
# 14  
Old 05-18-2009
Hi! peolpe

I m stuck again.Can somebody help me out.I need right a script that attaches a csv file to a mail then e-mail it.

I have tried the mailx option but I m not gettin any mail on my mailbox
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Connect to database with shell output

Dear All, I am trying to write a script which will generate output to a file based on input files on basis of a pattern which I am able to do so. But, I am stuck as I am trying to connect this to database server. Below is my command and output details. Input Code filedate=$(date... (6 Replies)
Discussion started by: grvk101
6 Replies

2. Shell Programming and Scripting

Connect to Oracle database

could someone please help me in shell scripting. i want to connect to oracle database which is on remote sever. requirement: 1 want to check files in source directory if file exist then a execute a corresponding batch jobs on unix sever and fetch data from oracle database which is on remote... (2 Replies)
Discussion started by: refi123
2 Replies

3. UNIX and Linux Applications

Identify a specific environment Oracle variable to connect a remote Oracle database ?

Good evening I nned your help pls, In an unix server i want to connect to a remote oracle databse server by sqlplus. I tried to find out the user/passwd and service name by env variable and all Ive got is this: ORACLE_SID_REPCOL=SCL_REPCOL ORACLE_SID=xmeta ORACLE_SID_TOL=SCL_PROTOLCOL... (2 Replies)
Discussion started by: alexcol
2 Replies

4. Shell Programming and Scripting

Connect to Oracle database with JDBC drivers.

Hi All, We are having LINUX server. I would like to connect to oracle database from server to with the help of shell script and execute a procedure. We dont have oracle installed to use sqlplus and connect to database. Do we have any command to connect to database using JDBC drivers. ... (1 Reply)
Discussion started by: Girish19
1 Replies

5. Shell Programming and Scripting

How to connect to Oracle database using shell script?

Hi All, I am newbie to unix shell scripting. I want to connect to oracle database using shell script. I know how to connect DB using user name and password but my question is if my password is having '@' sign then how to connect. I have tried like below, cnt=`sqlplus -s /nolog << EOFSQL ... (3 Replies)
Discussion started by: pmotewar
3 Replies

6. Shell Programming and Scripting

Shell Script to connect to the oracle database

Hi Unix Gurus, I have a requirement to write a script, Oracle DB gets referesh every 6hrs, hence we need write a script to connect to the database , if it connects it should generate a file to proceed the next job application or when an error when connectiong to DB it should not generate any... (8 Replies)
Discussion started by: bshivali
8 Replies

7. Shell Programming and Scripting

Korn Script to connect and query oracle database

I've been sent the following script to finish. It's supposed to connect to an oracle database, query it, and send an email if the query result value is one or more. Currently it isn't connecting properly, just giving the following error: ERROR: ORA-01017: invalid username/password; logon denied... (2 Replies)
Discussion started by: jackmorgan2007
2 Replies

8. Shell Programming and Scripting

How to connect with oracle database using unix...

Hi all I am working in datawarehouse project and use DB2 database . shell scripting is written to connect with DB2 database in my application but i dont know how to connect with oracle databse or other databases.Is there any command in unix to connect any of these datbases? (6 Replies)
Discussion started by: vijays3
6 Replies

9. Shell Programming and Scripting

How to COnnect to Oracle database from UNIX Box

I am trying to connect to Oracle Databse from UNIX box using sqlplus command. But i get sqplus not found message. $ sqlplus sqlplus: not found I have searched in forums and all are suggesting to set environment varaibles...can somebody tell me what variables to set and how to set.and the... (12 Replies)
Discussion started by: angelarosh
12 Replies

10. Shell Programming and Scripting

Help in Shell scripting to modify the User Creation script in oracle database.

Hi, I have several users to create on my test Oracle database taking the scripts from the Production Oracle database. I have a separate text file where I have user-id and passwords maintained. I need help in writing a shell script to go thru the user creation scripts and replace VALUES... (1 Reply)
Discussion started by: rparavastu
1 Replies
Login or Register to Ask a Question