如何在子图变量中给出查询的结果

发布于 2025-02-03 13:08:14 字数 641 浏览 1 评论 0 原文

问题

续集来自这个 加上代码正在工作

define a=22; 
host powershell.exe echo &a;

22

但是,如果来自查询的值来自查询,则不再起作用。

define a=2; 
select 22 into a;
host powershell.exe echo &a;

2而不是22

我用缓冲区尝试了,但无济于事

variable buffer varchar2;
select 22 into :buffer from dual;
define a=b;
host powershell.exe echo &a;

:b

sequel from this question

this SQL plus code is working

define a=22; 
host powershell.exe echo &a;

22

But if the value from a comes from a query, it doesn't work anymore.

define a=2; 
select 22 into a;
host powershell.exe echo &a;

2 instead of 22

I've tried that with a buffer but to no avails

variable buffer varchar2;
select 22 into :buffer from dual;
define a=b;
host powershell.exe echo &a;

:b

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

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

发布评论

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

评论(1

幸福%小乖 2025-02-10 13:08:14

您可以使用语法。如果您仍然需要一个绑定变量,例如在上一个问题中,那么现在定义并填充了该变量,例如:

SQL> variable buffer varchar2(2);
SQL> exec :buffer := '22';

PL/SQL procedure successfully completed.

SQL> print buffer

BUFFER
--------------------------------
22

然后以新值定义列,您可以稍后将其称为替换变量:

SQL> column a new_value a
SQL> select :buffer as a from dual;

A
--------------------------------
22

SQL> host powershell.exe echo &a
22

SQL> 

您可以设置termout Off ,如果您作为脚本运行并且不想看到输出,则在该额外查询周围返回。

您可以查询任何内容,它不必是一个绑定变量:

select 22 as a from dual;

SQL> select sysdate as a from dual;

A
---------
02-JUN-22

SQL> host powershell.exe echo &a
02-JUN-22

SQL> 

You can use the column .. new_value ... syntax. If you still want a bind variable too, as in your previous question, then define and populate that variable however you are now, e.g.:

SQL> variable buffer varchar2(2);
SQL> exec :buffer := '22';

PL/SQL procedure successfully completed.

SQL> print buffer

BUFFER
--------------------------------
22

Then define the column with a new value you can refer to later as a substitution variable:

SQL> column a new_value a
SQL> select :buffer as a from dual;

A
--------------------------------
22

SQL> host powershell.exe echo &a
22

SQL> 

You can set termout off and back on around that extra query if you're running this as a script and don't want to see the output.

And you can query anything, it doesn't have to be a bind variable:

select 22 as a from dual;

or

SQL> select sysdate as a from dual;

A
---------
02-JUN-22

SQL> host powershell.exe echo &a
02-JUN-22

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