2

Is it possible to determine where Oracle is installed using pure PL/SQL?

Use case: In order to call an external C library, I need to know its exact path (for the create library call). My DLL will reside in Oracle's BIN directory, but I can't hard-code the path of the DB installation in my scripts...

Jens Bannmann
  • 4,845
  • 5
  • 49
  • 76

3 Answers3

3
DECLARE
 RetVal VARCHAR2(100);
BEGIN
  dbms_system.get_env('ORACLE_HOME', RetVal);
  dbms_output.put_line(RetVal);
END;

NOTE: It is likely you that you will not have permission to this package by default.

Brian
  • 13,412
  • 10
  • 56
  • 82
2

On Windows and Oracle 10g, this works:

SELECT  
substr(file_spec,1,instr(file_spec,'\',1,3)) 
FROM dba_libraries 
WHERE library_name='DBMS_SUMADV_LIB'
Jens Bannmann
  • 4,845
  • 5
  • 49
  • 76
b.roth
  • 9,421
  • 8
  • 37
  • 50
2

Starting from Oracle 12c, you can use the SYS_CONTEXT function: Oracle docs

SET SERVEROUTPUT ON
BEGIN
   DBMS_OUTPUT.PUT_LINE(SYS_CONTEXT('USERENV','ORACLE_HOME'));
END;
/

/u01/app/oracle/product/12.1.0.2/dbhome_1
Kaushik Nayak
  • 30,772
  • 5
  • 32
  • 45