2009-12-09 131 views
0

我有以下批处理脚本:DOS/sqlplus“句柄无效”错误?

sqlplus ms/[email protected] < drop.sql 
sqlplus ms/[email protected] < create.1.0.sql 

当我双击在Windows资源管理器的bat文件,并运行它也能正常工作。

但是,当我从DOS提示符下键入命令的名字,我得到一个错误:

C:\>create.bat 

C:\>sqlplus ms/[email protected] 0<drop.sql 
The handle is invalid. 

C:\>sqlplus ms/[email protected] 0<create.1.0.sql 
The handle is invalid 

任何想法?


更新:进行了更改使用@,而不是<。这绕过了错误,但是现在该脚本仅执行第一个文件,然后在SQL>提示处离开您。要获得第二个文件执行,你必须在提示符下键入exit,然后运行第二个文件。不知道如何让两个文件执行。 ??

+0

看起来像从命令行运行的批处理脚本有一些额外的0。 0是一个无效的句柄,因此是错误消息。 使用shoover的解决方案 - @是sqlplus的一个参数,它告诉它运行给定的sql脚本。 – 2009-12-10 03:06:32

+0

试过了,不是运气。更新后。 – 2009-12-10 17:19:28

+0

在Jason的回答下看到我的评论。 – shoover 2009-12-10 17:59:38

回答

4

如果你想SQL * PLUS执行脚本,比命令行重定向一个更好的办法是@语法:

sqlplus ms/[email protected] @drop.sql 
sqlplus ms/[email protected] @create.1.0.sql 

同样在@@语法,你可以用它来执行读了来自同一目录中另一个.sql脚本的.sql脚本。

SQL> help @ 
SQL> help @@ 
+0

试过了,没有完全奏效。更新后。 – 2009-12-10 17:20:05

+0

我所做的是创建一个调用我的两个脚本的新'create.sql'脚本。我使用'@'符号执行'create.sql'。 – 2009-12-10 17:28:52

0

Made the change to use @ instead of <. This gets around the error but now the script only executes the first file and then leaves you at the SQL> prompt. To get the second file to execute you have to type exit at the prompt, then the second file runs. Not sure how to get both files to execute. ??

我最后写一个python脚本来运行SQL Plus中,然后退出它来解决这个问题。我还没有找到解决这个限制的方法。尽管如果您按照建议使用@@,则只需处理一次该问题。您只需从第一个脚本运行第二个脚本。

+0

如果您知道您只会从SQL * PLUS运行您的脚本,则可以添加QUIT;命令在脚本的底部。这会导致SQL * PLUS退出。 – shoover 2009-12-10 17:59:06