Problem in quitting/exiting from sqlplus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in quitting/exiting from sqlplus
# 1  
Old 08-28-2012
Problem in quitting/exiting from sqlplus

Hello,

This is my first post and I would be very thankful if you can help me. I've already searched in the forum and I've found a very similar thread in wich my problem is solved, but the thread is closed and the solution given in it doesn't work in my shell:

153194-problem-quitting-sqlplus

(Sorry but the system doesn't allow me to post complete URLs).

My script is the following:

Code:
#!/bin/bash

COUNT1=0
echo $COUNT1
if [[ ("$COUNT1" -eq "0") ]]; then
        echo 'hello'
fi

export ORACLE_SID=TCR
sqlplus -S /nolog  << EOF > output &
set linesize 3000
set trimspool on
set pagesize 55
connect / as sysdba
select 'COUNT1='||count(*) from reporter.reporter_status where alarma_rpv=8 and LASTOCCURRENCE > (sysdate - 5/1440);
quit;
EOF

if [[ ("$COUNT1" -gt "0") ]]; then
        echo 'hello'
fi

The first "if" works properly but the second one doesn't, and "COUNT1" is greater than zero. Of course, the query is also redirected to the file "output". I've also tried using "EXIT" instead of "quit" but it neither works.

Could you help me?

Thanks!

Last edited by JuanPerez; 08-28-2012 at 09:38 AM..
# 2  
Old 08-28-2012
What do you mean by second if doesnt work? You espect a value greater than zero and you get 0?
# 3  
Old 08-28-2012
Further information: If I delete "-s" argument to "sqlplus" command and I open the output file, I have the following:

Code:
 
SQL*Plus: Release 11.2.0.2.0 Production on Tue Aug 28 14:28:57 2012
 
Copyright (c) 1982, 2010, Oracle. All rights reserved.
 
SQL> SQL> SQL> SQL> Conectado.
SQL>
'COUNT1='||COUNT(*)
-----------------------------------------------
COUNT1=483
 
SQL> Desconectado de Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

So it means it exists saccessfully from sqlplus, but I don't know why it doesn't execute the remaining shell...

Thanks!

---------- Post updated at 07:36 AM ---------- Previous update was at 07:32 AM ----------

Quote:
Originally Posted by vbe
What do you mean by second if doesnt work? You espect a value greater than zero and you get 0?
Hi!

I mean I have a value greater than zero because it is written in the output file. I've also tried with another commands like "rm output" instead of a conditional clause, but it neither works, because the output file is still there. What I mean is the execution stops when it exits sqlplus...

Thanks!
# 4  
Old 08-28-2012
I wonder if it is not:
Code:
sqlplus -S /nolog  << EOF > output &

Try to remove the ampersand "&"
# 5  
Old 08-28-2012
If I understand correctly, you need something different.

Try this:

Code:
 
COUNT1=$(
sqlplus -S / as sysdba <<EOF
set trimspool on
set pagesize 0 feed off head off
select count(*) from reporter.reporter_status 
where alarma_rpv=8 and LASTOCCURRENCE > (sysdate - 5/1440);
EOF
)

instead of:

Code:
sqlplus -S /nolog  << EOF > output &
set linesize 3000
set trimspool on
set pagesize 55
connect / as sysdba
select 'COUNT1='||count(*) from reporter.reporter_status where alarma_rpv=8 and LASTOCCURRENCE > (sysdate - 5/1440);
quit;
EOF


Something like this:

Code:
 
#!/bin/bash
COUNT1=0
echo "$COUNT1"
if [[ $COUNT1 -eq 0 ]]; then
        echo 'hello'
fi
export ORACLE_SID=TCR
COUNT1=$(
sqlplus -S / as sysdba <<EOF
set trimspool on
set pagesize 0 feed off head off
select count(*) from reporter.reporter_status 
where alarma_rpv=8 and LASTOCCURRENCE > (sysdate - 5/1440);
EOF
)
if [[ $COUNT1 -gt 0 ]]; then
        echo 'hello'
fi


Last edited by radoulov; 08-28-2012 at 09:45 AM..
# 6  
Old 08-28-2012
Is your goal to assign the result of a sqlplus-query to a variable? The syntax for that is wrong and I wouldn't start the query in the background. quit or exit are not needed btw. Try this:
Code:
#!/bin/bash

COUNT1=0
echo $COUNT1
if [[ ("$COUNT1" -eq "0") ]]; then
        echo 'hello'
fi

export ORACLE_SID=TCR
COUNT1=$(sqlplus -S /nolog  << EOF > output 
set linesize 3000
set trimspool on
set pagesize 55
set heading off
connect / as sysdba
select count(*) from reporter.reporter_status where alarma_rpv=8 and LASTOCCURRENCE > (sysdate - 5/1440);
EOF
)

if [[ ("$COUNT1" -gt "0") ]]; then
        echo 'hello'
fi

# 7  
Old 08-28-2012
Quote:
Originally Posted by vbe
I wonder if it is not:
Code:
sqlplus -S /nolog  << EOF > output &

Try to remove the ampersand "&"
Thanks but it doesn't work! Smilie

---------- Post updated at 07:48 AM ---------- Previous update was at 07:42 AM ----------

Quote:
Originally Posted by radoulov
If I understand correctly, you need something different.

Try this:

Code:
 
COUNT1=$(
sqlplus -S / as sysdba <<EOF
set trimspool on
set pagesize 0 feed off head off
select count(*) from reporter.reporter_status 
where alarma_rpv=8 and LASTOCCURRENCE > (sysdate - 5/1440);
EOF
)

instead of:

Code:
sqlplus -S /nolog  << EOF > output &
set linesize 3000
set trimspool on
set pagesize 55
connect / as sysdba
select 'COUNT1='||count(*) from reporter.reporter_status where alarma_rpv=8 and LASTOCCURRENCE > (sysdate - 5/1440);
quit;
EOF

Something like this:

Code:
 
#!/bin/bash
COUNT1=0
echo "$COUNT1"
if [[ $COUNT1 -eq 0 ]]; then
        echo 'hello'
fi
export ORACLE_SID=TCR
COUNT1=$(
sqlplus -S / as sysdba <<EOF
set trimspool on
set pagesize 0 feed off head off
select count(*) from reporter.reporter_status 
where alarma_rpv=8 and LASTOCCURRENCE > (sysdate - 5/1440);
EOF
)
if [[ $COUNT1 -gt 0 ]]; then
        echo 'hello'
fi


It works!!!! SmilieSmilie

And what if I needed to save more than one count value? I mean if I used "gorup by"... Would I have to use cursors or something like that?

Thank you and thanks everybody!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem exiting a WHILE loop in ksh

Hi I am having a problem exiting a WHILE loop. I am on a Sun server using ksh. I am running a Veritas Cluster Software (High Availablity) command to obtain a group status and grepping the command output for status "G" which means that the filesystem is frozen and therefore not available to... (3 Replies)
Discussion started by: bigbuk
3 Replies

2. AIX

SQLPLUS problem

Hi guys, Here is the error i get by running a "sqlplus -v" after installing an oracle client 10.2.0.5 on an AIX 5.3.9 server. Could not load program sqlplus: Symbol resolution failed for sqlplus because: Symbol __pthread (number 307) is not exported from dependent ... (3 Replies)
Discussion started by: Chapel
3 Replies

3. Shell Programming and Scripting

SQLplus and Shell script problem

sql_rows=`sqlplus -s / <<EOF set heading off set pagesize 1000 set tab off set linesize 120 wrap off column "Path" format a15 --column "No_Of_files" format a10 select tablespace_name, substr(file_name,1,instr(file_name,'/',1,2)) as "Path" , count(*) as "No_Of_files" from dba_data_files ... (7 Replies)
Discussion started by: desibabu
7 Replies

4. Shell Programming and Scripting

problem in quitting from sqlplus

Hi all, I have a scenario where im connecting to sqlplus executing a query,redirecting the output to a file and manipulating the file MY CODE IS AS FOLLOWS sqlplus -s /nolog << EOF > $UTILITIES_HOME/temp/analyze.temp.log & set linesize 3000 set trimspool on set pagesize... (2 Replies)
Discussion started by: niteesh_!7
2 Replies

5. Shell Programming and Scripting

Quitting a bash script... any alternatives to exit?

Folks, Below is a basic synopsis of the problem. I have a script that I need to check for some env vars and fail (exit the script) if they are not there. At the same time I need to set some default env vars. To do this I must run the script from the parent shell or source the script. Doing... (3 Replies)
Discussion started by: bashN00b
3 Replies

6. Shell Programming and Scripting

Quitting from a script, either sourced or not

This is a very simple problem, I am wondering why I can find no answer anywhere... I have a script that can be run either sourced or not. This script has some place where it needs to quit execution (e.g., when an error is found) If I "exit", the sourced call would exit the parent shell, but... (7 Replies)
Discussion started by: MadMage
7 Replies

7. Shell Programming and Scripting

Problem in exiting a loop

Hi my code looks like: if test $STEP -le 10 then . . ls -1d AM*-OUT|while read MYDIR do cd $MYDIR ls |tail -n1| while read MYFILE do . . if test -s $MYFILE then sqlldr .... rc=$? if test $rc -ne 0 (3 Replies)
Discussion started by: anijan
3 Replies

8. Solaris

Emacs changes the term colors after quitting

Ok. So I've finally compiled the latest version of GNU emacs on Solaris 5.8. I've set putty up so that it sets TERM=xtermc. emacs now has syntax highlighting. The problem is, whenever I quit emacs, it changes the screen colors. The background is now the same as the color of the minibuffer. It... (1 Reply)
Discussion started by: m9dhatter
1 Replies

9. UNIX for Advanced & Expert Users

Problem while calling Oracle 10g SQLPLUS files

Hi all, Iam facing a lot of problem while calling Oracle 10g SQLPLUS files from shell. What is the standard procedures to be taken care. Any help would be useful for me. Thanks in advance, Ganapati. (2 Replies)
Discussion started by: ganapati
2 Replies

10. Shell Programming and Scripting

KSH Sqlplus problem

Hi, trying this =============================== Temp=`sqlplus -s user/passwd <<EOF WHENEVER SQLERROR EXIT 1 set serverout on set feedback off set heading off select nam from tabel1 where x=y; EOF` echo Temp>>$logfile ================================= The select statement is... (2 Replies)
Discussion started by: amitkr
2 Replies
Login or Register to Ask a Question