Returning an SQL result to a Shell script

Hi

Often it can be useful to return the result of a simple SQL*Plus query to a shell script variable, for example to check for a value before deciding wether or not to proceed.  The syntax is actually pretty simple :

#!/bin/sh
count=$(sqlplus -s 'scott/tiger@xe'<<EOF
  set pages 0 feed off
  select count(*) from tab;
EOF
)
echo $count

Enjoy!
Bookmark and Share

Tags: , ,

Leave a Reply

You must be logged in to post a comment.