Returning an SQL result to a Shell script

Returning an SQL result to a Shell script

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!

 


Comments (0)


Add a Comment

Please login to comment.