Lesson 5 | Managing LOB size |
Objective | Use LOB commands to adjust the storage size of LOBs |
ENABLE|DISABLE STORAGE IN ROW
CREATE TABLE my_table ( id NUMBER, my_lob CLOB ) LOB (my_lob) STORE AS ( ENABLE STORAGE IN ROW );
CHUNK
LOB (my_lob) STORE AS ( CHUNK 8192 );
PCTVERSION
LOB (my_lob) STORE AS ( PCTVERSION 10 );
RETENTION
, but still supported.RETENTION / RETENTION AUTO / RETENTION MAX / RETENTION MIN
PCTVERSION
in modern versions (like 23ai).LOB (my_lob) STORE AS ( RETENTION AUTO );
CACHE | NOCACHE | CACHE READS
LOB (my_lob) STORE AS ( NOCACHE );
SECUREFILE
and BASICFILE
LOB (my_lob) STORE AS SECUREFILE ( DEDUPLICATE COMPRESS HIGH ENCRYPT );
TABLESPACE
LOB (my_lob) STORE AS ( TABLESPACE lob_tbs );
ALTER TABLE
to Modify LOB Storage
ALTER TABLE my_table MODIFY LOB (my_lob) (CHUNK 8192 RETENTION AUTO NOCACHE ENABLE STORAGE IN ROW);
Option | Purpose |
---|---|
CHUNK |
Controls LOB I/O unit size |
RETENTION |
Controls undo retention vs versioning |
CACHE/NOCACHE |
Controls buffer caching |
ENABLE STORAGE IN ROW |
Stores LOB inline if small enough |
SECUREFILE |
Enables compression, dedup, encryption |
TABLESPACE |
Defines LOB segment storage location |
DBMS_LOB
built-in PL/SQL package. A number of procedures in this package help you adjust the way that LOBs are stored, but four of them of them are most commonly used, as shown in the following table:
Function | Simplified syntax | Notes |
DBMS_LOB.COPY() |
DBMS_LOB.COPY( dest_lob, src_lob dest_offset, src_offset, amt); where dest_lob is the LOB locator to which the data in src_lob is to be copied to, src_lob is the LOB locator of thesource LOB, dest_offset is the offset from the beginning of the destination LOB, src_offset is the offset from the beginningof the source LOB, and amt is the amount of bytes to be copied. | You can also specify an offset to begin copying the data from src_lob, the number of bytes to be copied, and the offset for thecopied data to be placed at in dest_lob. |
DBMS_LOB.APPEND() |
DBMS_LOB.APPEND( dest_lob, src_lob);where dest_lob is the LOB locator that the data in the src_lob is to be appended to and src_lob is the LOB locator or the source LOB. | This procedure will take the contents from one LOB and append them to the end of another LOB. |
DBMS_LOB.TRIM() |
DBMS_LOB.TRIM( lob_locator, newlen); where lob_locator is the LOB locator for the LOB and newlen is an integer representing the new number of bytes in the LOB. | You must first retrieve the locator for the LOB. newlen cannot be more than the existing length of the LOB or an exception will be returned. |
DBMS_LOB.ERASE() |
DBMS_LOB.ERASE( lob_loc, amount, offset); where lob_loc is the LOB locator for the target LOB, amount is an integer representing the number of bytes to be erased, andoffset is an integer representing the offset of the action. |
You can erase data from within a LOB by setting an offset and a number of characters. The size of the LOB is not reduced when theERASE() procedure is used. |
DBMS_LOB.COPY(src_lob, dest_lob, 1, 1, 2000);
src_lob
: The source LOB from which data is being copied.dest_lob
: The destination LOB to which data is being copied.1
: The amount of data to copy (likely 1 unit or chunk here).1
: The destination offset — start writing at position 1 in dest_lob
.2000
: The source offset — start reading from position 2000 in src_lob
.src_lob
dest_lob
2 0 0 0 bytes
" next to each LOB indicate the state of data (possibly a chunk identifier or byte offset).src_lob
and dest_lob
symbolizes the copy operation.2 0 0 0 bytesThis may represent the total byte size of the LOB or the number of bytes being handled during the operation. It implies that 2,000 bytes (from offset 2000) are involved.
DBMS_LOB.COPY
is a manual copy operation between two LOBs.DBMS_LOB.APPEND(src_lob, dest_lob);Here is a breakdown and explanation of the image components:
src_lob
: Represents the source LOB that contains the data to be appended.dest_lob
: Consists of two segments:
dest_lob
.src_lob
.src_lob
and dest_lob
, the text:
2 0 0 0 bytesLikely indicates the internal chunk structure or byte boundaries of the LOB data.
src_lob
to the end of dest_lob
, clearly illustrating that the data is added after existing data, not overwritten."With the APPEND() function, the contents of the src_lob are appended to the end of the contents of the dest_lob."Confirms the operational logic and the read/write behavior of the function.
DBMS_LOB.APPEND
does not erase or replace the data in dest_lob
.
dest_lob := dest_lob || src_lob
DBMS_LOB.TRIM(src_lob, 1000);
src_lob
is reduced to 1000 bytes in length.src_lob
(Before TRIM)
src_lob
.2 0 0 0 bytesThis likely indicates that the LOB originally consists of 2 chunks (or 2,000 bytes).
src_lob
(After TRIM)
src_lob
to a smaller bar below, indicating transformation.1 0 0 0 bytes
"With the TRIM() function, the length of the data in the src_lob
is reduced to the number of bytes specified in the function."
This confirms the operation, only the first 1000 bytes of the LOB are retained.
Feature | Description |
---|---|
Function | DBMS_LOB.TRIM(src_lob, 1000) |
Result | LOB content is truncated to 1000 bytes |
Affected LOB | Only the source LOB (src_lob ) is modified |
Use Cases | Discarding extra data, enforcing max sizes, etc. |