SQL * Plus可以从机器读取环境变量是否正在运行? [英] Can SQL*Plus read environment variables from the machine is it running on?

查看:178
本文介绍了SQL * Plus可以从机器读取环境变量是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道数据库引擎本身(通常)在另一台机器上,SQL * Plus没有直接的方式来阅读这些环境变量,但我处于一个棘手的情况,我只需要客户端本身运行的机器上的环境变量。



有没有办法从单个脚本中将这些值作为这些值从SQL * Plus客户端中进行欺骗那将在SQL * Plus中运行?脚本由单个开始/结束的PL / SQL块组成,但是如果我需要使用set / define / variable sort的SQL * Plus指令,也不应该是问题。



我不能做的是改变SQL * Plus可执行文件本身的启动方式(我没有访问权限作为参数传递值)。



有没有办法完成这个?



注意: dbms_system.get_env()从服务器本身检索环境变量,这是我不想要的。

解决方案

你可以得到一些客户端相关来自 USERENV context ,但不是任意的环境变量。



如果您可以在本地计算机上创建一个文件,您可以使用 主机命令根据环境变量设置替换变量:

  SQL> ;主机echo定义homedir = $ HOME> /tmp/gethome.sql 

SQL> @ / tmp / gethome.sql
SQL>主机rm -f /tmp/gethome.sql

SQL>选择'& homedir。'作为双重居所;

HOME
------------
/ home / apoole

1行选择。

不是很漂亮,但如果不能将命令行上的变量作为位置参数传递,你的选择是相当有限的。



这当然是使用Unix-y路径和命令,但是你可以在Windows中做同样的事情。


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.

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.

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?

Note: dbms_system.get_env() seems to retrieve environment variables from the server itself, which is what I do not want.

解决方案

You can get a few client-related things from the USERENV context, but not arbitrary environment variables.

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.

This is using a Unix-y paths and commands of course, but you can do the same sort of thing in Windows.

这篇关于SQL * Plus可以从机器读取环境变量是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆