2016-12-22 196 views
2

我已使用os_command.exec向Linux shell发送命令。我正在使用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'是一个Java存储过程,带PL/SQL函数包装器?什么数据类型返回?至少显示PL/SQL规范可能会有用。 (它可能是[这一个](http://www.oracle.com/technetwork/database/enterprise-edition/calling-shell-commands-from-plsql-1-1-129519.pdf),所以它返回一个int?) –

回答

3

您的查询从未执行。 From the documentation

如果dynamic_sql_statement是一个SELECT语句,你省略这两个into_clausebulk_collect_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