FAQ 常见问题系列--互操作篇 使用SQL Outbound Adapter调用Oracle存储过程获取CLOB的正确方式
近日遇到客户反映在Business Operation中使用SQL Outbound Adapter调用Oracle存储过程时,无法获取CLOB完整的返回内容。借此在这里介绍下该如何调用,话不多说,直接上代码。
注意,以下代码片段直接应用于Business Operation中,
set pIn = 4
set pIn(1) = "aaaa"
set pIn(1,"IOType") = 1 // 1:input , 4:output
set pIn(1,"SqlType") = 12 // 12: varchar
set pIn(2,"IOType") = 4
set pIn(2,"SqlType") = 4 // 4: integer
set pIn(3,"IOType") = 4
set pIn(3,"SqlType") = 12
set pIn(4,"IOType") = 4
set pIn(4,"SqlType") = 2005 // CLOB
set pIn(4,"LOB") = 1
set tQuery = "{ call test_hc(?,?,?,?) }" /// the first one parameter is input parameter, the last three are all output parameters.
set tSC = ..Adapter.ExecuteProcedureParmArray(.tRS,.pOut,tQuery,"iooo",.pIn)
set cnt = pOut.Count()
// you will get this stream data
if cnt >1
{
for i=1:1:cnt
{
set ov = pOut.GetAt(i))
$$$TRACE("pOut("_i_")="_ov)
/// the third one is the CLOB output.
if (i = 3)
{
while 'ov.AtEnd
{
$$$TRACE(ov.Read())
}
}
}
}
关于以上示例代码的几点说明,
1. test_hc为Oracle存储过程, 该存储过程的第一个参数为入参,后三个为出参,第三个出参为CLOB类型。
2. 使用上述方式获取到的第三个出参为%Stream.GlobalCharacter类型,拿到该数据后在程序中根据实际场景对其进行相应的处理,以上示例代码中我们只是将该%Stream类型数据读取出来。
3. 关于IOType,in: 1, out:4, both:2
4. 关于SqlType,经常使用的几个取值,12:varchar,4:integer, 2005: CLOB, 2004: BLOB, 更多详细取值对照请查看Routine,EnsSQLTypes.INC。
如果对方的oracle只提供了表,有个字段是clob,我们使用SQL Outbound Adapter,如何写入呢