Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Re: Shell scripting

Re: Re: Shell scripting

From: Jared Still <jkstill_at_cybcon.com>
Date: Tue, 08 Oct 2002 07:23:46 -0800
Message-ID: <F001.004E3404.20021008072346@fatcity.com>

Omar,

If what you mean is:

"How do I send a value from sqlplus plus directly to a variable in my shell environment?"

You can't.

What you've done is the way it is usually done.

Another way to do it is to use the '&|' korn shell mechanism.

e.g.
  sqlplus -silent scott/tiger@$ORACLE_SID |&

This allows you to send commands straight to sqlplus from the ksh command line, and retrieve the results of queries from the cmd line.

It's not as easy as it appears. I wrote a set of shell functions once upon a time to do this, and it gets more complex than you expect.

The method you are currently using works ok.

Of course, you could use Perl with DBI and avoid all this subshell nonsense.

Jared

On Tuesday 08 October 2002 01:23, Cyril Thankappan wrote:
> Sure
>
> THanks Omar
>
> But I was looking for a
> 'non-file based' solution :)
>
> Thanks anyway
>
> On Mon, 07 Oct 2002 Omar Khalid wrote :
> >hi
> >
> >well i think i did this once, you can read
> >the output of the SQL query into shell variables by
> >first redirecting the output of the SQL query to an
> >OS file and then reading the file and loading
> >the data in the file into shell variables.
> >
> >/* here is sample code to redirect the output of sql query to OS
> >file */
> >
> >#!/bin/sh
> >
> >CMD_FILE=sql_input.sql
> >LOC_FILE=output.log
> >
> > SQLCMD="connect internal ;
> > select * from sys.dba_users ;"
> > echo "$SQLCMD" > ${CMD_FILE}
> >
> > svrmgrl < ${CMD_FILE} > ${LOC_FILE} /* redirecting the
> >out of
> >svrmgrl to OS file */
> >
> >regards
> >'_-_'_-_'_-_'_-_'_-_'_-_'_-_'_-_'_-_'
> >Omar Khalid
> >Software Engineer
> >LMK Resources
> >Voice: 111-101-101*780
> >Mobile: 0333-510-4465
> >Web: www.lmkr.com
> >'_-_'_-_'_-_'_-_'_-_'_-_'_-_'_-_'_-_'
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > "Cyril
> > Thankappan" To: Multiple
> >recipients of list ORACLE-L <ORACLE-L_at_fatcity.com>
> > <cyril_thank_at_redif cc:
> > fmail.com> Subject: Shell
> >scripting
> > Sent by:
> > root_at_fatcity.com
> >
> >
> > 10/04/2002 09:18
> > PM
> > Please respond to
> > ORACLE-L
> >
> >
> >
> >
> >
> >
> >Hi
> >
> >I wanted to select a column from a v$ table
> >
> >struggled with it
> >and finally came with a workaround as follows
> >
> >------------------------------------
> >
> >archived_log='$archived_log'
> >begin_seq=`sqlplus -s /nolog <<EOF
> >connect / as sysdba
> >set head off
> >set echo off
> >set feedback off
> >set verify off
> >select max(sequence#)-1 from v$archived_log ;
> >exit
> >EOF`
> >echo $begin_seq
> >
> >---------------------------------------
> >
> >However, the question is how to
> >'directly' take the output into a shell variable?
> >there 'shud be' a better workaround than this !
> >
> >Thanks
> >--
> >Please see the official ORACLE-L FAQ: http://www.orafaq.com
> >--
> >Author: Cyril Thankappan
> > INET: cyril_thank_at_rediffmail.com
> >
> >Fat City Network Services -- 858-538-5051
> >http://www.fatcity.com
> >San Diego, California -- Mailing list and web hosting
> >services
> >---------------------------------------------------------------------
> >To REMOVE yourself from this mailing list, send an E-Mail
> >message
> >to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and
> >in
> >the message BODY, include a line containing: UNSUB ORACLE-L
> >(or the name of mailing list you want to be removed from). You
> >may
> >also send the HELP command for other information (like
> >subscribing).
> >
> >
> >
> >
> >--
> >Please see the official ORACLE-L FAQ: http://www.orafaq.com
> >--
> >Author: Omar Khalid
> > INET: okhalid_at_lmkr.com
> >
> >Fat City Network Services -- 858-538-5051
> >http://www.fatcity.com
> >San Diego, California -- Mailing list and web hosting
> >services
> >---------------------------------------------------------------------
> >To REMOVE yourself from this mailing list, send an E-Mail
> >message
> >to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and
> >in
> >the message BODY, include a line containing: UNSUB ORACLE-L
> >(or the name of mailing list you want to be removed from). You
> >may
> >also send the HELP command for other information (like
> >subscribing).

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Jared Still
  INET: jkstill_at_cybcon.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Tue Oct 08 2002 - 10:23:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US