Question

How to use Unix environment variable in a SQL query

Rating8.0Very Good

Hi,

I would like how to retrieve the value of an environment variable to use it in a SQL statement defined in testvarenv.sql and run when called in the file testvarenv.sh.
I know that the solution could be to insert the SQL statement in the Shell script, but I don't want to do this.

The files are described below.

Thanks in advance,
Pyxos

testvarenv.sql
--------------
delete from DESCRIPTIONS where description_code = 32000;
insert into DESCRIPTIONS (description_code, description_text, language_code, description_group) values (32000, $ARBORDIR || '/test', 1, 0);

testvarenv.sh
-------------
#!/bin/ksh

if [ $# -ne 3 ]
then
      echo "\n You need to provide the user, password and database names."
      echo "\n e.g. encapsulation.sh user password database\n"
      exit -1
fi

USER=$1
PASS=$2
DATABASE=$3


sqlplus $USER/$PASS@$DATABASE  << THEEND

@testvarenv

commit;

exit

THEEND

echo "Configuration done."

  1. moving files in unix
    i need to move a file form one unix server to another need quick help
  2. Oracle Environment variable
    I have set ORACLE_HOME=c\app\Hussain\product\11.1.0\db_1 variable on windows vista machine for Oracle11g. But now i would like to check whether the ORACLE_HOME is set properly or not. In unix after setting we can check with ECHO $ORACLE_HOME but in windows how can we check
  3. oracle sql query in unix
    Hi, I have a query which i will run via a unix shell scripts. If any rows are returned by the query i need to exit with 1 (error) or 0 if no rows are returned. What is the best way to do this ? thanks H my query is just: select SID , USERNAME, OSUSER, machine,EVENT, state, sl.sql_text from v\$session s, v\$sql …
  4. oracle-unix
    In unix -how u will connect to ur oracle database?
  5. SQL Plus Login Error - Mail from UNIX Shell
    I have a shell (korn) which runs sql scripts and mails the results via mailx to a list of recipients. Periodically the target database is unavailable but a blank email is still sent. Is there any way of preventing the blank emails being sent and instead raise an exception and email that to one recipient (me) notifiying me of the database error?

Solution

Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.

About this Solution
View This Solution - Start Your 30 Day Free Trial
Zone
General
Tags
sqlplus how ksh query variable
Participating Experts
2
Solution Grade
A

Replies

 
by: sbenyo

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 
by:

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 
by: pyxos

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

Stay Connected

Oracle Around the Web

The latest Oracle news, tips, and tricks

Oracle Unveils Netra SPARC T3 Servers

New Carrier-Grade Blade and Rackmount Servers Deliver Better Performance, Density and Power Efficiency for the Communications Industry ...

read more

Oracle fixes 21 flaws in Java SE, Java for Business

Oracle is fixing 21 flaws in its Java SE and Java for Business products in its February critical patch update issued this week ...

read more

Obama’s Silicon Valley “Tech Supper”

Why was he there? Who wasn’t invited and why? What did they talk about? Why was he really there? These are the questions being debated ...

read more

Featured Oracle Experts

slightwv

slightwv has answered more than 2,000 Oracle questions and oversees database management within the U.S. Government. Slightwv

sdstuber

A regular presenter at the Collaborate conference, Oracle developer sdstuber is a top expert in PL/SQL and Oracle 9, 10 and 11. sdstuber

Testimonials

What users are saying about our experts

"The Oracle gurus provide answers, solutions and valuable workarounds"

User: schwertner

"Wow! Excellent, valuable explanation. Hats off to you"

User: aseshu70

"Solution worked fantastic and performs excellent! Thanks heaps"

User: klausbrandlhuber

Top Experts

  1. slightwv

    2,000

    0 points yesterday

    Profile

BrowseBecome an Expert