Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Guru Help Needed: - How to free Temporary LOB returned by a Function

45508Apr 4 2013
I have a business need to have a db function that would construct and return a (temporary) CLOB value.

here is its sample code:

create or replace package PKG_TEST_CLOB
as
function FN_TEST_TEMP_CLOB
return clob;
end PKG_TEST_CLOB;
/

create or replace package body PKG_TEST_CLOB
as
function FN_TEST_TEMP_CLOB
return clob
as
l_temp_clob clob;

l_clob clob;
begin
DBMS_LOB.CREATETEMPORARY(l_temp_clob, false, DBMS_LOB.CALL);
DBMS_LOB.CREATETEMPORARY(l_clob, false, DBMS_LOB.CALL);
l_temp_clob := TO_CLOB('My Temp Clob Test Value');
DBMS_LOB.APPEND(l_clob, l_temp_clob);
DBMS_LOB.FREETEMPORARY(l_temp_clob);
return l_clob;
end FN_TEST_TEMP_CLOB;
end PKG_TEST_CLOB;
/

when this function is invoked from a SQL Statement...
***
select PKG_TEST_CLOB.FN_TEST_TEMP_CLOB from dual;
***
... the NOCACHE_LOBS counter in V$TEMPORARY_LOBS for my session is incremented by 1

when this function is invoked via a PL/SQL block...
***
declare
l_clob clob;
begin
select PKG_TEST_CLOB.FN_TEST_TEMP_CLOB into l_clob from dual;
end;
/

declare
l_clob clob;
begin
l_clob := PKG_TEST_CLOB.FN_TEST_TEMP_CLOB;
end;
/
***
... the counter doesn't budge

In real life, this function will be used by a Reporting Tool (cognos) via SQL. I tested it, and it seems that it is allocating a new temp lob segment with every invocation.

So what am I supposed to do?
Is this not coded properly? Stopping DB session is not really an option for me

Thank you in advance
-Mike

p.s. this is Oracle 11gR2
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 2 2013
Added on Apr 4 2013
0 comments
445 views