我被要求将现有 SQLPLUS 脚本的一部分更改为 shell 脚本以允许更多选项。
这是原始 SQLPLUS 脚本提示的内容:
SPOOL results.txt;
WHENEVER OSERROR EXIT 9;
WHENEVER SQLERROR EXIT SQL.SQLCODE;
PROMPT
PROMPT This script upgrades the database to the most recent version of eV8.0.
SET VERIFY OFF;
SET SERVEROUTPUT ON;
ACCEPT continue_flag CHAR PROMPT 'Are You ready to continue Y/N? '
PROMPT
我的 shell 脚本现在看起来像:
#!/bin/sh
echo "Please enter database username"
read eval_user
echo "Please enter database password"
read eval_pass
echo "Please enter the database name"
read db_name
$ORACLE_HOME/bin/sqlplus -s /nolog <<-EOF >> ${LOGFILE}
connect $eval_user/$eval_pass@$db_name
set serveroutput on format wrapped
set pages 0 lines 300 trimout on trimspool on
set echo off feedback off sqlprompt ''
SPOOL results.txt;
WHENEVER OSERROR EXIT 9;
WHENEVER SQLERROR EXIT SQL.SQLCODE;
PROMPT
SET VERIFY OFF;
SET SERVEROUTPUT ON;
ACCEPT continue_flag CHAR PROMPT 'Are You ready to continue Y/N? '
PROMPT
到达 SQLPLUS 提示行时出现此错误:
Are You ready to continue Y/N? You have entered an invalid response. Exiting.
BEGIN
*
ERROR at line 1:
ORA-06501: PL/SQL: program error
ORA-06512: at line 13
我是 sqlplus 的新手,所以我知道这与我一开始设置的设置有关,如果我设置 echo off feedback off sqlprompt ''。但是,在删除该行时,脚本只是挂起。
我应该完全从 SQLPLUS 中取出提示并仅在 shell 部分中使用它吗?