Detecting if an Oracle Database is Installed

I was wondering if there was a way to tell if an instance of Oracle on a system has a database installed or not?

This is for an installation script, and I need to verify that there is an actual database in place before proceeding with the loading of my own tablespace onto that database. Has anyone tackled this problem before?

Cheers

Answers

Check for the existence of an ORACLE_HOME. It's also reasonable to expect that this environment should be configured for the installation, so testing the environment variables and exiting with a sensible diagnostic (possibly suggesting they run oraenv) is a good first start. If you have an ORACLE_HOME, ORACLE_SID or other appropriate environment variable set up, you can then check for the existence of an oracle home and test for database connectivity and permissions.

For Oracle 10g, on Windows :

Check the registry :

The key HKLM\SOFTWARE\ORACLE must exist.

A subkey must exist that :

Has a name starting with KEY_ (like KEY_OraDb10g_home1, the end string being an Oracle home name).

Has a value whose name starts with ORA_ and ends with _AUTOSTART. (like ORA_XE_AUTOSTART, the middle string being an instance name).

Beware, installing an Oracle client (without a database instance then), creates entries in the registry and can set environment variables (like ORACLE_HOME). This is why the above pattern is a bit complicated.

This pattern is very likely to work for Oracle 9i also, and possibly Oracle 8i.