2009-12-09 35 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