如何用sqlplus用引号的字符串打印

发布于 2025-02-05 06:25:29 字数 698 浏览 2 评论 0原文

问题

define a='eee"dd'
prompt &a                       -- eee"dd OK
host powershell.exe echo '&a';  -- eeedd  not OK
host powershell.exe echo &a;    -- eeedd  not OK

可以看出,我无法用SQL Plus的Powershell中的引号打印一个引用。 有办法做到吗?


当值来自查询时,我已经尝试了Alex Poole的解决方案。但是如果有一个以上的报价字符串,它不起作用。

column a new_value a 
select replace('eee"d"d', '"', '""') as a from dual;

prompt &a                      -- eee""d""d  Ok as expected
host powershell.exe echo '"&a"'-- eee"dd instead of eee"d"d

Sequel from this question

define a='eee"dd'
prompt &a                       -- eee"dd OK
host powershell.exe echo '&a';  -- eeedd  not OK
host powershell.exe echo &a;    -- eeedd  not OK

As you can see, I can't print a stirng with a quotation quote in powershell from sql plus.
Is there a way to do that.?


I've tried the solution of Alex Poole when the value comes from a query.But it's not working if there is more than one quotation string.

column a new_value a 
select replace('eee"d"d', '"', '""') as a from dual;

prompt &a                      -- eee""d""d  Ok as expected
host powershell.exe echo '"&a"'-- eee"dd instead of eee"d"d

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

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

发布评论

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

评论(2

简单爱 2025-02-12 06:25:31
column a new_value a
select replace('eee"d"d', '"', '\"') as a from dual;
host powershell.exe echo '&a'

为我工作

column a new_value a
select replace('eee"d"d', '"', '\"') as a from dual;
host powershell.exe echo '&a'

works for me

苦行僧 2025-02-12 06:25:30

如果您逃脱了报价,似乎有效(用于PowerShell的福利)通过在值,中使用“”使用两种类型的引号好处:

SQL> define a='eee""dd'
SQL> host powershell.exe echo '"&a"'
eee"dd

如果您实际上是从查询中填充a变量,如以前的问题,您可以replace()引用:

column a new_value a
select replace('eee"dd', '"', '""') as a from dual;

It seems to work if you escape the quote (for PowerShell's benefit) by using "" within the value, and use both types of quotes, for both PowerShell's and SQL*Plus's benefit:

SQL> define a='eee""dd'
SQL> host powershell.exe echo '"&a"'
eee"dd

If you are actually populating the a variable from a query, as in your previous questions, then you can replace() quotes with:

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