Conditional execution of SQL scripts

If we want to execute a script, based on the values of a flag, we can use following steps

STEP 1

Create a script to write the output to flag file

variable v_status number;
declare
begin
SELECT COUNT(*) into :v_status FROM TEST WHERE ACTIVE = ‘TRUE’;
exception
when others then
NULL;
end;
/

spool off
set termout off
set heading off
spool /usr/dump/check.dat
print v_status
exit
/

STEP 2

Now in a shell script, to check the status of flag

if (grep -s 0 /usr/dump/check.dat) then

else

fi

Advertisements
This entry was posted in Unix Oracle scripting and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s