How can I avoid setting shell environment variables required by an ODBC driver?

Some ODBC drivers require environment variables to be set. For example, client-based Oracle ODBC drivers require that ORACLE_HOME is set. If you're using the unixODBC Driver Manager, you can set environment variables in odbc.ini rather than the shell by using:

DMEnvAttr = SQL_ATTR_UNIXODBC_ENVATTR={ENVVAR=value}

For example:

DMEnvAttr = SQL_ATTR_UNIXODBC_ENVATTR={DB2INSTANCE=db2inst2}

The unixODBC Driver Manager sets the environment variable before connecting to the ODBC driver. Note that this only works if your connection uses an ODBC data source.