Computing.Net > Forums > Unix > grep SQL code

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

grep SQL code

Reply to Message Icon

Name: bhben
Date: November 30, 2004 at 05:31:07 Pacific
OS: Windows XP
CPU/Ram: P4, 512MB
Comment:

Hi, i have a script that runs some SQL code and prints the count of records in a table to another file. This file is being used to setup XML code, so first i will echo a tag, then have the tables and then the closing tag. What i wish for is to setup an IF statement around this so that is there is a 0 count of records trhe word PASS will be written to XML and if there are records then FAIL will be written to XML. Sort of like this:
<result>PASS</result>
<data>
records tablename
0 table
</data>

Or a fail if there are records. I currently only have the data tag. So far i am echoing the tags and sending the ouput to $dir1, i then open sql, run an sql script and send this to $dir1 and then exit sql and echo the next tag. I am trying to egrep but am struggling since i can't use egrep whilst in sql. Please help.



Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: November 30, 2004 at 07:54:48 Pacific
Reply:

I would pull all of my table row counts first (suppress headers and spool to a file), then process that file to build your XML code, and your logic at that point could see if a row count is zero or not:

spool counts.lst
select 'emp',  count(*) from emp;
select 'dept', count(*) from dept;
select 'ord',  count(*) from ord;
spool off

emp   17
dept    8
ord    21


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: grep SQL code

Script to migrate oracle data www.computing.net/answers/unix/script-to-migrate-oracle-data/6024.html

SQL in shell script www.computing.net/answers/unix/sql-in-shell-script/5703.html

Check for new file, exec sql*plus www.computing.net/answers/unix/check-for-new-file-exec-sqlplus/6714.html