Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • ORA-00064: object is too large to allocate on this O/S during startup Oracle
  • When to rebuld B-tree index Oracle
  • Good notes for shared pool Oracle
  • Alter procedure auditing Oracle
  • Generate SSH without password authentication. Linux/Unix
  • On solaris 10, “S” link is not part of $ORACLE_HOME/bin/oracle as default. ( For 9.2.0.8) Oracle
  • Rollback force for distributed transactions Oracle
  • SQL Server Vs Oracle Architecture difference SQL Server
  • moving lob object to other tablespace lob_mvmt.sql Oracle
  • Gathering statistics with DBMS_STATS Oracle
  • Clean up Oracle
  • Giving Grant on v$DATABASE Oracle
  • Histogram information Oracle
  • Configure ssh authentications for RAC Oracle
  • Default User Profile 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

  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • to see when crontab is changed. Linux/Unix
  • tuning commmand for cpu, ip and memory stats Linux/Unix
  • How to change hostname in Linux Linux/Unix
  • To Find Orphan OS processes. Linux/Unix
  • send attachment from unix-shell script 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 (403)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (18)
  • rman-dataguard (26)
  • shell (150)
  • SQL scripts (350)
  • SQL Server (6)
  • Uncategorized (5)
  • Videos (0)

Recent Posts

  • Key Management in Oracle: The Core Issue: Missing Master Key12-May-2026
  • SAT Mathematics 10 questions and answer at the end.30-Apr-2026
  • top 10 AI news today30-Apr-2026
  • runon_allpdbs_show_conname.sh23-Apr-2026
  • runon_allcdbs_find_pdbs.sql23-Apr-2026
  • 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

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • How does one overcome the Unix 2 Gig file limit? Linux/Unix
  • Zip and unzip with tar Linux/Unix
  • Proc Compilation Oracle
  • send attachment from unix-shell script Linux/Unix
  • USE_NL and INDEX hints example Oracle
  • Oracle Material from OTN Oracle
  • Gathering statistics with DBMS_STATS Oracle
  • Database link password in user_db_links Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme