【问题标题】:Arguments passed to SQL*Plus script override the arguments of script which invoked it传递给 SQL*Plus 脚本的参数会覆盖调用它的脚本的参数
【发布时间】:2018-12-21 18:16:18
【问题描述】:

file2.sql

set serveroutput on
exec dbms_output.put_line('invoke file2.sql');

file1.sql

exec dbms_output.put_line('&1');
@file2.sql 'col2' 'col1'
exec dbms_output.put_line('&1');

我正在执行@file1.sql 'col1'。请在下面找到输出。

@f1.sql col1

col1

PL/SQL 过程成功完成。

调用file2.sql

PL/SQL 过程成功完成。

col2

PL/SQL 过程成功完成。

SQL>

我希望在调用 file2.sql 后打印“col2”,但它会被传递给 file2.sql 的值覆盖。如何克服?

【问题讨论】:

    标签: oracle sqlplus


    【解决方案1】:

    您可以将原始参数保存在新变量中:

    file1.sql:

    prompt Argument 1 = &1
    define somevar = &1
    
    @file2.sql col2 col1
    
    prompt Original argument 1 = &somevar
    

    输出:

    SQL> @file1.sql col1
    Argument 1 = col1
    This is file2.sql
    Original argument 1 = col1
    

    【讨论】:

    • 我随后将在 file.sql 中使用 &1 值。所以,我希望保留 &1 中的值,因为它是在调用 file1.sql 时传递的。有没有办法实现这一点或限制传递给调用文件的参数的覆盖值。
    • define 1 = &somevar 在调用 file2.sql 之后?但是,将编号的位置值复制到您可以控制的明确命名的变量中似乎是一种更可靠的方法。既然可以使用&customer_id,为什么还要坚持&1
    • 你明白了。谢谢!
    猜你喜欢
    • 2014-12-29
    • 1970-01-01
    • 2022-01-13
    • 2013-07-10
    • 1970-01-01
    • 2015-06-30
    • 2020-09-08
    • 1970-01-01
    • 2017-12-13
    相关资源
    最近更新 更多