加入收藏 | 设为首页 | 会员中心 | 我要投稿 孝感站长网 (https://www.0712zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

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

发布时间:2021-02-07 06:39:32 所属栏目:站长百科 来源:网络整理
导读:我的存储函数使用:Dbms_Lob.CreateTemporary(BUFFER,TRUE,Dbms_Lob.SESSION)创建临时LOB实例;其中BUFFER是本地CLOB变量.之后,该函数用一些数据填充BUFFER并返回它. 在我的例子中,Dbms_Lob.CreateTemporary的Duration参数是Dbms_Lob.SESSION,但是根据oracle

我的存储函数使用: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()解决了这个问题,所以现在这可能有点无关紧要了.

(编辑:孝感站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读