What is the point of dbms_lob.createtemporary()?
Asked Answered
T

1

33

I don't quite get the point of the dbms_lob.createtemporary() function. How is:

DECLARE
    myclob CLOB;
BEGIN
    myclob := 'foo';
END;

any different from:

DECLARE
    myclob CLOB;
BEGIN
    dbms_lob.createtemporary( myclob, TRUE );
    myclob := 'foo';
    dbms_lob.freetemporary( myclob );
END;

I'm assuming the actions in between the create and free calls make it relevant, but I'm just not clear on how.

Tier answered 19/1, 2014 at 16:47 Comment(1)
Probably, dbms_lob.freetemporary releases memory block (which may be huge enough) without waiting for variable goes out of scope, so you can control memory usage in a bit more flexible way.Tenuous
W
26

In earlier times you were always forced to use DBMS_LOB package. Then in Oracle 10g a feature called "SQL semantics for LOB" was introduced and now you can use the simplified syntax.

In CREATETEMPORARY you can specify the duration of the LOB in SQL semantic you cannot.

In your case the LOB is freed in the same way, i.e. when you leave the scope (i.e. the PL/SQL block) where the LOB is declared, then it is freed.

When you use FREETEMPORARY then the temporary segment in tablespace is released, when you call myclob := NULL; it will be kept.

Worrisome answered 19/1, 2014 at 19:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.