如何从文件执行 PL/SQL 代码并将 blob 作为参数传递
How to execute PL/SQL code from file and pass blob as parameter
我有 PL/SQL 代码,例如
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;
存储在文件中。我正在尝试执行此过程并将另一个文件作为 :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 列中有 'test' 值,但 [=20 中没有数据=]value_blob 列。此列中的先前数据已更改为空 blob。我尝试了命名参数和编号参数,我确信 dataFile 字节数组不为空。
如果我正确理解了你的问题,那么你期待的是那个陈述
update table set value_blob = empty_blob()
where expr_id = 2
returning value_blob into :fileData;
将return非空值。但是 returning
子句 return 更新了值,即 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;
我有 PL/SQL 代码,例如
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;
存储在文件中。我正在尝试执行此过程并将另一个文件作为 :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 列中有 'test' 值,但 [=20 中没有数据=]value_blob 列。此列中的先前数据已更改为空 blob。我尝试了命名参数和编号参数,我确信 dataFile 字节数组不为空。
如果我正确理解了你的问题,那么你期待的是那个陈述
update table set value_blob = empty_blob()
where expr_id = 2
returning value_blob into :fileData;
将return非空值。但是 returning
子句 return 更新了值,即 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;