The SUBSTR function returns a specified amount of bytes or characters from a LOB, starting from an absolute offset position relative to the beginning of the LOB.
For a CLOB with a fixed length of n bytes, if the input amount for SUBSTR is greater than (32767/n), SUBSTR returns a value of length (32767/n) or the length of the CLOB, whichever is smaller. For CLOBs in a varying-width character set, n is the maximum byte width of the CLOBs.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the 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 to read from. For more information, see Considerations. |
| amount | The amount of data to read. The value is in bytes for BLOBs, and in characters for CLOBs. |
| offset | The offset from the beginning of the LOB, with 1 as the origin, for the read operation. The value is in bytes for BLOBs and in characters for CLOBs. |
Return values
| Return value | Description |
|---|---|
| RAW | Function overloading that has a BLOB in the parameter. |
| VARCHAR2 | The version of the CLOB. |
| NULL | Several possibilities:
|
Considerations
The form of the
VARCHAR2buffer must match the form of theCLOBparameter. That is, if the type of the inputLOBparameter isCLOB, the data in the buffer must be of theCHARtype.When you call
DBMS_LOB.SUBSTRfrom the client, returned data in the buffer must use the client’s character set. Before the database returns the buffered data to the user, it converts the value of theLOBfrom the character set of the server to that of the client.DBMS_LOB.SUBSTRwill return 8,191 or more characters based on the characters stored in theLOB. If all characters are not returned because the character byte size exceeds the available buffer, you can either callDBMS_LOB.SUBSTRwith a new offset to read the remaining characters, or call the subprogram in a loop until all the data is extracted.When necessary,
SUBSTRobtains theLOBbefore it reads data.