Windows批处理循环错误

时间:2016-09-26 10:24:05

标签: windows batch-file

我正在尝试创建一个修补一系列数据库实例的批处理文件。
问题是我一直收到错误

  

“我此时出乎意料。”

如果这对解决问题有任何影响,我会直接从CMD运行。

/****GRAMMER:
 * 
 *  Why cannot use "this" in the main method?
 * 
 *  -----------------------------------------------------------------------------------
 * 
 *      "this" refers to the current object. However, the main method is static, 
 *      which means that it is attached to the class, not to an object instance.
 *  
 *      Which means that the static method can run without instantiate an object,
 *      Hence, there is no current "this" object inside of main().
 * 
 * 
 */

public class Test{
    int a ;
    public static void main(String[] args) {
        int c = this.a;   // Cannot use "this" in a static context, 
                          // because there isn't a "this".
    }
}

1 个答案:

答案 0 :(得分:0)

要在命令行上使用代码块,请将左括号“(”移到第一行的末尾。否则,第一行会产生语法错误。这就是为什么要调用sqlplus -s CONNECT / AS SYSDBA@orc%i一次,产生“我此时意外”的消息“,而不是称之为:

sqlplus -s CONNECT / AS SYSDBA@orc1
...
sqlplus -s CONNECT / AS SYSDBA@orc51

所以正确的循环如下所示:

for /l %i in (1, 1, 51) do ( 
    (echo @?/sqlpatch/18881811/postinstall.sql
    ) | sqlplus -s CONNECT / AS SYSDBA@orc%i
)

如果您将代码放入批处理文件中,请务必将%i更改为%%i 这是因为在批处理文件中,单个百分号用于引用批处理文件调用者提供的命令行参数。