SQL*Plus 可以从运行它的机器上读取环境变量吗?

Can SQL*Plus read environment variables from the machine is it running on?(SQL*Plus 可以从运行它的机器上读取环境变量吗?)
本文介绍了SQL*Plus 可以从运行它的机器上读取环境变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道数据库引擎本身(通常)在另一台机器上,并且 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 可以从运行它的机器上读取环境变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)