HELP. Oracle Call from ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HELP. Oracle Call from ksh script
# 1  
Old 03-11-2010
HELP. Oracle Call from ksh script

I have searched the forums and couldn't find my specific issue so I figure that I would post on it.

I am trying to run a simple sql script that spools to a flat file from a unix script.

I have tried to make the call outright from inside of the ksh script as such:

Code:
sqlplus username/pass@SID @script.sql

everytime I do I get the TNS invalid error.

So I went this route from within the script

Code:
sqlplus username/pass@sid

and I an now able to connect:

Here is my code

Code:
rm /tmp/blah.txt



sqlplus  user/pass@SID

spool /tmp/blah.txt
SELECT
  ta.foo
  ,cn.bar
  , count(*) cnt
FROM
  foo_bar ta
  , bar_foo cn
  WHERE
    ta.blah <= sysdate
    and ta.bleep=09
    and ta.foo=cn.foo
Group BY cn.bar,ta.bar
ORDER BY cnt DESC
spool off;

cat /tmp/blah.txt | mailx -s "HERE YOU GO" whoever@wherever.com
chmod 666 /tmp/blah.txt

Please help me.

Last edited by pludi; 03-12-2010 at 02:06 AM.. Reason: code tags, please...
# 2  
Old 03-11-2010
You'll maybe need to adjust for the value of your SID, unless it's got WOODY and BUZZ as counterparts elsewhere on the system. Smilie

Otherwise, you'd want to post your actual script. The one provided is not likely to work, since the shell doesn't interact with sqlplus quite this way. It'd take the form of either one of the following:

Code:
sqlplus user/pass@SID <<EO_SQL
spool /tmp/blah.txt
SELECT
ta.foo
,cn.bar
, count(*) cnt
FROM
foo_bar ta
, bar_foo cn
WHERE
ta.blah <= sysdate
and ta.bleep=09
and ta.foo=cn.foo
Group BY cn.bar,ta.bar
ORDER BY cnt DESC
;
spool off
-- note the moving of the ";" or GO string...
EO_SQL

Code:
sqlplus user/pass@SID @sql_file.sql 
# where sql_file.sql contains the SQL commands, including an exit after spool off...

...also, note that the ";" has to precede the "spool off" because ";" execs the SQL...whereas spool just serves to close the output file...
# 3  
Old 03-12-2010
Adding the EO_SQL and moving the ; worked perfectly.



Thanks a million (pushing it, is there a way to hide the actual query from the output?)
# 4  
Old 03-12-2010
set commands are your friend... They precede the actual SELECT statement. For example:

Code:
   set      colsep                              "|" 
   set      feedback                            off 
   set      heading                             on  
   set      pages                               0   
   set      lines                               200 
   set      underline                           off 
   set      verify                              off 
   set      termout                             off 
   set      trimspool                           on

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to call a power shell script from ksh or sh?

Hi, I have some .json scripts and azure commands in powershell script and I need to execute this powershell script from unix console by writing a shell script. But these powershell script is under my local for ex. C:\ drive. Would it be possible to achieve this? And do we need to install... (1 Reply)
Discussion started by: Samah
1 Replies

2. Shell Programming and Scripting

How to call Oracle function with multiple arguments from shell script?

Dear All, I want to know how can i call oracle function from shell script code . My oracle function have around 5 input parameters and one return value. for name in *.csv; do echo "connecting to DB and start processing '$name' file at " echo "csv file name=$x" sqlplus -s scoot/tiger <!... (2 Replies)
Discussion started by: Balraj
2 Replies

3. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies

4. Red Hat

How to call Oracle package through shell script?

Hey i have a package in oracle to validate file mask. can i call it in through shell script . if yes , how Thanks (1 Reply)
Discussion started by: ramsavi
1 Replies

5. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

6. Shell Programming and Scripting

How to call an sql script inside a while statement in KSH

Hi all, I'm trying to run an sql inside a loop which looks like this #!bin/ksh while IFS=, read var1 var2 do sqlplus -s ${USERNAME}/${PASSWORD}@${ORACLE_SID} << EOF insert into ${TABLE} ( appt_date ) values ( '${var1 }' ); ... (6 Replies)
Discussion started by: ryukishin_17
6 Replies

7. Shell Programming and Scripting

Call and redirect output of Oracle stored procedure from unix script

Hi, Can you assist me in how to redirect the output of oracle stored procedure from unix script? Something similar to what i did for sybase isql -U$MYDBLOG -D$MYDBNAME -S$MYDBSVR -P$MYDBPWD -o$MYFILE<< %% proc_my_test 8 go %% Thanks in advance - jak (0 Replies)
Discussion started by: jakSun8
0 Replies

8. Shell Programming and Scripting

Shell Script for call a procedure in Oracle DB

Hi everyone! I'm new with Shell Scripting, and I have to do a shell script to call a procedure, which have 2 input parameters, the directory(from server) and the txt file (which have informations to update/insert in DB). I have to create a shell script to execute that procedure for each txt... (5 Replies)
Discussion started by: renatoal
5 Replies

9. Shell Programming and Scripting

How to call the ksh script when rebooting the server

Hi all, Can any one help me....... I just want to run one shell script whenever i am rebooting the server. Is there any easy way to do that???? Thanks, selva (7 Replies)
Discussion started by: Selva_Kumar
7 Replies

10. Shell Programming and Scripting

i want to call a oracle function in my shell script

i want to call a oracle function in my shell script (4 Replies)
Discussion started by: dineshr85
4 Replies
Login or Register to Ask a Question