oracle 如何从 PL/SQL 确定 ORACLE_HOME?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1017936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:25:49  来源:igfitidea点击:

How to determine ORACLE_HOME from PL/SQL?

oracleplsqlpathoracle-home

提问by Jens Bannmann

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

是否可以使用纯 PL/SQL 确定 Oracle 的安装位置?

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

用例:为了调用外部 C 库,我需要知道它的确切路径(用于create library调用)。我的 DLL 将驻留在 Oracle 的 BIN 目录中,但我无法在脚本中硬编码 DB 安装的路径...

采纳答案by b.roth

On Windows and Oracle 10g, this works:

在 Windows 和 Oracle 10g 上,这有效:

SELECT  
substr(file_spec,1,instr(file_spec,'\',1,3)) 
FROM dba_libraries 
WHERE library_name='DBMS_SUMADV_LIB'

回答by Brian

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.

注意:默认情况下,您很可能没有权限访问此包。

回答by Kaushik Nayak

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

从Oracle 12c开始,可以使用SYS_CONTEXT功能: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