Below are different ways to get SQL query output inside unix shell script.
Method 1:
{
/bin/echo "set pause off"
/bin/echo "set pagesize 0"
/bin/echo "set linesize 300"
/bin/echo "set feedback off"
/bin/echo "set echo off"
/bin/echo "set term off"
/bin/echo "SELECT location_id
FROM location
WHERE facility_id = 'W1';"
} | sqlplus -s dbuser/dbpwd
Method 2:
Please note that ENDSQL is not a key word, you can use any word.
sqlplus -s dbuser/dbpwd << ENDSQL
set pause off
set pagesize 0
set linesize 300
set feedback off
set echo off
set term off
select location_id from location where facility_id='W1' and rownum < 2;
EXIT;
ENDSQL
Method 3:
sqlplus -s dbuser/dbpwd << ENDSQL
set pause off
set pagesize 0
set linesize 300
set feedback off
set echo off
set term off
@filename.sql
EXIT;
ENDSQL
No comments:
Post a Comment