2016-09-26 61 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; 
相關問題