How do you pass an argument to a PL/SQL block within a sql file called using START in sqlplus?(如何将参数传递给 sqlplus 中使用 START 调用的 sql 文件中的 PL/SQL 块?)
问题描述
我有一个通过 sqlplus 运行多个 sql 文件的 bash 脚本:
I have a bash script running several sql files via sqlplus:
sqlplus $connectioninfo << end
start file1.sql
start file2.sql
start file3.sql $variable
quit
end
file3 有一些 PL/SQL:
file3 has some PL/SQL:
BEGIN
DBMS_OUTPUT.PUT_LINE(&1);
END;
/
但它只是打印文字 "&1" 而不是 $variable 的值.我也在 file3 中尝试了以下内容:
But it just prints the literal "&1" instead of the value of $variable. I have also tried the following in file3:
DEFINE var_a = &1;
BEGIN
DBMS_OUTPUT.PUT_LINE(var_a);
END;
/
还有以下内容:
DECLARE
var_b VARCHAR2(64) := &1;
BEGIN
DBMS_OUTPUT.PUT_LINE(var_b);
END;
/
最后:
DEFINE var_a = &1;
DECLARE
var_b VARCHAR2(64) := var_a;
BEGIN
DBMS_OUTPUT.PUT_LINE(var_b);
END;
/
但是,我收到了各种错误,或者只是所有这些错误的字面值&1".
However, I am getting various errors or just the literal value '&1' for all of these.
推荐答案
尝试将 SET DEFINE ON 添加到脚本的开头 file3.sql.
Try adding SET DEFINE ON to the start of your script file3.sql.
如果SET DEFINE 是ON,SQL*Plus 将用它们的值替换&... 替换参数.如果 SET DEFINE 是 OFF(它似乎适合您),SQL*Plus 不会这样做.
If SET DEFINE is ON, SQL*Plus will replace &... substitution parameters with their values. If SET DEFINE is OFF (which it seems to be for you), SQL*Plus won't do this.
这篇关于如何将参数传递给 sqlplus 中使用 START 调用的 sql 文件中的 PL/SQL 块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将参数传递给 sqlplus 中使用 START 调用的 sql 文件中的 PL/SQL 块?
基础教程推荐
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
