oracle – 如何从Pl / SQL中的存储函数返回临时CLOB实例?

前端之家收集整理的这篇文章主要介绍了oracle – 如何从Pl / SQL中的存储函数返回临时CLOB实例?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的存储函数使用:Dbms_Lob.CreateTemporary(BUFFER,TRUE,Dbms_Lob.SESSION)创建临时LOB实例;其中BUFFER是本地CLOB变量.之后,该函数用一些数据填充BUFFER并返回它.

在我的例子中,Dbms_Lob.CreateTemporary的Duration参数是Dbms_Lob.SESSION,但是根据oracle documentation

The duration parameter passed to dbms_lob.createtemporary() is a hint.
The duration of the new temp LOB is the same as the duration of the
locator variable in PL/sql. For example,in the preceding program
block,the program variable a has the duration of the residing frame.
Therefore at the end of the block,memory of a will be freed at the
end of the function.

因此,离开功能块后,Oracle可能会销毁BUFFER CLOB.我可以看到,在某些情况下,当BUFFER超过32K时,我无法读取它从Java(JDBC)端以这种方式返回的值.

有没有其他方法函数返回临时CLOB实例?

解决方法

评论中你说:

clob.getSubString(0,clob.length()) throws: java.sql.sqlException:
Invalid argument(s) in call at
oracle.sql.CLOB.getSubString(CLOB.java:236)
while clob.length()
returns actual length of my clob

getSubString的文档指出:

pos – the first character of the substring to be extracted. The first character is at position 1.

有了生成和返回CLOB的简单函数,我可以通过JDBC(ojdbc5或ojdbc6)检索它,没有任何问题,无论是使用getCLOB()还是getString().但是,如果我尝试将使用getCLOB检索的Oracle.sql.CLOB分配给String

String x = getSubString(0,clob.length());

然后我也在调用错误中得到Invalid参数.只需将其更改为:

String x = getSubString(1,clob.length());

作品.所以它似乎与函数中的临时分配或CLOB大小无关.我不明白为什么你没有小CLOB的问题 – 也许你的逻辑只是在他们很小的时候没有打到这个?

与此同时,你已经使用clob.getCharacterStream().read()解决了这个问题,所以现在这可能有点无关紧要了.

猜你在找的Oracle相关文章