我的存储函数使用以下方法创建临时 LOB 实例:Dbms_Lob.CreateTemporary(BUFFER, TRUE, Dbms_Lob.SESSION);
哪里BUFFER
是本地人 CLOB
多变的。之后函数填充BUFFER
一些数据并返回它。Dbms_Lob.CreateTemporary
的持续时间参数在我的情况下是 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.
所以
BUFFER CLOB
离开功能块后可能会被 Oracle 销毁。我可以看到,在某些情况下,当 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)
whileclob.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()
.但是,如果我尝试分配 Oracle.sql.CLOB
用 getCLOB
检索到 String
使用String x = getSubString(0, clob.length());
然后我也得到了
Invalid argument(s) in call
错误。只需将其更改为:String x = getSubString(1, clob.length());
作品。所以似乎与函数中的临时分配,或者CLOB大小无关。我不明白为什么您对较小的 CLOB 没有问题——也许如果它们很小,您的逻辑就没有达到这一点?
与此同时,您已经通过
clob.getCharacterStream().read()
解决了这个问题。 ,所以这现在可能有点无关紧要。
关于oracle - 如何从 Pl/SQL 中的存储函数返回临时 CLOB 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14586253/