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

标签 oracle plsql clob

我的存储函数使用以下方法创建临时 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) 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( ojdbc5ojdbc6 )检索它,没有问题,无论是使用 getCLOB()getString() .但是,如果我尝试分配 Oracle.sql.CLOBgetCLOB 检索到 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/

相关文章:

oracle - 克服通过数据库链接批量插入的限制

sql - Oracle 11g 如何对来自两个不同列的值进行分组

db2 - IBM DB2 9.7,内联 CLOB 和 VARCHAR 之间有什么区别?

java - oracle.sql.CLOB 与 java.sql.Clob

sql - 按级别连接不随每行字段的变化而调整

sql - oracle sql中填写序号

sql - 在行之间随机排列一列

sql - 在Select *(all)语句中显示RowID

sql - 在SQL中减去前一行减去当前行

Oracle - 与 Varchar 列相比,包含少于 4K 行的行的 CLOB 列是否有任何性能影响?