dbTalk Databases Forums  

Did the query return any rows

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Did the query return any rows in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Randy Harris
 
Posts: n/a

Default Did the query return any rows - 05-22-2005 , 06:17 PM






I'm calling SQL*Plus to run a query from inside a Unix (ksh) script. How
can I tell whether the query returned any rows or not?


Reply With Quote
  #2  
Old   
absinth
 
Posts: n/a

Default Re: Did the query return any rows - 05-22-2005 , 07:12 PM






Consider:


SQL> select row_id from CX_LOCK;

ROW_ID
---------------
1
2
3
4
5
6
7
8
9
10
11

ROW_ID
---------------
12

12 rows selected.

SQL> select row_id from CX_LOCK where ROW_ID='abc';

no rows selected


Reply With Quote
  #3  
Old   
IANAL_VISTA
 
Posts: n/a

Default Re: Did the query return any rows - 05-22-2005 , 07:31 PM



"Randy Harris" <randy (AT) SpamFree (DOT) com> wrote in
news:1q8ke.90$3V.58 (AT) newssvr31 (DOT) news.prodigy.com:

Quote:
I'm calling SQL*Plus to run a query from inside a Unix (ksh) script. How
can I tell whether the query returned any rows or not?


By making "proper" use of SQL*Plus & the ability to generate a SPOOL file,
I test for non-zero length of the output file. In other words zero rows
results in a spool file of length 0. I use this approach daily in cron jobs



Reply With Quote
  #4  
Old   
Randy Harris
 
Posts: n/a

Default Re: Did the query return any rows - 05-22-2005 , 07:32 PM




"absinth" <absinth (AT) gmail (DOT) com> wrote

Quote:
Consider:


SQL> select row_id from CX_LOCK;

ROW_ID
---------------
1
2
3
4
5
6
7
8
9
10
11

ROW_ID
---------------
12

12 rows selected.

SQL> select row_id from CX_LOCK where ROW_ID='abc';

no rows selected
But how can I determine in the script whether any rows were returned? Is
there some way to "capture" that no rows selected message?



Reply With Quote
  #5  
Old   
absinth
 
Posts: n/a

Default Re: Did the query return any rows - 05-22-2005 , 07:44 PM



Couldn't you grep for it?

grep '^No rows selected' blah.out

if [[ $? -eq 0 ]]
then
xxxxx
fi


Reply With Quote
  #6  
Old   
Randy Harris
 
Posts: n/a

Default Re: Did the query return any rows - 05-22-2005 , 07:47 PM




"IANAL_VISTA" <IANAL_Vista (AT) hotmail (DOT) com> wrote

Quote:
"Randy Harris" <randy (AT) SpamFree (DOT) com> wrote in
news:1q8ke.90$3V.58 (AT) newssvr31 (DOT) news.prodigy.com:

I'm calling SQL*Plus to run a query from inside a Unix (ksh) script.
How
can I tell whether the query returned any rows or not?



By making "proper" use of SQL*Plus & the ability to generate a SPOOL file,
I test for non-zero length of the output file. In other words zero rows
results in a spool file of length 0. I use this approach daily in cron
jobs

I'm running the jobs from cron and generating spool files. It didn't occur
to me that the file would be 0 length. I assumed that it would contain the
message "no rows selected". Thanks.



Reply With Quote
  #7  
Old   
IANAL_VISTA
 
Posts: n/a

Default Re: Did the query return any rows - 05-22-2005 , 07:52 PM



"Randy Harris" <randy (AT) SpamFree (DOT) com> wrote in
news:PK9ke.107$l51.44 (AT) newssvr31 (DOT) news.prodigy.com:

Quote:
"IANAL_VISTA" <IANAL_Vista (AT) hotmail (DOT) com> wrote in message
news:Xns965EB230B9ADFSunnySD (AT) 68 (DOT) 6.19.6...
"Randy Harris" <randy (AT) SpamFree (DOT) com> wrote in
news:1q8ke.90$3V.58 (AT) newssvr31 (DOT) news.prodigy.com:

I'm calling SQL*Plus to run a query from inside a Unix (ksh)
script.
How
can I tell whether the query returned any rows or not?



By making "proper" use of SQL*Plus & the ability to generate a SPOOL
file, I test for non-zero length of the output file. In other words
zero rows results in a spool file of length 0. I use this approach
daily in cron
jobs


I'm running the jobs from cron and generating spool files. It didn't
occur to me that the file would be 0 length. I assumed that it would
contain the message "no rows selected". Thanks.


Not if
SET FEEDBACK NO


Reply With Quote
  #8  
Old   
absinth
 
Posts: n/a

Default Re: Did the query return any rows - 05-22-2005 , 08:09 PM



Couldn't you grep for it?

grep '^No rows selected' blah.out

if [[ $? -eq 0 ]]
then
xxxxx
fi


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.