2016-09-26 60 views
0

我如如何从文件执行PL/SQL代码,并通过BLOB作为参数

begin 
     update table set value_blob = empty_blob() 
     where expr_id = 2 
     returning value_blob into :fileData; 
     update table set value_text = 'test' 
     where expr_id = 2; 
    end; 

存储在文件中的PL/SQL代码。我想执行这个过程,并通过另一个文件中,:FILEDATA参数:

public void handle(String connectionString, String procedure, byte[] dataFile) throws Exception { 

    OracleDataSource ods = new OracleDataSource(); 
    ods.setURL(connectionString); 

    try(Connection conn = ods.getConnection(); 
     CallableStatement statement = conn.prepareCall(procedure); 
     InputStream inputStream = new ByteArrayInputStream(dataFile)) { 

     statement.setBinaryStream("fileData", inputStream, dataFile.length); 
     statement.executeUpdate(); 

    } catch (Exception e) { 
     throw e; 
    } 
} 

执行后我有“测试”value_txt列值,但在value_blob列中没有数据。此列中的以前的数据已更改为空blob。我试过命名和编号的参数,我确信dataFile字节数组不是空的。

+0

我不相信它能够以这种方式工作,你的程序应该存储在你的数据库,那么你就可以使用CallableStatement的调用它https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_6009.htm –

回答

0

如果我正确地理解你的问题,你期待这句话

update table set value_blob = empty_blob() 
    where expr_id = 2 
    returning value_blob into :fileData; 

将返回非空值。但是returning子句返回更新的值,即empty_blob()的结果 这就是为什么您在value_blob列中看不到数据的原因。

如果你想更新value_blob列尝试使用

update table set value_blob = (RAWTOHEX(UTL_RAW.cast_to_raw('some data'))) 
     where expr_id = 2 
     returning value_blob into :fileData; 
相关问题