U of A University of Arkansas Division of Agriculture

Pictures of chickens, flowers, wheat, a boy looking through a magnifying glass, irrigation pipe, soybean pods, and fruits and vegetables.

Cooperative Extension Service

Cooperative Extension Service

Agricultural Experiment Station

Steve Rea's
Oracle Tips, Tricks, and Scripts

Link to Steve Rea's Oracle Certification graphic


Search | Publications | Jobs | Personnel Directory | Links

Setting Unix Environment Variables From SQL

If you need to use a value from a table in a UNIX shell script, you can retrieve the value in sqlplus, set a shell environment variable from that retrieved value, and use that environment variable in your shell script.  For example, suppose you are creating a shell script to run an sql script using runsqlplus, but want to use a printer entered in the first parameter of the job submission screen instead of the printer specified in the Printer environment variable set by the job submission screen.  The following retrieves parameter number 01 for the current job being run by job submission and stores it in the unix environment variable named "printer". The tic (or whatever it's called) symbol, ` , is below the tilde symbol, ~ , on the top left of most keyboards.

`echo \`sqlplus -S $UID/$PSWD <<EOF
select gjbprun_value from gjbprun where gjbprun_number = '01'
   and gjbprun_one_up_no = $ONE_UP;
EOF\` | sed 's/.* \(.*\)/export printer=\1/'`

Then, you could do something like:
    runsqlplus $UID $PSWD mysqlscript $ONE_UP $HOME/$TEMP.lis $LOG $printer
instead of the current:
    runsqlplus $UID $PSWD mysqlscript $ONE_UP $HOME/$TEMP.lis $LOG $PRNT

This technique can be used to retrieve any value from the database and set an environment variable independent of job submission.  You would just have to substitute a user ID and password for $UID and $PSWD, and change the select statement to any other select statement that returns just one value that didn't contain embedded blanks.  If the value did contain blanks, you would have to modify the sed command to just strip off the header instead of everything up through the last blank.  (This exercise is left to the reader.)

This Page was Last Updated on 06/04/07

You Are Visitor Number

Hit Counter

Link to CES Home PageBack To CES Home Page

Link to Steve Rea's Oracle PageBack To Steve Rea's Oracle Page

Back to top of this pageBack To Top


© 2006
University of Arkansas
Division of Agriculture
All rights reserved.
Last Date Modified 02/09/2008
Webmaster

University of Arkansas • Division of Agriculture
Cooperative Extension Service
2301 South University Avenue
Little Rock, Arkansas 72204 • USA
Phone (501) 671-2000 • Fax (501) 671-2209
 

MissionDisclaimerEEO
PrivacyFOI