问题描述
我知道数据库引擎本身(通常)在另一台机器上,并且 SQL*Plus 无法直接读取 那些 环境变量,但我遇到了一个棘手的情况我只需要运行客户端本身的机器上的环境变量.
I'm aware that the database engine itself is (often) on another machine and that SQL*Plus has no direct way of reading those environment variables, but I'm in a tricky situation where I merely need the environment variables from the machine the client itself is running on.
有没有办法从将在 SQL*Plus 中运行的单个脚本中将这些值欺骗到 SQL*Plus 客户端中?该脚本由单个开始/结束 PL/SQL 块组成,但如果我需要使用 set/define/variable 排序的 SQL*Plus 指令,这也不应该成为问题.
Is there a way to cheat these values into the SQL*Plus client from within a single script that will be run in SQL*Plus? The script consists of a single begin/end PL/SQL block, but if I need to use SQL*Plus directives of the set/define/variable sort that shouldn't be a problem either.
我不能做的是改变 SQL*Plus 可执行文件本身的启动方式(我无权将值作为参数传递).
What I can't do is alter the way that the SQL*Plus executable itself is started (I don't have access to pass the values in as arguments).
有没有办法做到这一点?
Is there any way to accomplish this?
注意:dbms_system.get_env()
似乎是从服务器本身检索环境变量,这是我不想要的.
Note: dbms_system.get_env()
seems to retrieve environment variables from the server itself, which is what I do not want.
推荐答案
你可以从USERENV
上下文,但不是任意环境变量.
You can get a few client-related things from the USERENV
context, but not arbitrary environment variables.
如果您可以在本地计算机上创建文件,则可以使用 host
命令根据环境变量设置替换变量:
If you can create a file on your local machine you could use the host
command to set a substitution variable based on an environment variable:
SQL > host echo define homedir=$HOME > /tmp/gethome.sql
SQL > @/tmp/gethome.sql
SQL > host rm -f /tmp/gethome.sql
SQL > select '&homedir.' as home from dual;
HOME
------------
/home/apoole
1 row selected.
不是很漂亮,但是如果您不能在命令行上将变量作为位置参数传递,那么您的选择就相当有限.
Not very pretty, but if you can't pass the variables on the command line as positional parameters then your options are rather limited.
这当然是使用 Unix-y 路径和命令,但你可以在 Windows 中做同样的事情.
This is using a Unix-y paths and commands of course, but you can do the same sort of thing in Windows.
这篇关于SQL*Plus 可以从运行它的机器上读取环境变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!