Setting Oracle Environment in Scripts

   Send article as PDF   

A quickie! How do you set the correct Oracle environment in scripts? Do you hard code? You better not.

I’ve lost count of the times I’ve ended up with, for example, a 10g database running with bits of the 9i software hanging around. It leads to monumental problems that can be hard to track down.

Moral: Do not hard code Oracle environment details.

This is what I usually do:

#!/usr/bin/env bash

export ORACLE_SID=my_sid
. oraenv

# Rest of bash script goes here....

Reagrdless of how many times the database version gets an update, you will still always have the correct Oracle software on the path and in the environment when the script runs.

Today, I learned a new way to do the above, with much less typing. You can see an example here.

#!/usr/bin/env bash

. oraenv <<EOF

# Rest of bash script goes here....

All those years of Oracle and I never figured out that I could user a “here” document. Thanks Gokhan.

One thought on “Setting Oracle Environment in Scripts”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.