我正在尝试将show con_name的结果保存到oracle pl/sql sqlplus中的变量

发布于 2025-02-10 08:14:50 字数 272 浏览 2 评论 0原文

我想写这样的东西:

exec show con_name in:= connection_name

但这不起作用。

我知道我可以做到这一点,但是我想知道以后的参考,是否有任何方法可以为show

exec oflect select seles sys_context('userEnv','con_name')in:connection_name from dual;> connection_name

I want to write something like this:

exec SHOW CON_NAME into :=connection_name

but this doesnt work.

I know I can do this but I want to know for future reference if there is any way to do this for show

EXEC SELECT SYS_CONTEXT('USERENV','CON_NAME') into :connection_name from DUAL;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[浮城] 2025-02-17 08:14:50

exec只是一个匿名块的包装器,因此

exec SHOW CON_NAME into :=connection_name

即使

begin SHOW CON_NAME into :=connection_name end

解决其他问题,show> show是sql*plus客户端命令,也不意味着什么在SQL或PL/SQL上下文中。

您可以这样做:

exec :connection_name := SYS_CONTEXT('USERENV','CON_NAME');

避免在PL/SQL中从dual中选择的上下文开关。

Looking at the statement log in SQL Developer, show con_name is doing something similar, with a checkone bind variable it uses internally;尽管它也将其通过本地PL/SQL变量,并将其修剪为30个字符。

您还可以使用列... new_value ...和从dual查询,而无需使用PL/SQL,然后使用替换变量来稍后引用该值,而不是绑定变量:

column con_name new_value connection_name
select SYS_CONTEXT('USERENV','CON_NAME') as con_name from dual;

-- then later...
select '&connection_name' from dual;

不确定那将是多么有用。取决于您想使用的是什么。

exec is just a wrapper for an anonymous block, so

exec SHOW CON_NAME into :=connection_name

is the same as

begin SHOW CON_NAME into :=connection_name end

Even with other issues fixed, show is a SQL*Plus client command, and doesn't mean anything inside a SQL or PL/SQL context.

You could do:

exec :connection_name := SYS_CONTEXT('USERENV','CON_NAME');

to avoid the context switch of selecting from dual within the PL/SQL.

Looking at the statement log in SQL Developer, show con_name is doing something similar, with a checkone bind variable it uses internally; though it also puts it through a local PL/SQL variable and trims that to 30 chars.

You could also use column ... new_value ... and query from dual, without using PL/SQL, and then use a substitution variable to refer to the value later instead of a bind variable:

column con_name new_value connection_name
select SYS_CONTEXT('USERENV','CON_NAME') as con_name from dual;

-- then later...
select '&connection_name' from dual;

Not sure how useful that would be though. Depends what you want to use it for I suppose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文