2016-12-22 87 views
2

os_command.execを使用して、Linuxシェルにコマンドを送信しました。私はOracle 12cを使用しています。ここでOracleストアドプロシージャからos_command.execを呼び出す

が正常に動作サンプルコードです:

select os_command.exec('/home/smucha/app/smucha/product/12.1.0/dbhome_1/bin/sqlldr userid=system/password control=/home/smucha/load_data.cmt') 
from dual 

私は、ストアドプロシージャに類似したコマンドを実行したいと思います。これを行う方法はありますか?

私は以下を試しましたが、動作しません。私の手続きはエラーなく実行されますが、レコードはロードされません。

execute immediate 'select os_command.exec(''/home/smucha/app/smucha/product/12.1.0/dbhome_1/bin/sqlldr userid=system/acorp56k control=/home/smucha/IZ/load_data.cmt'') from dual'; 
+0

おそらく、 'os_command'はPL/SQLの機能ラッパーを持つJavaストアドプロシージャですか?そのデータ型はどのようなものですか?少なくともPL/SQL仕様を示すことは有用かもしれません。 (これは[this one](http://www.oracle.com/technetwork/database/enterprise-edition/calling-shell-commands-from-plsql-1-1-129519.pdf)なので、 int?) –

答えて

3

クエリは実行されません。 From the documentationdynamic_sql_statementがSELECT文で、あなたが bulk_collect_into_clauseとinto_clause両方を省略した場合

、その後、execute_immediate_statementが実行されません。

execute immdiateにはinto句が含まれていないため、本質的に無視されています。

あなたはしかし、クエリを必要としない、あなたは直接関数を呼び出すことができます。余談として

procedure foo is 
    result pls_integer; -- or whatever type your function actually returns 
begin 
    result := os_command.exec('/home/smucha/app/smucha/product/12.1.0/dbhome_1/bin/sqlldr userid=system/password control=/home/smucha/load_data.cmt'); 
    -- do something with the result? 
end foo; 

、あなたはSQL * Loaderのへのコールアウトではなく、外部表を使用して検討する必要があります。

+0

ありがとうございます。これは私の問題を解決し、すべてがうまくいきます! – smucha

関連する問題