Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Index Range Scan Oracle
  • Error Handling in Proc Oracle
  • Benefits and Usage of RMAN with Standby Databases Oracle
  • Updated LCK.SQL file. Oracle
  • Important Script Method for tuning Oracle
  • plan10g.sql good Oracle
  • Very Good Oralce Internal Tuning Book Oracle
  • sess1.sql Oracle
  • How can I tell if ASO is installed ? Oracle
  • DBMS_UTILITY PACKAGE Oracle
  • Committing distributed transaction using commit force Oracle
  • Monitor and Trace Unix processes using truss Linux/Unix
  • Find execution plan from dba_hist_sql_plan for a specific SQL_ID and PLAN_HASH_VALUE fplan.sql Oracle
  • Histogram information Oracle
  • Good link for LIO in Oracle ( Logical IOs) Oracle

How does one SELECT a value from a table into a Unix variable? From SQL to Shell

Posted on 23-Aug-2005 By Admin No Comments on How does one SELECT a value from a table into a Unix variable? From SQL to Shell

One can select a value from a database column directly into a Unix environment variable. Look at the following shell script examples:

#!/bin/sh

VALUE=`sqlplus -silent user/password@instance < set pagesize 0 feedback off verify off heading off echo off

select max(c1) from t1;

exit;

END`

if [ -z “$VALUE” ]; then

echo “No rows returned from database”

exit 0

else

echo $VALUE

fi

Second example, using the SQL*Plus EXIT status code (can only return integer values smaller than 256):

#!/bin/ksh

sqlplus -s >junk1 /nolog < connect user/password@instance

column num_rows new_value num_rows format 9999

select count(*) num_rows

from table_name;

exit num_rows

EOF

echo “Number of rows are: $?”

Yet another example, only this time we will read multiple values from SQL*Plus into shell variables.

sqlplus -s /nolog |& # Open a pipe to SQL*Plus

print -p — ‘connect user/password@instance’

print -p — ‘set feed off pause off pages 0 head off veri off line 500’

print -p — ‘set term off time off’

print -p — “set sqlprompt ””

print -p — “select sysdate from dual;”

read -p SYSDATE

print -p — “select user from dual;”

read -p USER

print -p — “select global_name from global_name;”

read -p GLOBAL_NAME

print -p — exit

echo SYSDATE: $SYSDATE

echo USER: $USER

echo GLOBAL_NAME: $GLOBAL_NAME

Linux/Unix, shell

Post navigation

Previous Post: Good Link from metalink 1
Next Post: How does one overcome the Unix 2 Gig file limit?

Related Posts

  • Reading parameter file and printing Linux/Unix
  • Single character replacement in Unix Linux/Unix
  • adding new line after specific pattern using sed Linux/Unix
  • More info about /proc folder and its relation with processes. Linux/Unix
  • nfs mount command Linux/Unix
  • replace alphabets using sed Linux/Unix

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Django (0)
  • GIT (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (400)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (18)
  • rman-dataguard (26)
  • shell (150)
  • SQL scripts (348)
  • SQL Server (6)
  • Uncategorized (3)
  • Videos (0)

Recent Posts

  • Running PDB on single node in RAC09-Apr-2026
  • find_arc.sql09-Apr-2026
  • pvm_pre_change.sql08-Apr-2026
  • find_encr_wallet.sql08-Apr-2026
  • find_pdbs.sql08-Apr-2026
  • Creating a Container Database using dbaascli08-Apr-2026
  • track_autoupgrade_copy_progress.sql01-Apr-2026
  • refre.sql for multitenant01-Apr-2026
  • prepfiles.sh for step by step generating pending statistics files10-Mar-2026
  • tracksqltime.sql05-Mar-2026

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • scripts to take listener.log backup Linux/Unix
  • How to set Processes Parameter Oracle
  • Good Doc 28-JUN-2006 Oracle
  • DBMS_SQL for alter session. Oracle
  • to see when crontab is changed. Linux/Unix
  • Global Unique Identifier Generation in Oracle 9.2 SYS_GUID() Oracle
  • ORACLE_SID in sqlplus Oracle
  • DETERMINING WHICH INSTANCE OWNS WHICH SHARED MEMORY & SEMAPHORE SEGMENTS Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme