Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 通过Windows批处理文件执行时,ECHO无法正常工作_Oracle_Batch File_Sqlplus - Fatal编程技术网

Oracle 通过Windows批处理文件执行时,ECHO无法正常工作

Oracle 通过Windows批处理文件执行时,ECHO无法正常工作,oracle,batch-file,sqlplus,Oracle,Batch File,Sqlplus,我正在尝试编写一个简单的批处理脚本,如果环境最近被刷新并删除了我们的更改,我们的用户可以使用它将一些代码重新部署到环境中 这个脚本工作得很好,但它并不是我想要的那样。我不是DBA,只是一个开发人员,我们不能在文件中包含ECHO命令 为了解决这个问题,作为批处理脚本的一部分,我在工作目录中创建了一个文件,其中包含SET ECHO ON和SPOOL file.log APPEND命令。目标是在脚本和假脱机输出之前执行此操作。然而,虽然SPOOL命令似乎在工作,但脚本的内容没有得到响应 以下是批处理脚

我正在尝试编写一个简单的批处理脚本,如果环境最近被刷新并删除了我们的更改,我们的用户可以使用它将一些代码重新部署到环境中

这个脚本工作得很好,但它并不是我想要的那样。我不是DBA,只是一个开发人员,我们不能在文件中包含ECHO命令

为了解决这个问题,作为批处理脚本的一部分,我在工作目录中创建了一个文件,其中包含SET ECHO ON和SPOOL file.log APPEND命令。目标是在脚本和假脱机输出之前执行此操作。然而,虽然SPOOL命令似乎在工作,但脚本的内容没有得到响应

以下是批处理脚本中的相关代码:

:: Identify all files that begin with a number and end with .sql and write to a file.
dir /b *.sql | findstr /b "[0-9]" > ScriptsToImplement.txt

:: Show the user the files to be executed and confirm whether to proceed
echo The following scripts will be executed in %DB%:
for /f "delims=" %%i in (ScriptsToImplement.txt) do echo %%i
echo:
set /p PROCEED=Proceed with implementation? [y/n] ^>
if /i "%PROCEED%" NEQ "y" (goto :opt_to_terminate)

:: Build the user profile SQL file that will be executed after logging into SQLPlus
:: This allows for the spooling of the output without having the SPOOL command declared in the file.
echo SET ECHO ON >> login.sql
echo SPOOL %DB%~%FOLDER%~%DATESTAMP%.log APPEND >> login.sql

:: Go through the SQL files in the text file and execute them in the specified database.
for /f "delims=" %%i in (ScriptsToImplement.txt) do (
echo exit | sqlplus -L -S %DB_USER%/%DB_PASS%@%DB% @%%i
if %errorlevel% NEQ 0 (@echo an error occurred with applying %%i; stopping further script execution... & pause & goto :terminate) else (@echo %%i was applied successfully) >> %DATESTAMP%_run_all.log
)

我的理解是,由于这是用每个单独的脚本启动一个单独的SQL*Plus会话,它每次都调用login.SQL文件,因此每次都应该使用SET ECHO ON命令。

如果您在BAT文件中使用它,请记住ECHO是一个命令,而不是一个环境变量。打开echo的命令是echo on。将回显设置为ON不会影响回显行为。它返回环境变量ECHO not defined。

这是ECHO exit | sqlplus-L-S%DB_USER%/%DB_PASS%@%DB%@%i行,您每次调用login.sql都是指它。这就是它的工作原理。你确认脚本中没有设置ECHO OFF吗?@dbenham是的,脚本是我写的。它们包含的唯一非DDL/DML是ALTER SESSION命令。SET ECHO ON是SQL*Plus命令。我正在将该命令写入login.sql文件,希望它在脚本之前执行。