Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Oracle GoldenGate lag monitoring shell script Linux/Unix
  • CPU Core related projections AWS
  • Rman Notes -1 Oracle
  • pvmehta.com SQL scripts
    Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle Oracle
  • Find execution plan from dba_hist_sql_plan for a specific SQL_ID and PLAN_HASH_VALUE fplan.sql Oracle
  • Establishing trusted relationship between dbmonitor( central monitoring) and monitoring targets. Linux/Unix
  • How to collect CPU usage on Linux using Shell script Linux/Unix
  • CTAS with LONG Column for 9i and higher Oracle
  • Move WordPress site from one hosting service to other. PHP/MYSQL/Wordpress
  • How to hide author name in WordPress BLOG PHP/MYSQL/Wordpress
  • Oracle Release Explaination Oracle
  • Good link for LIO in Oracle ( Logical IOs) Oracle
  • upload.html PHP/MYSQL/Wordpress
  • Linux CPU info. Linux/Unix
  • SQL_PROFILE – I explaination 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

  • purge_trc.sh Linux/Unix
  • xargs use Linux/Unix
  • how to find VIP from ifconfig Linux/Unix
  • Small sample shell program Linux/Unix
  • Some useful Unix Commands Linux/Unix
  • cif crons 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)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (393)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (0)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (342)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • Trace a SQL session from another session using ORADEBUG30-Sep-2025
  • SQL Server Vs Oracle Architecture difference25-Jul-2025
  • SQL Server: How to see historical transactions25-Jul-2025
  • SQL Server: How to see current transactions or requests25-Jul-2025
  • T-SQL Vs PL/SQL Syntax25-Jul-2025
  • Check SQL Server edition25-Jul-2025
  • Checking SQL Server Version25-Jul-2025
  • Oracle vs MYSQL Architecture differences (For DBAs)24-Jul-2025
  • V$INSTANCE of Oracle in MYSQL24-Jul-2025
  • Day to day MYSQL DBA operations (Compared with Oracle DBA)24-Jul-2025

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • cur_sql.sql Oracle
  • SQL Server Vs Oracle Architecture difference SQL Server
  • Sample WW22 listener.ora Oracle
  • Import and export statements Oracle
  • Removing first line Linux/Unix
  • refre.sql Oracle
  • tblwopk.sql tablewopk.sql Oracle
  • Reclaim temp tablespace for oracle 8, 8i Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme