Oracle SQLPLUS - 如何在提示命令中连接变量?

发布于 2025-01-14 04:27:33 字数 413 浏览 2 评论 0原文

例如,在脚本的开头,我从用户那里获取输入:

Prompt "Type the path where the script will be saved: "
spool '&&PATH\tmp_script.sql'

好的,最后我想留下一些类似的消息:

Prompt
prompt End of commands.
prompt
prompt Execute: @&PATHtmp_script.sql to execute the generated script.
prompt

但是 sqlplus 不明白我正在尝试将 &PATH 与 tmp_script.sql 连接起来。我尝试过 scape \,但不适用于提示命令。

For example, in the beggining of script I get the input from user:

Prompt "Type the path where the script will be saved: "
spool '&&PATH\tmp_script.sql'

ok, at the end I want to leave some message like it:

Prompt
prompt End of commands.
prompt
prompt Execute: @&PATHtmp_script.sql to execute the generated script.
prompt

But the sqlplus don't undestand I am trying to concatenate &PATH with tmp_script.sql. I've tried the scape \, but don't work on prompt command.

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

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

发布评论

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

评论(3

二货你真萌 2025-01-21 04:27:33

这不是两个&符号吗?

SQL> prompt "Type path"
"Type path"
SQL> spool '&&PATH\test.sql'
Enter value for path: c:\temp
SQL> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> prompt End of commands
End of commands
SQL> prompt Execute :: &&PATH\test.sql to execute ...
Execute :: c:\temp\test.sql to execute ...                        --> here's te result
SQL>

Isn't that two ampersands?

SQL> prompt "Type path"
"Type path"
SQL> spool '&&PATH\test.sql'
Enter value for path: c:\temp
SQL> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> prompt End of commands
End of commands
SQL> prompt Execute :: &&PATH\test.sql to execute ...
Execute :: c:\temp\test.sql to execute ...                        --> here's te result
SQL>
海之角 2025-01-21 04:27:33

替换变量可以用点终止。

SQL> define PATH = u:\whatever
SQL> prompt File is saved to &PATH.\somefile.log

给出

File is saved to u:\whatever\somefile.log

Substitution variables can be terminated with a dot.

SQL> define PATH = u:\whatever
SQL> prompt File is saved to &PATH.\somefile.log

gives

File is saved to u:\whatever\somefile.log
十年九夏 2025-01-21 04:27:33

我找到了解决方案。其实我已经差不多了,需要使用\,但是在我们需要使用set escape on命令将\作为转义之前,你可以检查此处

SET ESCAPE on

Prompt "Type the path where the script will be saved: "
spool '&&PATH\tmp_script.sql'

Prompt
prompt End of commands.
prompt
prompt Execute: @&PATH\tmp_script.sql to execute the generated script.
prompt

I've found the solution. Actually, I was almost there, need to use \, but before we need to use set escape on command to make \ as escape, You can check here

SET ESCAPE on

Prompt "Type the path where the script will be saved: "
spool '&&PATH\tmp_script.sql'

Prompt
prompt End of commands.
prompt
prompt Execute: @&PATH\tmp_script.sql to execute the generated script.
prompt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文