The SUBSTR function returns amount bytes or characters from a LOB starting at the absolute offset of the LOB.
For a fixed-width CLOB of n bytes, if the input to SUBSTR exceeds 32767/n, SUBSTR returns a value of length 32767/n or the CLOB length, whichever is smaller. n is the maximum byte width of the CLOB.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
Syntax
DBMS_LOB.SUBSTR (
lob_loc IN BLOB,
amount IN INTEGER := 32767,
offset IN INTEGER := 1)
RETURN RAW;
DBMS_LOB.SUBSTR (
lob_loc IN CLOB CHARACTER SET ANY_CS,
amount IN INTEGER := 32767,
offset IN INTEGER := 1)
RETURN VARCHAR2;
Parameters
| Parameter | Description |
|---|---|
| lob_loc | The locator of the LOB to be read. For more information, see DBMS_LOB. |
| amount | The number of bytes to read for a BLOB or the number of characters to read for a CLOB. |
| offset | The offset (in bytes for a BLOB or in characters for a CLOB) at which to start reading the LOB (default value is 1). |
Return value
| Return value | Description |
|---|---|
| RAW | The overload of the function that contains a BLOB parameter. |
| VARCHAR2 | The overload of the function that contains a CLOB parameter. |
| NULL | The return value is NULL in the following cases:
|
Considerations
The
VARCHAR2buffer must match the format of theCLOBparameter. In other words, if the inputLOBparameter is of typeCLOB, the buffer must containCHARdata.When you call
DBMS_LOB.SUBSTRfrom a client, the returned buffer contains data in the client character set. Before returning the buffer to the user, the database converts theLOBvalue from the server character set to the client character set.DBMS_LOB.SUBSTRreturns 8191 or more characters based on the characters stored in theLOB. If not all characters can be returned due to the buffer size, you can callDBMS_LOB.SUBSTRagain with a new offset to read the remaining characters or loop through the procedure until all data is extracted.SUBSTRretrieves theLOBbefore reading it.
