SQLPlus 单行题

SQLPlus one-line questions

我继承了一些在我们的工作负载自动化工具中不再有效的 sqlplus 代码。它需要转换为脚本并调用,或者单行命令。我完全了解如何做第一个(相当基本)。但是如果我想转换成一行,我的想法是否正确?

sqlplus -s myID/pwd <<EOF
define start_date=$start_date;
define end_date=$end_date;
define max_depth=$max_depth;
define min_units=$min_units;
@/app/myapp/sql/forecast
EOF

转换成一行,是不是很简单:

sqlplus -s myID/pwd < define start_date=$start_date; define   end_date=$end_date; define max_depth=$max_depth; define min_units=$min_units; @/app/myapp/sql/forecast

提前致谢

假设您的一行仍然是来自 shell 脚本的 运行,对 sqlplus 的调用表明,您可以使用管道而不是重定向来传递命令到 SQL* 加上:

printf "define start_date=$start_date\ndefine end_date=$end_date\ndefine max_depth=$max_depth\ndefine min_units=$min_units\n@/app/myapp/sql/forecast" | sqlplus -s myID/pwd

或者 稍微 更具可读性,您可能不同意:

printf "define start_date=%s\ndefine end_date=%d\ndefine max_depth=%d\ndefine min_units=%d\n@%s" $start_date $end_date $max_depth $min_units /app/myapp/sql/forecast | sqlplus -s myID/pwd

您需要换行符而不是分号来分隔 define 客户端命令和 @.