The SUBSTR function returns amount bytes or characters from a LOB value, starting at the absolute offset of the LOB value.
For a fixed-width CLOB with width n bytes, if the amount parameter exceeds (32767/n), the SUBSTR function returns a substring of length (32767/n) or the CLOB length, whichever is smaller. The n value represents the maximum width of the CLOB in bytes.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only MySQL mode.
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 value to be read. For more information, see DBMS_LOB. |
| amount | The number of bytes to be read from the BLOB value or the number of characters to be read from the CLOB value. | | offset | The offset in bytes (for the BLOB value) or in characters (for the CLOB value) at which to start reading the LOB value. The default value is 1. |
Return value
| Return value | Description |
|---|
| RAW | The function overload that contains the BLOB parameter. | | VARCHAR2 | The CLOB version. |
| NULL | The return value is NULL in the following cases:
- Any input parameter is
NULL. - The
amountparameter is less than 1. - The
amountparameter exceeds 32767 bytes (or the equivalent number of characters). - The
offsetparameter is less than 1. - The
offsetparameter exceedsLOBMAXSIZE.
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 are returned due to the buffer size being insufficient, you can callDBMS_LOB.SUBSTRwith a new offset to read the remaining characters, or call the procedure repeatedly until all data is extracted.If necessary,
SUBSTRretrieves theLOBbefore reading it.