【问题标题】:Getting error sp2-0310 when using "@@" (double "at" sign) command使用“@@”(双“at”符号)命令时出现错误 sp2-0310
【发布时间】:2016-06-08 15:39:28
【问题描述】:

我的文件夹结构类似于

/Release_script/
  install.sql
/common_code/
  error_handling.sql
/Reporting/
  fancy_report1.sql
  fancy_report2.sql
  some_code_to_include.sql

install.sql 脚本包含这些行

@../Reporting/fancy_report1.sql
@../Reporting/fancy_report2.sql

fancy_report1.sql 和 fancy_report2.sql 都以该行开头

@@../common_code/error_handling.sql

它们还包括其他/Reporting/文件,即@@some_code_to_include.sql

如“SQL*Plus 用户指南和参考”中所述,@@ (double "at" sign)

运行脚本。该命令几乎与@(“at”符号)相同 命令。 它对于运行嵌套脚本很有用,因为它具有 在 与调用它的脚本相同的路径或 URL。。只有网址 iSQL*Plus 支持表单。

当我在/Release_script/ 中打开sqlplus 并尝试运行install.sql 时,我得到了错误

SP2-0310:无法打开文件“../common_code/error_handling.sql”

如果我将fancy_report1.sql 的引用更改为@../common_code/error_handling.sql,然后直接从/Reporting/ 文件夹执行fancy_report1.sql,就可以了。

我应该使用哪些命令从调用文件的起点(即fancy_report1.sql)和从工作目录的起点(即@987654332)运行命令@)? 为什么@@ 命令的行为似乎与@ 命令完全一样?

物有所值:

sqlplus -S /nolog<<EOF
prompt &_SQLPLUS_RELEASE

产量:

1102000100

【问题讨论】:

  • 似乎对我有用。你检查过你的目录和文件权限了吗?
  • @tale852150 ... 文件权限?我正在使用 Windows 7...
  • 您不应该在 Windows 7 上使用反斜杠作为路径分隔符吗?
  • @JeromyFrench 好的,然后是文件夹权限。我想到了“文件”,因为我看到了问题中的正斜杠并且没有驱动器号。
  • @mustaccio:我也在考虑这个问题......但是第一条路径 (@../Reporting/fancy_report.sql) 有效,并且它使用正斜杠,所以我认为 sqlplus 做了一些魔法来让它工作.

标签: oracle sqlplus


【解决方案1】:

我要说的是您的 SQL*Plus 版本不喜欢使用 @@ 的相对路径。

此链接:http://www.orafaq.com/wiki/SQL*Plus_FAQ 表示“@@ 引用不支持相对目录引用,例如 @@dir/file.sql 或 @@./file.sql。”但它适用于我的版本。

我进行了与您描述的相同的设置并使用 SQL*Plus 运行脚本:版本 12.1.0.2.0 并且运行良好。 (唯一的区别是我让error_handling.sql 脚本生成文本“COMMON_CODE\ERROR_HANDLING SCRIPT”。)

我将工作目录设置为 Release_script 并运行安装文件:

C:\tmp\Release_script>sqlplus <un/pwd> @install.sql

SQL*Plus: Release 12.1.0.2.0 Production on Wed Jun 8 15:16:00 2016

MSG
---------------------------------
COMMON_CODE\ERROR_HANDLING SCRIPT


MSG
---------------------------------
COMMON_CODE\ERROR_HANDLING SCRIPT

【讨论】:

    【解决方案2】:

    来自 SQL*Plus 文档:

        @@ (double "at" sign)
    
    Runs a script. This command is similar to the @ ("at" sign) command.
    It is useful for running nested scripts because it looks for the specified
    script in the same path as the script from which it was called.
    

    希望最后一句话的后半部分可能成为您问题的线索。 如果是这样,您可能需要使用绝对路径名和相对路径名。

    很遗憾,我无法在 Red Hat Linux 6.7 或 Windows 7 上重现该问题。这是我的 Windows 会话(我只是在文件 error_handling.sql 中使用 select sysdate - 1 from dual;):

    所以我的建议是使用绝对路径名。

    SQL*Plus 版本(在 Windows 7 上):

    【讨论】:

    • 谢谢。你运行的是什么版本的 sqlplus?
    • 查看更新后的答案,现在包括适用于 Windows 环境的 SQL*Plus 版本。
    猜你喜欢
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 1970-01-01
    • 2017-01-05
    • 1970-01-01
    相关资源
    最近更新 更多